From 7c7ab30c840b77976b5c3232982e62d96832d80c Mon Sep 17 00:00:00 2001 From: Kai Chen Date: Thu, 8 Nov 2018 02:04:12 -0800 Subject: [PATCH] Add support to export list of org repo Add option to export list of org repos into different formats. Closes https://github.com/ksdme/org-status/issues/6 --- org_status/export/__init__.py | 14 ++++++++++++++ org_status/export/gitman.py | 20 ++++++++++++++++++++ org_status/org_status.py | 18 ++++++++++++++++++ requirements.txt | 2 ++ 4 files changed, 54 insertions(+) create mode 100644 org_status/export/__init__.py create mode 100644 org_status/export/gitman.py diff --git a/org_status/export/__init__.py b/org_status/export/__init__.py new file mode 100644 index 0000000..d0d2df6 --- /dev/null +++ b/org_status/export/__init__.py @@ -0,0 +1,14 @@ +class Encoder: + NAME = None + + @classmethod + def convert_org_list_to_format(cls, repos): + raise NotImplementedError() + + +def get_all_supported_exporters(): + from org_status.export.gitman import GitManEncoder + + return ( + GitManEncoder, + ) diff --git a/org_status/export/gitman.py b/org_status/export/gitman.py new file mode 100644 index 0000000..512ee26 --- /dev/null +++ b/org_status/export/gitman.py @@ -0,0 +1,20 @@ +import yaml +from furl import furl + +from org_status.export import Encoder + + +class GitManEncoder(Encoder): + NAME = 'gitman' + + @classmethod + def convert_org_list_to_format(cls, repos): + repo_data = [] +it + for repo in repos: + name = furl(repo.repo_url).path.segments[1] + repo_data.append({'name': name, + 'repo': repo.repo_url, + 'rev': 'master'}) + + return yaml.dump(repo_data) diff --git a/org_status/org_status.py b/org_status/org_status.py index 8b42510..d18f8ba 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 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.convert_org_list_to_format(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..28fce98 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ git+https://gitlab.com/gitmate/open-source/IGitt.git#egg=IGitt requests termcolor +furl +pyyaml