Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def remove(obj: M, addons: Sequence[Defn]):
"Remove add-ons."
results = obj.m.run(obj.m.remove(addons))
Report(results.items()).generate_and_exit()
def install(obj: M, addons: Sequence[Defn], replace: bool):
"Install add-ons."
if not addons:
raise click.UsageError(
'You must provide at least one of "ADDONS", "--with-strategy", '
'"--version" or "--import"'
)
results = obj.m.run(obj.m.install(addons, replace))
Report(results.items()).generate_and_exit()
def update(obj: M, addons: Sequence[Defn]):
"Update installed add-ons."
def report_filter(result: E.ManagerResult):
# Hide package from output if up to date and ``update`` was invoked without args
return cast(bool, addons) or not isinstance(result, E.PkgUpToDate)
defns = addons or list(map(Defn.from_pkg, obj.m.db_session.query(models.Pkg).all()))
results = obj.m.run(obj.m.update(defns))
Report(results.items(), report_filter).generate_and_exit()
)
if len(versions) <= 1:
Report([(addon, E.PkgFileUnavailable('cannot find older versions'))]).generate_and_exit()
reconstructed_defn = Defn.from_pkg(pkg)
choices = [
Choice(
[('', v.version)], # type: ignore
disabled='installed version' if v.version == pkg.version else None,
)
for v in versions
]
selection = select(
f'Select version of {reconstructed_defn} for rollback', choices
).unsafe_ask()
Report(
chain(
manager.run(manager.remove([reconstructed_defn])).items(),
manager.run(
manager.install([reconstructed_defn.with_version(selection)], replace=False)
).items(),