Migrate "migrate_names" to use "cliff"
Partial-Bug: #1985049 Change-Id: Ia03f5c983acd8354adfa2f5f42e6a3e91e940618
This commit is contained in:
@@ -21,10 +21,12 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import click
|
from cliff import app
|
||||||
|
from cliff import command
|
||||||
|
from cliff import commandmanager
|
||||||
import download_gerrit_change
|
import download_gerrit_change
|
||||||
|
|
||||||
|
|
||||||
root_dir = os.path.dirname(os.path.realpath(__file__))
|
root_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
Migration = namedtuple('Migration', 'from_repo to_repo')
|
Migration = namedtuple('Migration', 'from_repo to_repo')
|
||||||
|
|
||||||
@@ -80,30 +82,55 @@ def open_output(filename=None):
|
|||||||
fh.close()
|
fh.close()
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
class Config(command.Command):
|
||||||
@click.option('-i', '--input_patch', prompt='Input patch file or gerrit id',
|
def get_parser(self, prog_name):
|
||||||
help='input_patch patch file or gerrit change')
|
parser = super().get_parser(prog_name)
|
||||||
@click.option('-o', '--output_patch', default='-',
|
parser.add_argument(
|
||||||
help='Output patch file. Default: stdout')
|
'-i', '--input_patch', required=True,
|
||||||
@click.option('-m', '--mapfile',
|
help='input_patch patch file or gerrit change')
|
||||||
default=os.path.join(root_dir, 'migrate_names.txt'),
|
parser.add_argument(
|
||||||
show_default=True,
|
'-o', '--output_patch', default='-',
|
||||||
type=click.Path(),
|
help='Output patch file. Default: stdout')
|
||||||
help='Data file that specifies mapping to be applied to input')
|
parser.add_argument(
|
||||||
@click.option('--reverse/--no-reverse',
|
'-m', '--mapfile',
|
||||||
default=False,
|
default=os.path.join(root_dir, 'migrate_names.txt'),
|
||||||
help='Map filenames from networking-ovn to Neutron repo')
|
help='Data file that specifies mapping to be applied to input')
|
||||||
def cli(input_patch, output_patch, mapfile, reverse):
|
reverse_group = parser.add_mutually_exclusive_group()
|
||||||
dirmaps = read_mapfile(mapfile)
|
reverse_group.add_argument(
|
||||||
if reverse:
|
'--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]
|
dirmaps = [Migration(two, one) for one, two in dirmaps]
|
||||||
if os.path.isfile(input_patch):
|
if os.path.isfile(parsed_args.input_patch):
|
||||||
with open(input_patch, 'r') as input_fd:
|
with open(parsed_args.input_patch, 'r') as input_fd:
|
||||||
patch_content = ''.join(input_fd.readlines())
|
patch_content = ''.join(input_fd.readlines())
|
||||||
else:
|
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)
|
parse_input(dirmaps, patch_content, output_fd)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -2,4 +2,5 @@
|
|||||||
# of appearance. Changing the order has an impact on the overall integration
|
# of appearance. Changing the order has an impact on the overall integration
|
||||||
# process, which may cause wedges in the gate later.
|
# process, which may cause wedges in the gate later.
|
||||||
click>=7.0 # BSD
|
click>=7.0 # BSD
|
||||||
|
cliff>=3.10.1 # Apache-2.0
|
||||||
requests>=2.14.2 # Apache-2.0
|
requests>=2.14.2 # Apache-2.0
|
||||||
|
Reference in New Issue
Block a user