diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/download_gerrit_change.py | 52 | ||||
-rwxr-xr-x | tools/migrate_names.py | 71 | ||||
-rw-r--r-- | tools/requirements.txt | 1 |
3 files changed, 85 insertions, 39 deletions
diff --git a/tools/download_gerrit_change.py b/tools/download_gerrit_change.py index f21f93370c..31ba1a63eb 100755 --- a/tools/download_gerrit_change.py +++ b/tools/download_gerrit_change.py @@ -16,8 +16,11 @@ # under the License. import base64 +import sys -import click +from cliff import app +from cliff import command +from cliff import commandmanager import requests GERRIT_URL = 'https://review.opendev.org/' @@ -38,22 +41,37 @@ def fetch(change, output_patch=None, url=GERRIT_URL, timeout=TIMEOUT): return str(message_bytes, 'utf-8') -@click.command() -@click.argument('gerrit_change', nargs=1, type=click.INT) -@click.option('-o', '--output_patch', - help='Output patch file [default: stdout]') -@click.option('-g', '--gerrit_url', - default=GERRIT_URL, - show_default=True, - help='The url to Gerrit server') -@click.option('-t', '--timeout', - default=TIMEOUT, - show_default=True, - type=click.INT, - help='Timeout, in seconds') -def cli(gerrit_change, output_patch, gerrit_url, timeout): - message = fetch(gerrit_change, output_patch, gerrit_url, timeout) - if not output_patch or output_patch == '-': +class Config(command.Command): + def get_parser(self, prog_name): + parser = super().get_parser(prog_name) + parser.add_argument('gerrit_change', help='Gerrit change') + parser.add_argument( + '-o', '--output_patch', default='-', + help='Output patch file [default: stdout]') + parser.add_argument( + '-g', '--gerrit_url', default=GERRIT_URL, + help='The url to Gerrit server') + parser.add_argument( + '-t', '--timeout', default=TIMEOUT, + help='Verify server certificate (default)', + ) + return parser + + def take_action(self, parsed_args): + pass + + +def cli(): + my_app = app.App( + description='Download a gerrit change', + version='1.0.0', + command_manager=commandmanager.CommandManager('mycli.cli')) + cmd = Config(my_app, None) + parser = cmd.get_parser('migrate_names') + parsed_args = parser.parse_args(sys.argv[1:]) + message = fetch(parsed_args.gerrit_change, parsed_args.output_patch, + parsed_args.gerrit_url, parsed_args.timeout) + if not parsed_args.output_patch or parsed_args.output_patch == '-': print(message) diff --git a/tools/migrate_names.py b/tools/migrate_names.py index 818cdec4cb..2a6b581e1a 100755 --- a/tools/migrate_names.py +++ b/tools/migrate_names.py @@ -21,10 +21,12 @@ import os import re import sys -import click - +from cliff import app +from cliff import command +from cliff import commandmanager import download_gerrit_change + root_dir = os.path.dirname(os.path.realpath(__file__)) Migration = namedtuple('Migration', 'from_repo to_repo') @@ -80,30 +82,55 @@ def open_output(filename=None): fh.close() -@click.command() -@click.option('-i', '--input_patch', prompt='Input patch file or gerrit id', - help='input_patch patch file or gerrit change') -@click.option('-o', '--output_patch', default='-', - help='Output patch file. Default: stdout') -@click.option('-m', '--mapfile', - default=os.path.join(root_dir, 'migrate_names.txt'), - show_default=True, - type=click.Path(), - help='Data file that specifies mapping to be applied to input') -@click.option('--reverse/--no-reverse', - default=False, - help='Map filenames from networking-ovn to Neutron repo') -def cli(input_patch, output_patch, mapfile, reverse): - dirmaps = read_mapfile(mapfile) - if reverse: +class Config(command.Command): + def get_parser(self, prog_name): + parser = super().get_parser(prog_name) + parser.add_argument( + '-i', '--input_patch', required=True, + help='input_patch patch file or gerrit change') + parser.add_argument( + '-o', '--output_patch', default='-', + help='Output patch file. Default: stdout') + parser.add_argument( + '-m', '--mapfile', + default=os.path.join(root_dir, 'migrate_names.txt'), + help='Data file that specifies mapping to be applied to input') + reverse_group = parser.add_mutually_exclusive_group() + reverse_group.add_argument( + '--reverse', + action='store_true', + default=False, + help='Verify server certificate (default)', + ) + reverse_group.add_argument( + '--no-reverse', + action='store_true', + help='Disable server certificate verification', + ) + return parser + + def take_action(self, parsed_args): + pass + + +def cli(): + my_app = app.App( + description='Migrate names between repositories', + version='1.0.0', + command_manager=commandmanager.CommandManager('mycli.cli')) + cmd = Config(my_app, None) + parser = cmd.get_parser('migrate_names') + parsed_args = parser.parse_args(sys.argv[1:]) + dirmaps = read_mapfile(parsed_args.mapfile) + if parsed_args.reverse: dirmaps = [Migration(two, one) for one, two in dirmaps] - if os.path.isfile(input_patch): - with open(input_patch, 'r') as input_fd: + if os.path.isfile(parsed_args.input_patch): + with open(parsed_args.input_patch, 'r') as input_fd: patch_content = ''.join(input_fd.readlines()) else: - patch_content = download_gerrit_change.fetch(input_patch) + patch_content = download_gerrit_change.fetch(parsed_args.input_patch) - with open_output(output_patch) as output_fd: + with open_output(parsed_args.output_patch) as output_fd: parse_input(dirmaps, patch_content, output_fd) diff --git a/tools/requirements.txt b/tools/requirements.txt index e43ec246e2..6857292747 100644 --- a/tools/requirements.txt +++ b/tools/requirements.txt @@ -2,4 +2,5 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. click>=7.0 # BSD +cliff>=3.10.1 # Apache-2.0 requests>=2.14.2 # Apache-2.0 |