mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 23:10:24 +01:00
* move man doc links to descriptions, fix some help copies * minor init force message fix * deal with ugly inheritance in lock base * remove unnecessary super calls * add return back to python lock/unlock run functions
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
from __future__ import unicode_literals
|
|
|
|
import argparse
|
|
|
|
import dvc.logger as logger
|
|
from dvc.exceptions import DvcException
|
|
from dvc.command.base import CmdBase, append_doc_link
|
|
|
|
|
|
class CmdLockBase(CmdBase):
|
|
def _run(self, unlock):
|
|
for target in self.args.targets:
|
|
try:
|
|
self.repo.lock_stage(target, unlock=unlock)
|
|
except DvcException:
|
|
logger.error(
|
|
"failed to {}lock '{}'".format(
|
|
"un" if unlock else "", target
|
|
)
|
|
)
|
|
|
|
return 1
|
|
return 0
|
|
|
|
|
|
class CmdLock(CmdLockBase):
|
|
def run(self):
|
|
return self._run(False)
|
|
|
|
|
|
class CmdUnlock(CmdLockBase):
|
|
def run(self):
|
|
return self._run(True)
|
|
|
|
|
|
def add_parser(subparsers, parent_parser):
|
|
LOCK_HELP = "Lock DVC file."
|
|
lock_parser = subparsers.add_parser(
|
|
"lock",
|
|
parents=[parent_parser],
|
|
description=append_doc_link(LOCK_HELP, "lock"),
|
|
help=LOCK_HELP,
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
)
|
|
lock_parser.add_argument("targets", nargs="+", help="DVC files.")
|
|
lock_parser.set_defaults(func=CmdLock)
|
|
|
|
UNLOCK_HELP = "Unlock DVC file."
|
|
unlock_parser = subparsers.add_parser(
|
|
"unlock",
|
|
parents=[parent_parser],
|
|
description=append_doc_link(UNLOCK_HELP, "unlock"),
|
|
help=UNLOCK_HELP,
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
)
|
|
unlock_parser.add_argument("targets", nargs="+", help="DVC files.")
|
|
unlock_parser.set_defaults(func=CmdUnlock)
|