From 64100ecfe2a3e0bf4226864e1709835f45580c7b Mon Sep 17 00:00:00 2001 From: Sergey Reshetnyak Date: Mon, 30 Jan 2017 11:37:57 +0300 Subject: [PATCH] Add force flag to fetch command Force flag allows to cleanup directory before fetching repositories Change-Id: I71f6522da8f0969387c24c82c121ce81d752ee90 --- fuel_ccp/cli.py | 13 +++++++++++++ fuel_ccp/tests/test_cli.py | 13 ++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/fuel_ccp/cli.py b/fuel_ccp/cli.py index 14ec3917..896e2c12 100644 --- a/fuel_ccp/cli.py +++ b/fuel_ccp/cli.py @@ -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() diff --git a/fuel_ccp/tests/test_cli.py b/fuel_ccp/tests/test_cli.py index 48236705..920a2c16 100644 --- a/fuel_ccp/tests/test_cli.py +++ b/fuel_ccp/tests/test_cli.py @@ -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()