Skip to content

Commit

Permalink
Merge pull request #280 from nephila/feature/one_command
Browse files Browse the repository at this point in the history
Enable batch mode by default
  • Loading branch information
yakky committed Aug 27, 2016
2 parents bdc86f0 + d482b82 commit 9777f4b
Show file tree
Hide file tree
Showing 35 changed files with 82 additions and 63 deletions.
24 changes: 15 additions & 9 deletions djangocms_installer/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ def parse(args):
parser = argparse.ArgumentParser(description="""Bootstrap a django CMS project.
Major usage modes:
- wizard: djangocms -p /path/whatever project_name: ask for all the options through a CLI wizard.
- wizard: djangocms -w -p /path/whatever project_name: ask for all the options through a
CLI wizard.
- batch: djangocms -q -p /path/whatever project_name: runs with the default values plus any
- batch: djangocms project_name: runs with the default values plus any
additional option provided (see below) with no question asked.
- config file: djangocms_installer --config-file /path/to/config.ini project_name: reads values
Expand Down Expand Up @@ -78,7 +79,7 @@ def parse(args):
choices=data.DJANGOCMS_SUPPORTED,
default='stable', help='django CMS version')
parser.add_argument('--parent-dir', '-p', dest='project_directory',
required=True, default='',
default='',
action='store', help='Optional project parent directory')
parser.add_argument('--bootstrap', dest='bootstrap', action='store',
choices=('yes', 'no'),
Expand Down Expand Up @@ -106,8 +107,10 @@ def parse(args):
# Advanced options. These have a predefined default and are not asked
# by config wizard.
parser.add_argument('--no-input', '-q', dest='noinput', action='store_true',
default=False, help='Don\'t run the configuration wizard, just use the '
'provided values')
default=True, help='Don\'t run the configuration wizard, just use the '
'provided values')
parser.add_argument('--wizard', '-w', dest='wizard', action='store_true',
default=False, help='Run the configuration wizard')
parser.add_argument('--verbose', dest='verbose', action='store_true',
default=False,
help='Be more verbose and don\'t swallow subcommands output')
Expand Down Expand Up @@ -146,6 +149,11 @@ def parse(args):
# If config_args then pretend that config args came from the stdin and run parser again.
config_args = ini.parse_config_file(parser, args)
args = parser.parse_args(config_args + args)
if not args.wizard:
args.noinput = True

if not args.project_directory:
args.project_directory = args.project_name

# First of all, check if the project name is valid
if not validate_project(args.project_name):
Expand All @@ -156,8 +164,7 @@ def parse(args):
sys.exit(3)

# Checking the given path
setattr(args, 'project_path',
os.path.join(args.project_directory, args.project_name).strip())
setattr(args, 'project_path', os.path.join(args.project_directory, args.project_name).strip())
if not args.skip_project_dir_check:
if (os.path.exists(args.project_directory) and
[path for path in os.listdir(args.project_directory) if not path.startswith('.')]):
Expand Down Expand Up @@ -206,8 +213,7 @@ def parse(args):

# Convert version to numeric format for easier checking
try:
django_version, cms_version = supported_versions(args.django_version,
args.cms_version)
django_version, cms_version = supported_versions(args.django_version, args.cms_version)
except RuntimeError as e:
sys.stderr.write(compat.unicode(e))
sys.exit(6)
Expand Down
10 changes: 7 additions & 3 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ Arguments reference
Required arguments
------------------

You must always provide the following arguments when invoking **djangocms installer**:
You must always provide the following argument when invoking **djangocms installer**:

* ``project_name``: Name of the project to be created
* ``--parent-dir``, ``-p``: Optional project directory;

Optionally you can provide a project directory, otherwise a directory named after the project name
will be created in the current directory.

.. warning:: project directory dir is the main project directory (the one where ``manage.py``
will be created); by default the installer check if it's empty (minus hidden files)
Expand Down Expand Up @@ -56,7 +58,9 @@ Advanced options
The following options are not managed by the config wizard and are meant for
advanced usage:

* ``--no-input``, ``-q``: If given **djangocms installer** run in :ref:`batch_mode`;
* ``--no-input``, ``-q``: If given **djangocms installer** run in :ref:`batch_mode` (default behavior);
* ``--wizard``, ``-w``: If given **djangocms installer** run in :ref:`wizard_mode`;
* ``--parent-dir``, ``-p``: Optional project directory;
* ``--verbose``, : Provides output of the commands used to setup the project, namely ``pip`` and
``django-admin``;
* ``--filer``, ``-f``: Install and configure django-filer plugins; since 0.9 this is enabled by default
Expand Down
32 changes: 16 additions & 16 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ By default it:
**djangocms installer** works as a batch script and as a command line wizard.



.. _batch_mode:

Batch mode (default)
--------------------

In batch mode **djangocms installer** will use the arguments
provided to create and configure the project.
All the paramaters asked by the wizard can be passed as command line arguments.

See :ref:`arguments` for arguments reference


.. _wizard_mode:

Wizard mode
-----------

Wizard mode works by asking relevant questions to the user; it must be called with
the `-p` option (which is the project main directory) and the `project_name`
argument::
Wizard mode works by asking relevant questions to the user; it can be invoked with ``-w`` option::

djangocms -p /path/whatever project_name
djangocms -w -p /path/whatever project_name

A wizard will ask for the missing parameters; for most of them sane defaults are
provided, but you're free to adapt to your own needs.
The only required parameters are the database name, in url format, and the
project languages, as a comma separated list.

.. _batch_mode:

Batch mode
----------

By giving the `-q` parameter **djangocms installer** will use the arguments
provided to create and configure the project.
All the paramaters asked by the wizard can be passed as command line arguments.

See :ref:`arguments` for arguments reference


.. _dump_mode:

Expand Down Expand Up @@ -142,7 +142,7 @@ HOWTO

#. Execute the wizard::

djangocms -p /path/whatever project_name
djangocms project_name

#. Answer the wizard questions;

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

def __init__(self, *args, **kwargs):
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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = false
29 changes: 0 additions & 29 deletions tests/fixtures/configs/config-10b.ini

This file was deleted.

1 change: 1 addition & 0 deletions tests/fixtures/configs/config-11.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = false
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = true
utc = false
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = true
utc = true
no-plugins = false
verbose = false
wizard = 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 @@ -27,3 +27,4 @@ skip-empty-check = true
utc = true
no-plugins = true
verbose = false
wizard = false
1 change: 1 addition & 0 deletions tests/fixtures/configs/config-30.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ skip-empty-check = true
utc = true
no-plugins = true
verbose = true
wizard = false
20 changes: 14 additions & 6 deletions tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import os
import sys
from subprocess import CalledProcessError
from tempfile import mkdtemp

from mock import patch
from shutil import rmtree

from djangocms_installer import config, install, main

Expand Down Expand Up @@ -72,22 +74,28 @@ def cleanup_skip(self):
self.assertTrue(os.path.exists(self.project_dir))

def test_main_invocation(self):
base_dir = mkdtemp()
project_dir = os.path.join(base_dir, 'example_prj')
original_dir = os.getcwd()
os.chdir(base_dir)
with patch('sys.stdout', self.stdout):
with patch('sys.stderr', self.stderr):
sys.argv = ['main'] + ['--db=sqlite://localhost/test.db',
'-len', '--cms-version=stable', '--django=%s' % dj_ver,
'-q', '-u', '-p'+self.project_dir, '--verbose',
'-q', '-u', '--verbose',
'example_prj']
main.execute()
self.assertTrue(os.path.exists(os.path.join(self.project_dir, 'static')))
self.assertTrue(os.path.exists(os.path.join(self.project_dir, 'requirements.txt')))
self.assertTrue(os.path.exists(os.path.join(self.project_dir, 'example_prj', 'static')))
with open(os.path.join(self.project_dir, 'requirements.txt'), 'r') as req_file:
self.assertTrue(os.path.exists(os.path.join(project_dir, 'static')))
self.assertTrue(os.path.exists(os.path.join(project_dir, 'requirements.txt')))
self.assertTrue(os.path.exists(os.path.join(project_dir, 'example_prj', 'static')))
with open(os.path.join(project_dir, 'requirements.txt'), 'r') as req_file:
text = req_file.read()
self.assertTrue(text.find('djangocms-text-ckeditor') > -1)
# Checking we successfully completed the whole process
self.assertTrue('Successfully installed ' in self.stdout.getvalue())
self.assertTrue(('Get into "%s" directory and type "python manage.py runserver" to start your project' % self.project_dir) in self.stdout.getvalue())
self.assertTrue(('Get into "%s" directory and type "python manage.py runserver" to start your project' % project_dir) in self.stdout.getvalue())
os.chdir(original_dir)
rmtree(base_dir)

def test_two_langs_invocation(self):
with patch('sys.stdout', self.stdout):
Expand Down

0 comments on commit 9777f4b

Please sign in to comment.