Skip to content

Commit 9d789b2

Browse files
committed
Implemented --ignore-missing and --uninstall-missing
1 parent fbff784 commit 9d789b2

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

shpc/client/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,21 @@ def get_parser():
149149
action="store_true",
150150
)
151151
reinstall.add_argument(
152-
"--force",
153-
"-f",
154-
dest="force",
152+
"--ignore-missing",
153+
"-i",
154+
dest="ignore_missing",
155155
help="Ignore and leave intact the versions that don't exist in the registry anymore.",
156156
default=False,
157157
action="store_true",
158158
)
159+
reinstall.add_argument(
160+
"--uninstall-missing",
161+
"-u",
162+
dest="uninstall_missing",
163+
help="Uninstall the versions that don't exist in the registry anymore.",
164+
default=False,
165+
action="store_true",
166+
)
159167

160168
# List installed modules
161169
listing = subparsers.add_parser("list", description="list installed modules.")

shpc/client/reinstall.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,19 @@ def main(args, parser, extra, subparser):
2828
# One option must be present
2929
if not args.reinstall_recipe and not args.all:
3030
logger.exit("Missing arguments: provide reinstall_recipe or --all.")
31+
if args.ignore_missing and args.uninstall_missing:
32+
logger.exit(
33+
"Conflicting arguments --ignore-missing and --uninstall-missing, choose one."
34+
)
3135

3236
# And do the reinstall
3337
cli.reinstall(
3438
args.reinstall_recipe,
35-
force=args.force,
39+
when_missing=(
40+
"ignore"
41+
if args.ignore_missing
42+
else "uninstall"
43+
if args.uninstall_missing
44+
else None
45+
),
3646
)

shpc/main/modules/base.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,37 +462,51 @@ def view_install(self, view_name, name, force=False):
462462
view.confirm_install(module.module_dir, force=force)
463463
view.install(module.module_dir)
464464

465-
def reinstall(self, module, force=False):
465+
def reinstall(self, name, when_missing=None):
466466
"""
467467
Reinstall the module, or all modules
468468
"""
469-
if module:
470-
module_name, _, version = module.partition(":")
469+
if name:
470+
module_name, _, version = name.partition(":")
471471
# Find all the versions currently installed
472472
installed_modules = self._get_module_lookup(
473473
self.settings.module_base, self.modulefile, module_name
474474
)
475475
if (module_name not in installed_modules) or (
476476
version and version not in installed_modules[module_name]
477477
):
478-
logger.exit("%s is not installed. Nothing to reinstall." % module)
478+
logger.exit("%s is not installed. Nothing to reinstall." % name)
479479
versions = [version] if version else installed_modules[module_name]
480480
# Reinstall the required version(s) one by one
481481
for version in versions:
482-
self.install(module_name + ":" + version, allow_reinstall=True)
482+
self._reinstall(module_name, version, when_missing)
483483
else:
484484
# Reinstall everything that is currently installed
485485
installed_modules = self._get_module_lookup(
486486
self.settings.module_base, self.modulefile
487487
)
488488
for module_name, versions in installed_modules.items():
489489
for version in versions:
490-
self.install(module_name + ":" + version, allow_reinstall=True)
490+
self._reinstall(module_name, version, when_missing)
491491

492-
def _reinstall(self, module_name, versions, upgrade=False, force=False):
492+
def _reinstall(self, module_name, version, when_missing):
493493
"""
494494
Reinstall (and possibly upgrade) all the current modules, possibly filtered by pattern.
495495
"""
496+
config = self.load_registry_config(module_name)
497+
if version in config.tags:
498+
self.install(module_name + ":" + version, allow_reinstall=True)
499+
elif when_missing == "ignore":
500+
pass
501+
elif when_missing == "uninstall":
502+
self.uninstall(module_name + ":" + version, force=True)
503+
else:
504+
logger.exit(
505+
"%s is not in the Registry any more. Add --uninstall-missing or --ignore-missing."
506+
% module_name
507+
)
508+
509+
def _upgrade(self, module_name, versions, upgrade=False, force=False):
496510
result = self.registry.find(module_name)
497511
if result:
498512

0 commit comments

Comments
 (0)