Skip to content

Commit

Permalink
add an exclude option
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed May 14, 2020
1 parent c33a3bd commit 72e6b64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
5 changes: 4 additions & 1 deletion manic/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down Expand Up @@ -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():
Expand Down
20 changes: 12 additions & 8 deletions manic/externals_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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)))
Expand Down

0 comments on commit 72e6b64

Please sign in to comment.