Skip to content

Commit 72e6b64

Browse files
committed
add an exclude option
1 parent c33a3bd commit 72e6b64

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

manic/checkout.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ def commandline_arguments(args=None):
279279
help='The externals description filename. '
280280
'Default: %(default)s.')
281281

282+
parser.add_argument('-x', '--exclude', nargs='*',
283+
help='Component(s) listed in the externals file which should be ignored.' )
284+
282285
parser.add_argument('-o', '--optional', action='store_true', default=False,
283286
help='By default only the required externals '
284287
'are checked out. This flag will also checkout the '
@@ -362,7 +365,7 @@ def main(args):
362365
root_dir = os.path.abspath(os.getcwd())
363366
external_data = read_externals_description_file(root_dir, args.externals)
364367
external = create_externals_description(
365-
external_data, components=args.components)
368+
external_data, components=args.components, exclude=args.exclude)
366369

367370
for comp in args.components:
368371
if comp not in external.keys():

manic/externals_description.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,18 @@ def read_gitmodules_file(root_dir, file_name):
264264
return externals_description
265265

266266
def create_externals_description(
267-
model_data, model_format='cfg', components=None, parent_repo=None):
267+
model_data, model_format='cfg', components=None, exclude=None, parent_repo=None):
268268
"""Create the a externals description object from the provided data
269269
"""
270270
externals_description = None
271271
if model_format == 'dict':
272272
externals_description = ExternalsDescriptionDict(
273-
model_data, components=components)
273+
model_data, components=components, exclude=exclude)
274274
elif model_format == 'cfg':
275275
major, _, _ = get_cfg_schema_version(model_data)
276276
if major == 1:
277277
externals_description = ExternalsDescriptionConfigV1(
278-
model_data, components=components, parent_repo=parent_repo)
278+
model_data, components=components, exclude=exclude, parent_repo=parent_repo)
279279
else:
280280
msg = ('Externals description file has unsupported schema '
281281
'version "{0}".'.format(major))
@@ -710,7 +710,7 @@ class ExternalsDescriptionDict(ExternalsDescription):
710710
711711
"""
712712

713-
def __init__(self, model_data, components=None):
713+
def __init__(self, model_data, components=None, exclude=None):
714714
"""Parse a native dictionary into a externals description.
715715
"""
716716
ExternalsDescription.__init__(self)
@@ -725,6 +725,10 @@ def __init__(self, model_data, components=None):
725725
for key in model_data.items():
726726
if key not in components:
727727
del model_data[key]
728+
if exclude:
729+
for key in model_data.items():
730+
if key in exclude:
731+
del model_data[key]
728732

729733
self.update(model_data)
730734
self._check_user_input()
@@ -736,7 +740,7 @@ class ExternalsDescriptionConfigV1(ExternalsDescription):
736740
737741
"""
738742

739-
def __init__(self, model_data, components=None, parent_repo=None):
743+
def __init__(self, model_data, components=None, exclude=None, parent_repo=None):
740744
"""Convert the config data into a standardized dict that can be used to
741745
construct the source objects
742746
@@ -749,7 +753,7 @@ def __init__(self, model_data, components=None, parent_repo=None):
749753
get_cfg_schema_version(model_data)
750754
self._verify_schema_version()
751755
self._remove_metadata(model_data)
752-
self._parse_cfg(model_data, components=components)
756+
self._parse_cfg(model_data, components=components, exclude=exclude)
753757
self._check_user_input()
754758

755759
@staticmethod
@@ -761,7 +765,7 @@ def _remove_metadata(model_data):
761765
"""
762766
model_data.remove_section(DESCRIPTION_SECTION)
763767

764-
def _parse_cfg(self, cfg_data, components=None):
768+
def _parse_cfg(self, cfg_data, components=None, exclude=None):
765769
"""Parse a config_parser object into a externals description.
766770
"""
767771
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):
778782

779783
for section in cfg_data.sections():
780784
name = config_string_cleaner(section.lower().strip())
781-
if components and name not in components:
785+
if (components and name not in components) or (exclude and name in exclude):
782786
continue
783787
self[name] = {}
784788
self[name].update(list_to_dict(cfg_data.items(section)))

0 commit comments

Comments
 (0)