summaryrefslogtreecommitdiff
path: root/src/server/management/commands
diff options
context:
space:
mode:
authorGraham Dumpleton <Graham.Dumpleton@gmail.com>2016-09-02 11:40:30 +1000
committerGraham Dumpleton <Graham.Dumpleton@gmail.com>2016-09-02 11:40:30 +1000
commit7512d9a7efb1a30ce58d4c03b9e355b0666ae29b (patch)
tree0496f811089a69dfa79fc0f0af48099abb9267d7 /src/server/management/commands
parente9da6e86b59eec8fbb98c644675a0d7f41feee6c (diff)
parent785ce986646bd83dd2a7c6066db87885918c8b7d (diff)
downloadmod_wsgi-4.5.6.tar.gz
Merge branch 'release/4.5.6'4.5.6
Diffstat (limited to 'src/server/management/commands')
-rw-r--r--src/server/management/commands/runmodwsgi.py57
1 files changed, 54 insertions, 3 deletions
diff --git a/src/server/management/commands/runmodwsgi.py b/src/server/management/commands/runmodwsgi.py
index 02ba17a..74eaf13 100644
--- a/src/server/management/commands/runmodwsgi.py
+++ b/src/server/management/commands/runmodwsgi.py
@@ -6,11 +6,60 @@ from django.core.management.base import BaseCommand
import mod_wsgi.server
+def check_percentage(string):
+ if value is not None and value < 0 or value > 1:
+ import argparse
+ msg = '%s option value needs to be within the range 0 to 1.' % string
+ raise argparse.ArgumentTypeError(msg)
+ return value
+
class Command(BaseCommand):
- option_list = BaseCommand.option_list + mod_wsgi.server.option_list
+
args = ''
help = 'Starts Apache/mod_wsgi web server.'
+ if hasattr('BaseCommand', 'option_list'):
+ # Used prior to Django 1.10.
+
+ option_list = BaseCommand.option_list + mod_wsgi.server.option_list
+
+ else:
+ # This horrible mess tries to convert optparse option list to
+ # argparse as required by Django 1.10+. We can't switch to
+ # using argparse as need to still support Python 2.6, which
+ # lacks the argparse module.
+
+ def add_arguments(self, parser):
+ ignore = set(['const', 'callback', 'callback_args',
+ 'callback_kwargs'])
+ types = { 'int': int, 'string': str }
+
+ for option in mod_wsgi.server.option_list:
+ opts = option._short_opts + option._long_opts
+ kwargs = {}
+
+ for attr in option.ATTRS:
+ if attr not in ignore and hasattr(option, attr):
+ if attr == 'type':
+ if getattr(option, attr) in types:
+ kwargs[attr] = types[getattr(option, attr)]
+ elif attr == 'default':
+ if getattr(option, attr) != ('NO', 'DEFAULT'):
+ kwargs[attr] = getattr(option, attr)
+ else:
+ if getattr(option, attr) is not None:
+ kwargs[attr] = getattr(option, attr)
+
+ if (kwargs.get('action') == 'callback' and
+ option.callback.__name__ == 'check_percentage'):
+ del kwargs['action']
+ kwargs['type'] = check_percentage
+
+ if kwargs.get('nargs') == 1:
+ del kwargs['nargs']
+
+ parser.add_argument(*opts, **kwargs)
+
def handle(self, *args, **options):
self.stdout.write('Successfully ran command.')
@@ -36,8 +85,10 @@ class Command(BaseCommand):
if hasattr(settings, 'BASE_DIR'):
options['working_directory'] = settings.BASE_DIR
else:
- settings_mod = sys.modules[os.environ['DJANGO_SETTINGS_MODULE']]
- parent = os.path.dirname(os.path.dirname(settings_mod.__file__))
+ settings_module_path = os.environ['DJANGO_SETTINGS_MODULE']
+ root_module_path = settings_module_path.split('.')[0]
+ root_module = sys.modules[root_module_path]
+ parent = os.path.dirname(os.path.dirname(root_module.__file__))
options['working_directory'] = parent
url_aliases = options.setdefault('url_aliases') or []