Skip to content

Commit 6eec4c2

Browse files
committed
Converted all management commands which set up additional command-line switches to use the argparse approach instead of the deprecated optparse approach.
- Legacy-Id: 12645
1 parent 7b95411 commit 6eec4c2

11 files changed

Lines changed: 80 additions & 81 deletions

File tree

ietf/ipr/management/commands/process_email.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys
2-
from optparse import make_option
32

43
from django.core.management.base import BaseCommand, CommandError
54

@@ -9,8 +8,9 @@
98

109
class Command(BaseCommand):
1110
help = (u"Process incoming email responses to ipr mail")
12-
option_list = BaseCommand.option_list + (
13-
make_option('--email-file', dest='email', help='File containing email (default: stdin)'),)
11+
12+
def add_arguments(self, parser):
13+
parser.add_argument('--email-file', dest='email', help='File containing email (default: stdin)')
1414

1515
def handle(self, *args, **options):
1616
email = options.get('email', None)

ietf/liaisons/management/commands/remind_update_sdo_list.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from optparse import make_option
21

32
from django.core.management.base import BaseCommand
43

@@ -8,10 +7,10 @@
87

98
class Command(BaseCommand):
109
help = (u"Send a remind to each SDO Liaison Manager to update the list of persons authorized to send liaison statements on behalf of his SDO")
11-
option_list = BaseCommand.option_list + (
12-
make_option('-s', '--sdo-pk', dest='sdo_pk',
13-
help='Send the reminder to the SDO with this primary key. If not provided reminder will be sent to all SDOs'),
14-
)
10+
11+
def add_arguments(self, parser):
12+
parser.add_argument('-s', '--sdo-pk', dest='sdo_pk',
13+
help='Send the reminder to the SDO with this primary key. If not provided reminder will be sent to all SDOs')
1514

1615
def handle(self, *args, **options):
1716
sdo_pk = options.get('sdo_pk', None)

ietf/meeting/management/commands/autoplace.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"""
99

1010
from django.core.management.base import BaseCommand
11-
from optparse import make_option
1211
#import cProfile, pstats, io
1312
import sys
1413
from ietf.meeting.models import Schedule, Meeting
@@ -26,33 +25,33 @@ class Command(BaseCommand):
2625
seed = None
2726
recordsteps = False
2827

29-
option_list = BaseCommand.option_list + (
30-
make_option('--profile',
28+
def add_arguments(self, parser):
29+
parser.add_argument('--profile',
3130
action='store_true',
3231
dest='profile',
3332
default=False,
34-
help='Enable verbose mode'),
35-
make_option('--recordsteps',
33+
help='Enable verbose mode')
34+
parser.add_argument('--recordsteps',
3635
action='store_true',
3736
dest='recordsteps',
3837
default=False,
39-
help='Enable recording progress to table'),
40-
make_option('--verbose',
38+
help='Enable recording progress to table')
39+
parser.add_argument('--verbose',
4140
action='count',
4241
dest='verbose',
4342
default=False,
44-
help='Enable verbose mode'),
45-
make_option('--maxstep',
43+
help='Enable verbose mode')
44+
parser.add_argument('--maxstep',
4645
action="store", type="int",
4746
dest='maxstep',
4847
default=20000,
49-
help='Maximum number of steps'),
50-
make_option('--seed',
48+
help='Maximum number of steps')
49+
parser.add_argument('--seed',
5150
action="store", type="int",
5251
dest='seed',
5352
default=None,
54-
help='Seed to use for calculation'),
55-
)
53+
help='Seed to use for calculation')
54+
5655

5756
def handle(self, *labels, **options):
5857
self.verbose = options.get('verbose', 1)

ietf/meeting/management/commands/schedwrite.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from django.core.management.base import BaseCommand, CommandError
22
from django.core import serializers
3-
from optparse import make_option
43

54

65
class Command(BaseCommand):
7-
option_list = BaseCommand.option_list + (
8-
make_option('--format', default='json', dest='format',
9-
help='Specifies the output serialization format for fixtures.'),
10-
make_option('--indent', default=None, dest='indent', type='int',
11-
help='Specifies the indent level to use when pretty-printing output'),
12-
# make_option('--schedulename', action='store', dest='schedulename', default=False,
6+
7+
def add_arguments(self, parser):
8+
parser.add_argument('--format', default='json', dest='format',
9+
help='Specifies the output serialization format for fixtures.')
10+
parser.add_argument('--indent', default=None, dest='indent', type='int',
11+
help='Specifies the indent level to use when pretty-printing output')
12+
# parser.add_argument('--schedulename', action='store', dest='schedulename', default=False,
1313
# help='Tells Django to stop running the test suite after first failed test.')
14-
)
14+
1515
help = 'Saves the scheduled information for a named schedule in JSON format'
1616
args = 'meetingname [owner] schedname'
1717

ietf/nomcom/management/commands/feedback_email.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys
2-
from optparse import make_option
32

43
from django.core.management.base import BaseCommand, CommandError
54

@@ -12,9 +11,10 @@
1211

1312
class Command(BaseCommand):
1413
help = (u"Receive nomcom email, encrypt and save it.")
15-
option_list = BaseCommand.option_list + (
16-
make_option('--nomcom-year', dest='year', help='NomCom year'),
17-
make_option('--email-file', dest='email', help='File containing email (default: stdin)'),)
14+
15+
def add_arguments(self, parser):
16+
parser.add_argument('--nomcom-year', dest='year', help='NomCom year')
17+
parser.add_argument('--email-file', dest='email', help='File containing email (default: stdin)')
1818

1919
def handle(self, *args, **options):
2020
email = options.get('email', None)

ietf/submit/management/commands/manualpost_email.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys
2-
from optparse import make_option
32

43
from django.core.management.base import BaseCommand, CommandError
54

@@ -9,8 +8,9 @@
98

109
class Command(BaseCommand):
1110
help = (u"Process incoming manual post email responses")
12-
option_list = BaseCommand.option_list + (
13-
make_option('--email-file', dest='email', help='File containing email (default: stdin)'),)
11+
12+
def add_arguments(self, parser):
13+
parser.add_argument('--email-file', dest='email', help='File containing email (default: stdin)')
1414

1515
def handle(self, *args, **options):
1616
email = options.get('email', None)

ietf/utils/management/commands/coverage_changes.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import json
55
import codecs
66
import gzip
7-
from optparse import make_option
87

98
from django.conf import settings
109
from django.core.management.base import BaseCommand, CommandError
@@ -30,18 +29,25 @@ class Command(BaseCommand):
3029
"\n"
3130
" List URLs which are not covered:\n"
3231
" $ manage.py {name} --absolute --sections=url | grep False\n"
33-
"\n"
34-
).format(**locals())
32+
"\n".format(**locals())
33+
)
3534
args = "[[master_json] latest_json]"
36-
option_list = BaseCommand.option_list + (
37-
make_option('--sections', default='template,url,code', dest='sections',
38-
help='Specify which kinds of coverage changes to show. Default: %default'),
39-
make_option('--release', dest='release',
35+
36+
def create_parser(self, prog_name, subcommand):
37+
import argparse
38+
parser = super(Command, self).create_parser(prog_name, subcommand)
39+
parser.formatter_class = argparse.RawDescriptionHelpFormatter
40+
return parser
41+
42+
def add_arguments(self, parser):
43+
parser.add_argument('--sections', default='template,url,code', dest='sections',
44+
help='Specify which kinds of coverage changes to show. Default: %(default)s\n')
45+
parser.add_argument('--release', dest='release',
4046
help='Which release to use as baseline. Default is the latest release in '
41-
'the release coverage file.'),
42-
make_option('--absolute', dest='absolute', action='store_true', default=False,
43-
help='Show absolute figures instead of changes from last release.'),
44-
)
47+
'the release coverage file.')
48+
parser.add_argument('--absolute', dest='absolute', action='store_true', default=False,
49+
help='Show absolute figures instead of changes from last release.')
50+
4551

4652
diff_line_format = "%-58s %8s %8s\n"
4753
list_line_format = "%-68s %8s\n"

ietf/utils/management/commands/create_group_wikis.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import copy
55
import syslog
66
import pkg_resources
7-
from optparse import make_option
8-
#from optparse import make_option
97

108
from trac.core import TracError
119
from trac.env import Environment
@@ -30,17 +28,16 @@
3028
class Command(BaseCommand):
3129
help = "Create group wikis for WGs, RGs and Areas which don't have one."
3230

33-
option_list = BaseCommand.option_list + (
34-
make_option('--wiki-dir-pattern', dest='wiki_dir_pattern',
31+
def add_arguments(self, parser):
32+
parser.add_argument('--wiki-dir-pattern', dest='wiki_dir_pattern',
3533
default=settings.TRAC_WIKI_DIR_PATTERN,
36-
help='A pattern with %s placeholder for group wiki path'),
37-
make_option('--svn-dir-pattern', dest='svn_dir_pattern',
34+
help='A pattern with %s placeholder for group wiki path')
35+
parser.add_argument('--svn-dir-pattern', dest='svn_dir_pattern',
3836
default=settings.TRAC_SVN_DIR_PATTERN,
39-
help='A pattern with %s placeholder for group svn path'),
40-
make_option('--group-list', '-g', dest='group_list', help='Limit processing to groups with the given acronyms (a comma-separated list)'),
41-
make_option('--dummy-run', '-n', default=False, action='store_true', dest='dummy_run', help='Make no changes, just show what would be done'),
42-
)
43-
37+
help='A pattern with %s placeholder for group svn path')
38+
parser.add_argument('--group-list', '-g', dest='group_list', help='Limit processing to groups with the given acronyms (a comma-separated list)')
39+
parser.add_argument('--dummy-run', '-n', default=False, action='store_true', dest='dummy_run', help='Make no changes, just show what would be done')
40+
4441
def note(self, msg):
4542
if self.verbosity > 1:
4643
self.stdout.write(msg)

ietf/utils/management/commands/import_htpasswd.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sys
22

3-
from optparse import make_option
43
from textwrap import dedent
54

65
from django.contrib.auth.models import User
@@ -46,11 +45,11 @@ class Command(BaseCommand):
4645

4746
help = dedent(__doc__).strip()
4847

49-
option_list = BaseCommand.option_list + (
50-
make_option('--force',
48+
def add_arguments(self, parser):
49+
parser.add_argument('--force',
5150
action='store_true', dest='overwrite', default=False,
52-
help='Overwrite existing passwords in the auth_user table.'),
53-
)
51+
help='Overwrite existing passwords in the auth_user table.')
52+
5453

5554
args = '[path [path [...]]]'
5655

ietf/utils/management/commands/makefixture.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@
3838
#known issues:
3939
#no support for generic relations
4040
#no support for one-to-one relations
41-
from optparse import make_option
4241
from django.core import serializers
4342
from django.core.management.base import BaseCommand
4443
from django.core.management.base import CommandError
4544
from django.core.management.base import LabelCommand
4645
from django.db.models.fields.related import ForeignKey
4746
from django.db.models.fields.related import ManyToManyField
48-
from django.db.models.loading import get_models
47+
from django.apps import apps
4948

5049
DEBUG = True
5150

@@ -56,16 +55,17 @@ def model_name(m):
5655
class Command(LabelCommand):
5756
help = 'Output the contents of the database as a fixture of the given format.'
5857
args = 'modelname[pk] or modelname[id1:id2] repeated one or more times'
59-
option_list = BaseCommand.option_list + (
60-
make_option('--skip-related', default=True, action='store_false', dest='propagate',
61-
help='Specifies if we shall not add related objects.'),
62-
make_option('--reverse', default=[], action='append', dest='reverse',
63-
help="Reverse relations to follow (e.g. 'Job.task_set')."),
64-
make_option('--format', default='json', dest='format',
65-
help='Specifies the output serialization format for fixtures.'),
66-
make_option('--indent', default=None, dest='indent', type='int',
67-
help='Specifies the indent level to use when pretty-printing output'),
68-
)
58+
59+
def add_arguments(self, parser):
60+
parser.add_argument('--skip-related', default=True, action='store_false', dest='propagate',
61+
help='Specifies if we shall not add related objects.')
62+
parser.add_argument('--reverse', default=[], action='append', dest='reverse',
63+
help="Reverse relations to follow (e.g. 'Job.task_set').")
64+
parser.add_argument('--format', default='json', dest='format',
65+
help='Specifies the output serialization format for fixtures.')
66+
parser.add_argument('--indent', default=None, dest='indent', type=int,
67+
help='Specifies the indent level to use when pretty-printing output')
68+
6969
def handle_reverse(self, **options):
7070
follow_reverse = options.get('reverse', [])
7171
to_reverse = {}
@@ -157,7 +157,7 @@ def handle_models(self, models, **options):
157157
raise CommandError("Unable to serialize database: %s" % e)
158158

159159
def get_models(self):
160-
return [(m, model_name(m)) for m in get_models()]
160+
return [(m, model_name(m)) for m in apps.get_models()]
161161

162162
def get_model_from_name(self, search):
163163
"""Given a name of a model, return the model object associated with it

0 commit comments

Comments
 (0)