Allow nvtake to update to a specific version

This is useful when the new version is somehow broken and you currently
can only update the software to a version in between. It's also useful
when you ran nvtake by accident and want to reset it back to the correct
old version.
This commit is contained in:
Felix Yan 2020-09-03 00:17:14 +08:00
parent 0eb5860584
commit 3591bd8ce8
No known key found for this signature in database
GPG key ID: 786C63F330D7CB92

View file

@ -18,7 +18,8 @@ def take() -> None:
parser.add_argument('--ignore-nonexistent', action='store_true',
help='ignore nonexistent names')
parser.add_argument('names', metavar='NAME', nargs='*',
help='software name to be updated')
help='software name to be updated. use NAME=VERSION to update '
'to a specific version instead of the new version.')
args = parser.parse_args()
if core.process_common_arguments(args):
return
@ -41,17 +42,21 @@ def take() -> None:
oldvers.update(newvers)
else:
for name in args.names:
try:
oldvers[name] = newvers[name]
except KeyError:
if args.ignore_nonexistent:
logger.warning('nonexistent in newver, ignored', name=name)
continue
if "=" in name:
name, newver = name.split("=")
oldvers[name] = newver
else:
try:
oldvers[name] = newvers[name]
except KeyError:
if args.ignore_nonexistent:
logger.warning('nonexistent in newver, ignored', name=name)
continue
logger.critical(
"doesn't exist in 'newver' set.", name=name,
)
sys.exit(2)
logger.critical(
"doesn't exist in 'newver' set.", name=name,
)
sys.exit(2)
try:
oldverf.rename(