Skip to content

Commit

Permalink
Add support to export list of org repo
Browse files Browse the repository at this point in the history
Add option to export list of org repos into different formats.

Closes ksdme#6
  • Loading branch information
kx-chen committed Nov 8, 2018
1 parent d832331 commit bbf0fd2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
15 changes: 15 additions & 0 deletions org_status/export/Exporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Exporter:
NAME = None
OUTPUT_FILE = None

def save_org_repos_to_file(self, repos):
raise NotImplementedError()

def use_org_list_to_check_status(self):
raise NotImplementedError()


def get_all_supported_exporters():
from org_status.export.gitman import GitManExporter

return [GitManExporter]
Empty file added org_status/export/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions org_status/export/gitman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import yaml

from furl import furl

from org_status.export.Exporter import Exporter


class GitManExporter(Exporter):
NAME = 'gitman'
OUTPUT_FILE = f'{os.getcwd()}/gitman.yml'

@classmethod
def save_org_repos_to_file(cls, repos):
repo_data = []

for repo in repos:
name = furl(repo.repo_url).path.segments[1]
repo_data.append({'name': name,
'repo': repo.repo_url,
'rev': 'master'})

with open(cls.OUTPUT_FILE, 'r') as yml:
config_yml = yaml.load(yml)

with open(cls.OUTPUT_FILE, 'w') as yml:
if config_yml['sources'] is None:
config_yml['sources'] = []

for repo in repo_data:
config_yml['sources'].append(repo)

yaml.dump(config_yml, yml, default_flow_style=False)

@classmethod
def use_org_list_to_check_status(cls):
pass
18 changes: 18 additions & 0 deletions org_status/org_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from org_status.status_providers import Status
from org_status.org_hosts import get_all_supported_hosts
from org_status.export.Exporter import get_all_supported_exporters


def get_host_token(host_name):
Expand Down Expand Up @@ -75,10 +76,24 @@ def get_argument_parser():
parser.add_argument('--verbose', '-v', action='store_true')
parser.add_argument('--hosts-only', '-o', action='store_true')
parser.add_argument('--skip-host-checks', action='store_true')
parser.add_argument('--exporter', type=str)

return parser


def export(repo_data, exporter_name):
exporters = get_all_supported_exporters()

for exporter in exporters:
if exporter.NAME == exporter_name:
try:
exporter.save_org_repos_to_file(repo_data)
except NotImplementedError:
print('exporter does not support exporting results')
else:
print('exporter format not found')


def main():
parser = get_argument_parser()
args = parser.parse_args()
Expand Down Expand Up @@ -137,4 +152,7 @@ def main():

org_host = Host(token, org, verbose=args.verbose)
org_status = aggregate_org_status(org_host, threads=args.threads)

export(org_status, args.exporter)

present_status(org_status, args.no_color)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
git+https://gitlab.com/gitmate/open-source/IGitt.git#egg=IGitt
requests
termcolor
furl

0 comments on commit bbf0fd2

Please sign in to comment.