Skip to content

Commit

Permalink
Merge pull request #283 from nephila/feature/delete_option
Browse files Browse the repository at this point in the history
Batch mode does not delete project by default
  • Loading branch information
yakky authored Aug 30, 2016
2 parents 90c30d7 + 958128e commit cdb3000
Show file tree
Hide file tree
Showing 36 changed files with 89 additions and 5 deletions.
3 changes: 2 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ History
* Make project-path option optional
* Batch mode is now the default one
* Add support for conda package manager
* Admin user is now created in batch mode by default. Use --no-user option to skip user creation.
* Admin user is now created in batch mode by default. Use --no-user option to skip user creation
* In batch mode directory is not removed in case of cleanup unless --delete-project-dir is given

0.8.12 (2016-08-27)
+++++++++++++++++++
Expand Down
5 changes: 5 additions & 0 deletions djangocms_installer/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def parse(args):
parser.add_argument('--skip-empty-check', '-s', dest='skip_project_dir_check',
action='store_true',
default=False, help='Skip the check if project dir is empty.')
parser.add_argument('--delete-project-dir', '-c', dest='delete_project_dir',
action='store_true',
default=False, help='Delete project directory on creation failure.')
parser.add_argument('--utc', dest='utc',
action='store_true',
default=False, help='Use UTC timezone.')
Expand All @@ -151,6 +154,8 @@ def parse(args):
args = parser.parse_args(config_args + args)
if not args.wizard:
args.noinput = True
else:
args.noinput = False

if not args.project_directory:
args.project_directory = args.project_name
Expand Down
8 changes: 5 additions & 3 deletions djangocms_installer/install/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def cleanup_directory(config_data):
Asks user for removal of project directory and eventually removes it
"""
if os.path.exists(config_data.project_directory):
choice = 'N'
choice = False
if config_data.noinput is False and not config_data.verbose:
choice = query_yes_no(
'The installation failed.\n'
Expand All @@ -125,8 +125,10 @@ def cleanup_directory(config_data):
'no'
)
else:
sys.stdout.write('The installation failed.\n')
if config_data.skip_project_dir_check is False and (choice or config_data.noinput):
sys.stdout.write('The installation has failed.\n')
if config_data.skip_project_dir_check is False and (choice or
(config_data.noinput and
config_data.delete_project_dir)):
sys.stdout.write('Removing everything under {0}\n'.format(
os.path.abspath(config_data.project_directory)
))
Expand Down
1 change: 1 addition & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ advanced usage:
It doesn't need to be a Python file, its content is blindly copied in the project settings.
* ``--skip-empty-check``, ``-s``: Skip the check if the project dir contains files or directory;
in case of error when setting up the project the existing directory will be preserved.
* ``--delete-project-dir``', ``-c``: Delete project directory on creation failure in :ref:`batch_mode`.



Expand Down
2 changes: 2 additions & 0 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ class TestBaseConfig(unittest.TestCase):
'no_plugins': False,
'verbose': False,
'wizard': False,
'delete_project_dir': False,
})

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -782,6 +783,7 @@ def test_parse_config_file(self, *args):
('config-27.ini', 'utc', True),
('config-28.ini', 'no_plugins', True),
('config-30.ini', 'verbose', True),
('config-32.ini', 'delete_project_dir', True),
]
fixture = copy.copy(self.config_fixture)
for filename, key, val in test_data:
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-01.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-02.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-03.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-04.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-05.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-06.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-07.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-08.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-09.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-10.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-11.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-12.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-13.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-14.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-15.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-16.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-17.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-18.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-19.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-20.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-21.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-22.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-23.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-24.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-25.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-26.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = false
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-27.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = true
no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-28.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ utc = true
no-plugins = true
verbose = false
wizard = false
delete-project-dir = false
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-30.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ utc = true
no-plugins = true
verbose = true
wizard = false
delete-project-dir = false

31 changes: 31 additions & 0 deletions tests/fixtures/configs/config-32.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[djangocms_installer]
db = postgres://user:pwd@host:54321/dbname
i18n = no
use-tz = no
timezone = Europe/London
reversion = no
permissions = no
languages = en,ru
django-version = stable
cms-version = 3.3
parent-dir = /test/me
bootstrap = yes
templates = .
starting-page = yes
list-plugins = true
dump-requirements = true
no-input = true
filer = true
requirements = /test/reqs
no-deps = true
no-db-driver = true
no-sync = true
no-user = true
template = /test/template
extra-settings = /test/extra_settings
skip-empty-check = true
utc = true
no-plugins = true
verbose = true
wizard = false
delete-project-dir = true
14 changes: 13 additions & 1 deletion tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,20 @@ def test_cleanup(self):
with patch('sys.stderr', self.stderr):
with self.assertRaises((CalledProcessError, EnvironmentError)):
sys.argv = ['main'] + ['--db=postgres://user:pwd@host/dbname',
'-len', '--no-db-driver',
'-len', '--no-db-driver', '-c',
'-q', '-u', '-p'+self.project_dir,
'example_prj']
main.execute()
self.assertFalse(os.path.exists(self.project_dir))

def test_no_cleanup(self):
with patch('sys.stdout', self.stdout):
with patch('sys.stderr', self.stderr):
with self.assertRaises((CalledProcessError, EnvironmentError)):
sys.argv = ['main'] + ['--db=postgres://user:pwd@host/dbname',
'-len', '--no-db-driver',
'-q', '-u', '-p' + self.project_dir,
'example_prj']
main.execute()
self.assertTrue(os.path.exists(self.project_dir))

0 comments on commit cdb3000

Please sign in to comment.