diff --git a/org_status/export/Exporter.py b/org_status/export/Exporter.py new file mode 100644 index 0000000..59331e3 --- /dev/null +++ b/org_status/export/Exporter.py @@ -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] diff --git a/org_status/export/__init__.py b/org_status/export/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/org_status/export/gitman.py b/org_status/export/gitman.py new file mode 100644 index 0000000..908525a --- /dev/null +++ b/org_status/export/gitman.py @@ -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 diff --git a/org_status/org_status.py b/org_status/org_status.py index 8b42510..5b341bf 100644 --- a/org_status/org_status.py +++ b/org_status/org_status.py @@ -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): @@ -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() @@ -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) diff --git a/requirements.txt b/requirements.txt index 78da91f..53fceeb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ git+https://gitlab.com/gitmate/open-source/IGitt.git#egg=IGitt requests termcolor +furl