From 72e6b64aef25c1e58147130f1a6f98bae6f3a1d7 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 14 May 2020 16:01:45 -0600 Subject: [PATCH] add an exclude option --- manic/checkout.py | 5 ++++- manic/externals_description.py | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/manic/checkout.py b/manic/checkout.py index edc5655954..793002d58b 100755 --- a/manic/checkout.py +++ b/manic/checkout.py @@ -279,6 +279,9 @@ def commandline_arguments(args=None): help='The externals description filename. ' 'Default: %(default)s.') + parser.add_argument('-x', '--exclude', nargs='*', + help='Component(s) listed in the externals file which should be ignored.' ) + parser.add_argument('-o', '--optional', action='store_true', default=False, help='By default only the required externals ' 'are checked out. This flag will also checkout the ' @@ -362,7 +365,7 @@ def main(args): root_dir = os.path.abspath(os.getcwd()) external_data = read_externals_description_file(root_dir, args.externals) external = create_externals_description( - external_data, components=args.components) + external_data, components=args.components, exclude=args.exclude) for comp in args.components: if comp not in external.keys(): diff --git a/manic/externals_description.py b/manic/externals_description.py index bd644c9814..4c0d6971be 100644 --- a/manic/externals_description.py +++ b/manic/externals_description.py @@ -264,18 +264,18 @@ def read_gitmodules_file(root_dir, file_name): return externals_description def create_externals_description( - model_data, model_format='cfg', components=None, parent_repo=None): + model_data, model_format='cfg', components=None, exclude=None, parent_repo=None): """Create the a externals description object from the provided data """ externals_description = None if model_format == 'dict': externals_description = ExternalsDescriptionDict( - model_data, components=components) + model_data, components=components, exclude=exclude) elif model_format == 'cfg': major, _, _ = get_cfg_schema_version(model_data) if major == 1: externals_description = ExternalsDescriptionConfigV1( - model_data, components=components, parent_repo=parent_repo) + model_data, components=components, exclude=exclude, parent_repo=parent_repo) else: msg = ('Externals description file has unsupported schema ' 'version "{0}".'.format(major)) @@ -710,7 +710,7 @@ class ExternalsDescriptionDict(ExternalsDescription): """ - def __init__(self, model_data, components=None): + def __init__(self, model_data, components=None, exclude=None): """Parse a native dictionary into a externals description. """ ExternalsDescription.__init__(self) @@ -725,6 +725,10 @@ def __init__(self, model_data, components=None): for key in model_data.items(): if key not in components: del model_data[key] + if exclude: + for key in model_data.items(): + if key in exclude: + del model_data[key] self.update(model_data) self._check_user_input() @@ -736,7 +740,7 @@ class ExternalsDescriptionConfigV1(ExternalsDescription): """ - def __init__(self, model_data, components=None, parent_repo=None): + def __init__(self, model_data, components=None, exclude=None, parent_repo=None): """Convert the config data into a standardized dict that can be used to construct the source objects @@ -749,7 +753,7 @@ def __init__(self, model_data, components=None, parent_repo=None): get_cfg_schema_version(model_data) self._verify_schema_version() self._remove_metadata(model_data) - self._parse_cfg(model_data, components=components) + self._parse_cfg(model_data, components=components, exclude=exclude) self._check_user_input() @staticmethod @@ -761,7 +765,7 @@ def _remove_metadata(model_data): """ model_data.remove_section(DESCRIPTION_SECTION) - def _parse_cfg(self, cfg_data, components=None): + def _parse_cfg(self, cfg_data, components=None, exclude=None): """Parse a config_parser object into a externals description. """ def list_to_dict(input_list, convert_to_lower_case=True): @@ -778,7 +782,7 @@ def list_to_dict(input_list, convert_to_lower_case=True): for section in cfg_data.sections(): name = config_string_cleaner(section.lower().strip()) - if components and name not in components: + if (components and name not in components) or (exclude and name in exclude): continue self[name] = {} self[name].update(list_to_dict(cfg_data.items(section)))