Add force flag to fetch command

Force flag allows to cleanup directory before fetching repositories

Change-Id: I71f6522da8f0969387c24c82c121ce81d752ee90
This commit is contained in:
Sergey Reshetnyak 2017-01-30 11:37:57 +03:00
parent 4878237d89
commit 64100ecfe2
2 changed files with 25 additions and 1 deletions

View File

@ -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()

View File

@ -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()