Merge "Add force flag to fetch command"
This commit is contained in:
commit
c980998c42
|
@ -3,6 +3,7 @@ from __future__ import print_function
|
|||
import argparse
|
||||
import logging
|
||||
import os.path
|
||||
import shutil
|
||||
import signal
|
||||
import sys
|
||||
|
||||
|
@ -104,7 +105,19 @@ def do_fetch():
|
|||
class Fetch(BaseCommand):
|
||||
"""Fetch all repos with components definitions"""
|
||||
|
||||
def get_parser(self, *args, **kwargs):
|
||||
parser = super(Fetch, self).get_parser(*args, **kwargs)
|
||||
parser.add_argument("-f", "--force",
|
||||
action="store_true",
|
||||
help="Cleanup component directory before fetching")
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
if parsed_args.force:
|
||||
comp_dir = CONF.repositories.path
|
||||
if os.path.exists(comp_dir):
|
||||
LOG.info("Delete directory %s", comp_dir)
|
||||
shutil.rmtree(comp_dir)
|
||||
do_fetch()
|
||||
|
||||
|
||||
|
|
|
@ -146,9 +146,20 @@ class TestDeploy(TestParser):
|
|||
|
||||
class TestFetch(TestParser):
|
||||
cmd = 'fetch'
|
||||
scenarios = [('empty', {'argv': []})]
|
||||
scenarios = [
|
||||
('empty', {
|
||||
'argv': [],
|
||||
'margs': {'force': False}
|
||||
}),
|
||||
('force', {
|
||||
'argv': ['--force'],
|
||||
'margs': {'force': True}
|
||||
})
|
||||
]
|
||||
|
||||
def test_parser(self):
|
||||
self.useFixture(fixtures.MockPatch('os.path.exists',
|
||||
return_value=False))
|
||||
self._run_app()
|
||||
self.fetch_mock.assert_called_once_with()
|
||||
|
||||
|
|
Loading…
Reference in New Issue