cli: add gc option to include additional projects

This commit is contained in:
buec
2018-11-07 18:03:41 +01:00
parent 111c51f44b
commit 19eeb62e6e
3 changed files with 37 additions and 5 deletions
+7
View File
@@ -591,6 +591,13 @@ def parse_args(argv=None):
type=int,
default=None,
help='Number of jobs to run simultaneously.')
gc_parser.add_argument(
'-p',
'--projects',
type=str,
nargs='*',
default=None,
help='Collect garbage for all given projects.')
gc_parser.set_defaults(func=CmdGC)
# Config
+16 -5
View File
@@ -1,3 +1,5 @@
import os
from dvc.command.base import CmdBase
@@ -5,13 +7,21 @@ class CmdGC(CmdBase):
def run(self):
msg = 'This will remove all cache except the cache that is used in '
if not self.args.all_branches and not self.args.all_tags:
msg += 'the current git branch.'
msg += 'the current git branch'
elif self.args.all_branches and not self.args.all_tags:
msg += 'all git branches.'
msg += 'all git branches'
elif not self.args.all_branches and self.args.all_tags:
msg += 'all git tags.'
msg += 'all git tags'
else:
msg += 'all git branches and all git tags.'
msg += 'all git branches and all git tags'
if self.args.projects is not None and len(self.args.projects) > 0:
msg += ' of the current and the following projects:'
for project_path in self.args.projects:
msg += '\n - %s' % os.path.abspath(project_path)
else:
msg += ' of the current project.'
self.project.logger.warn(msg)
@@ -24,5 +34,6 @@ class CmdGC(CmdBase):
cloud=self.args.cloud,
remote=self.args.remote,
force=self.args.force,
jobs=self.args.jobs)
jobs=self.args.jobs,
projects=self.args.projects)
return 0
+14
View File
@@ -129,6 +129,20 @@ class TestGC(TestDvc):
self.assertIsInstance(args.func(args), CmdGC)
class TestGCMultipleProjects(TestDvc):
def test(self):
args = parse_args([
'gc',
'-p',
'/tmp/asdf',
'/tmp/xyz'
])
self.assertIsInstance(args.func(args), CmdGC)
self.assertEqual(args.projects, ['/tmp/asdf', '/tmp/xyz'])
class TestConfig(TestDvc):
def test(self):
name = 'param'