Merge pull request #2012 from normanjaeckel/DevOption

Changed name of '--development' option and name of the respective dir…
This commit is contained in:
Emanuel Schütze 2016-03-02 08:18:37 +01:00
commit bab909713a
7 changed files with 42 additions and 35 deletions

4
.gitignore vendored
View File

@ -12,8 +12,8 @@
node_modules/* node_modules/*
bower_components/* bower_components/*
# Development user data (settings, database, media, search index, static files) # Local user data (settings, database, media, search index, static files)
development/* personal_data/*
openslides/static/* openslides/static/*
# Package building/IDE # Package building/IDE

View File

@ -56,7 +56,8 @@ Other:
- Updated to Bootstrap 3. - Updated to Bootstrap 3.
- Used SockJS for automatic update of AngularJS driven single page frontend. - Used SockJS for automatic update of AngularJS driven single page frontend.
- Refactored plugin API. - Refactored plugin API.
- Refactored start script and management commands. - Refactored start script and management commands. Changed command line
options and path for local installation.
- Refactored tests. - Refactored tests.
- Used Bower and gulp to manage third party JavaScript and Cascading Style - Used Bower and gulp to manage third party JavaScript and Cascading Style
Sheets libraries. Sheets libraries.

View File

@ -149,6 +149,12 @@ To get help on the command line options run::
openslides --help openslides --help
You can store settings, database and other personal files in a local
subdirectory and use these files e. g. if you want to run multiple
instances of OpenSlides::
openslides --local-installation
V. Development V. Development
============== ==============
@ -214,7 +220,7 @@ Installation and start of the development version
python manage.py start python manage.py start
This will create a new development directoy with settings.py and database. This will create a new directoy with settings.py and database.
To get help on the command-line options run:: To get help on the command-line options run::

View File

@ -10,8 +10,8 @@ from openslides.utils.main import (
ExceptionArgumentParser, ExceptionArgumentParser,
UnknownCommand, UnknownCommand,
get_default_settings_path, get_default_settings_path,
get_development_settings_path, get_local_settings_path,
is_development, is_local_installation,
setup_django_settings_module, setup_django_settings_module,
start_browser, start_browser,
write_settings, write_settings,
@ -32,8 +32,8 @@ def main():
if unknown_command: if unknown_command:
# Run a command, that is defined by the django management api # Run a command, that is defined by the django management api
development = is_development() local_installation = is_local_installation()
setup_django_settings_module(development=development) setup_django_settings_module(local_installation=local_installation)
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)
else: else:
# Run a command that is defined here # Run a command that is defined here
@ -45,7 +45,7 @@ def get_parser():
""" """
Parses all command line arguments. Parses all command line arguments.
""" """
if len(sys.argv) == 1 and not is_development(): if len(sys.argv) == 1 and not is_local_installation():
sys.argv.append('start') sys.argv.append('start')
# Init parser # Init parser
@ -104,9 +104,9 @@ def get_parser():
help='The used settings file. The file is created, if it does not exist.') help='The used settings file. The file is created, if it does not exist.')
subcommand_start.set_defaults(callback=start) subcommand_start.set_defaults(callback=start)
subcommand_start.add_argument( subcommand_start.add_argument(
'--development', '--local-installation',
action='store_true', action='store_true',
help='Option for development purposes.') help='Store settings and user files in a local directory.')
# Subcommand createsettings # Subcommand createsettings
createsettings_help = 'Creates the settings file.' createsettings_help = 'Creates the settings file.'
@ -121,9 +121,9 @@ def get_parser():
default=None, default=None,
help='The used settings file. The file is created, even if it exists.') help='The used settings file. The file is created, even if it exists.')
subcommand_createsettings.add_argument( subcommand_createsettings.add_argument(
'--development', '--local-installation',
action='store_true', action='store_true',
help='Option for development purposes.') help='Store settings and user files in a local directory.')
# Help text for several Django subcommands # Help text for several Django subcommands
django_subcommands = ( django_subcommands = (
@ -147,11 +147,11 @@ def start(args):
Starts OpenSlides: Runs migrations and runs runserver. Starts OpenSlides: Runs migrations and runs runserver.
""" """
settings_path = args.settings_path settings_path = args.settings_path
development = is_development() local_installation = is_local_installation()
if settings_path is None: if settings_path is None:
if development: if local_installation:
settings_path = get_development_settings_path() settings_path = get_local_settings_path()
else: else:
settings_path = get_default_settings_path() settings_path = get_default_settings_path()
@ -161,7 +161,7 @@ def start(args):
# Set the django setting module and run migrations # Set the django setting module and run migrations
# A manual given environment variable will be overwritten # A manual given environment variable will be overwritten
setup_django_settings_module(settings_path, development=development) setup_django_settings_module(settings_path, local_installation=local_installation)
execute_from_command_line(['manage.py', 'migrate']) execute_from_command_line(['manage.py', 'migrate'])
@ -178,14 +178,14 @@ def createsettings(args):
Creates settings for OpenSlides. Creates settings for OpenSlides.
""" """
settings_path = args.settings_path settings_path = args.settings_path
development = is_development() local_installation = is_local_installation()
context = {} context = {}
if development: if local_installation:
if settings_path is None: if settings_path is None:
settings_path = get_development_settings_path() settings_path = get_local_settings_path()
context = { context = {
'openslides_user_data_path': repr(os.path.join(os.getcwd(), 'development', 'var')), 'openslides_user_data_path': repr(os.path.join(os.getcwd(), 'personal_data', 'var')),
'debug': 'True'} 'debug': 'True'}
settings_path = write_settings(settings_path, **context) settings_path = write_settings(settings_path, **context)

View File

@ -82,16 +82,16 @@ def get_default_settings_path(openslides_type=None):
return os.path.join(parent_directory, 'openslides', 'settings.py') return os.path.join(parent_directory, 'openslides', 'settings.py')
def get_development_settings_path(): def get_local_settings_path():
""" """
Returns the path to a local development settings. Returns the path to a local settings.
On Unix systems: 'development/var/settings.py' On Unix systems: 'personal_data/var/settings.py'
""" """
return os.path.join('development', 'var', 'settings.py') return os.path.join('personal_data', 'var', 'settings.py')
def setup_django_settings_module(settings_path=None, development=None): def setup_django_settings_module(settings_path=None, local_installation=None):
""" """
Sets the environment variable ENVIRONMENT_VARIABLE, that means Sets the environment variable ENVIRONMENT_VARIABLE, that means
'DJANGO_SETTINGS_MODULE', to the given settings. 'DJANGO_SETTINGS_MODULE', to the given settings.
@ -106,8 +106,8 @@ def setup_django_settings_module(settings_path=None, development=None):
return return
if settings_path is None: if settings_path is None:
if development: if local_installation:
settings_path = get_development_settings_path() settings_path = get_local_settings_path()
else: else:
settings_path = get_default_settings_path() settings_path = get_default_settings_path()
@ -307,10 +307,10 @@ def translate_customizable_strings(language_code):
activate(current_language) activate(current_language)
def is_development(): def is_local_installation():
""" """
Returns True if the command is called for development. Returns True if the command is called for a local installation
This is the case if manage.py is used, or when the --development flag is set. This is the case if manage.py is used, or when the --local-installation flag is set.
""" """
return True if '--development' in sys.argv or 'manage.py' in sys.argv[0] else False return True if '--local-installation' in sys.argv or 'manage.py' in sys.argv[0] else False

View File

@ -2,7 +2,7 @@
source = openslides source = openslides
[coverage:html] [coverage:html]
directory = development/tmp/htmlcov directory = personal_data/tmp/htmlcov
[flake8] [flake8]
max_line_length = 150 max_line_length = 150

View File

@ -55,8 +55,8 @@ class TestFunctions(TestCase):
self.assertEqual(main.get_default_settings_path(main.WINDOWS_PORTABLE_VERSION), self.assertEqual(main.get_default_settings_path(main.WINDOWS_PORTABLE_VERSION),
'portable/openslides/settings.py') 'portable/openslides/settings.py')
def test_get_development_settings_path(self): def test_get_local_settings_path(self):
self.assertEqual(main.get_development_settings_path(), os.sep.join(('development', 'var', 'settings.py'))) self.assertEqual(main.get_local_settings_path(), os.sep.join(('personal_data', 'var', 'settings.py')))
def test_setup_django_settings_module(self): def test_setup_django_settings_module(self):
main.setup_django_settings_module('test_dir_dhvnghfjdh456fzheg2f/test_path_bngjdhc756dzwncshdfnx.py') main.setup_django_settings_module('test_dir_dhvnghfjdh456fzheg2f/test_path_bngjdhc756dzwncshdfnx.py')