|
7 | 7 | from django.core.management.base import BaseCommand, CommandError |
8 | 8 |
|
9 | 9 | import mod_wsgi.express |
| 10 | +import mod_wsgi.express.options |
| 11 | +import mod_wsgi.express.server |
10 | 12 |
|
11 | 13 | def check_percentage(string): |
12 | | - if value is not None and value < 0 or value > 1: |
| 14 | + value = float(string) |
| 15 | + if value < 0 or value > 1: |
13 | 16 | import argparse |
14 | 17 | msg = '%s option value needs to be within the range 0 to 1.' % string |
15 | 18 | raise argparse.ArgumentTypeError(msg) |
@@ -48,6 +51,20 @@ def add_arguments(self, parser): |
48 | 51 | elif attr == 'default': |
49 | 52 | if getattr(option, attr) != ('NO', 'DEFAULT'): |
50 | 53 | kwargs[attr] = getattr(option, attr) |
| 54 | + elif attr == 'help': |
| 55 | + # optparse displays help text literally, but |
| 56 | + # argparse expands it with '%'-formatting. Escape |
| 57 | + # any literal '%' (e.g. the '%{GLOBAL}' token) and |
| 58 | + # translate the optparse '%default'/'%prog' tokens |
| 59 | + # to their argparse equivalents. |
| 60 | + help_text = getattr(option, attr) |
| 61 | + if help_text is not None: |
| 62 | + help_text = help_text.replace('%', '%%') |
| 63 | + help_text = help_text.replace( |
| 64 | + '%%default', '%(default)s') |
| 65 | + help_text = help_text.replace( |
| 66 | + '%%prog', '%(prog)s') |
| 67 | + kwargs[attr] = help_text |
51 | 68 | else: |
52 | 69 | if getattr(option, attr) is not None: |
53 | 70 | kwargs[attr] = getattr(option, attr) |
|
0 commit comments