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
This commit is contained in:
parent
7b95411f58
commit
6eec4c2648
|
@ -1,5 +1,4 @@
|
|||
import sys
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
|
@ -9,8 +8,9 @@ import debug # pyflakes:ignore
|
|||
|
||||
class Command(BaseCommand):
|
||||
help = (u"Process incoming email responses to ipr mail")
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--email-file', dest='email', help='File containing email (default: stdin)'),)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--email-file', dest='email', help='File containing email (default: stdin)')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
email = options.get('email', None)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
@ -8,10 +7,10 @@ from ietf.liaisons.mails import send_sdo_reminder
|
|||
|
||||
class Command(BaseCommand):
|
||||
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")
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('-s', '--sdo-pk', dest='sdo_pk',
|
||||
help='Send the reminder to the SDO with this primary key. If not provided reminder will be sent to all SDOs'),
|
||||
)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('-s', '--sdo-pk', dest='sdo_pk',
|
||||
help='Send the reminder to the SDO with this primary key. If not provided reminder will be sent to all SDOs')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
sdo_pk = options.get('sdo_pk', None)
|
||||
|
|
|
@ -8,7 +8,6 @@ https://docs.djangoproject.com/en/dev/howto/custom-management-commands/
|
|||
"""
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from optparse import make_option
|
||||
#import cProfile, pstats, io
|
||||
import sys
|
||||
from ietf.meeting.models import Schedule, Meeting
|
||||
|
@ -26,33 +25,33 @@ class Command(BaseCommand):
|
|||
seed = None
|
||||
recordsteps = False
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--profile',
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--profile',
|
||||
action='store_true',
|
||||
dest='profile',
|
||||
default=False,
|
||||
help='Enable verbose mode'),
|
||||
make_option('--recordsteps',
|
||||
help='Enable verbose mode')
|
||||
parser.add_argument('--recordsteps',
|
||||
action='store_true',
|
||||
dest='recordsteps',
|
||||
default=False,
|
||||
help='Enable recording progress to table'),
|
||||
make_option('--verbose',
|
||||
help='Enable recording progress to table')
|
||||
parser.add_argument('--verbose',
|
||||
action='count',
|
||||
dest='verbose',
|
||||
default=False,
|
||||
help='Enable verbose mode'),
|
||||
make_option('--maxstep',
|
||||
help='Enable verbose mode')
|
||||
parser.add_argument('--maxstep',
|
||||
action="store", type="int",
|
||||
dest='maxstep',
|
||||
default=20000,
|
||||
help='Maximum number of steps'),
|
||||
make_option('--seed',
|
||||
help='Maximum number of steps')
|
||||
parser.add_argument('--seed',
|
||||
action="store", type="int",
|
||||
dest='seed',
|
||||
default=None,
|
||||
help='Seed to use for calculation'),
|
||||
)
|
||||
help='Seed to use for calculation')
|
||||
|
||||
|
||||
def handle(self, *labels, **options):
|
||||
self.verbose = options.get('verbose', 1)
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.core import serializers
|
||||
from optparse import make_option
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--format', default='json', dest='format',
|
||||
help='Specifies the output serialization format for fixtures.'),
|
||||
make_option('--indent', default=None, dest='indent', type='int',
|
||||
help='Specifies the indent level to use when pretty-printing output'),
|
||||
# make_option('--schedulename', action='store', dest='schedulename', default=False,
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--format', default='json', dest='format',
|
||||
help='Specifies the output serialization format for fixtures.')
|
||||
parser.add_argument('--indent', default=None, dest='indent', type='int',
|
||||
help='Specifies the indent level to use when pretty-printing output')
|
||||
# parser.add_argument('--schedulename', action='store', dest='schedulename', default=False,
|
||||
# help='Tells Django to stop running the test suite after first failed test.')
|
||||
)
|
||||
|
||||
help = 'Saves the scheduled information for a named schedule in JSON format'
|
||||
args = 'meetingname [owner] schedname'
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import sys
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
|
@ -12,9 +11,10 @@ import debug # pyflakes:ignore
|
|||
|
||||
class Command(BaseCommand):
|
||||
help = (u"Receive nomcom email, encrypt and save it.")
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--nomcom-year', dest='year', help='NomCom year'),
|
||||
make_option('--email-file', dest='email', help='File containing email (default: stdin)'),)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--nomcom-year', dest='year', help='NomCom year')
|
||||
parser.add_argument('--email-file', dest='email', help='File containing email (default: stdin)')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
email = options.get('email', None)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import sys
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
|
@ -9,8 +8,9 @@ import debug # pyflakes:ignore
|
|||
|
||||
class Command(BaseCommand):
|
||||
help = (u"Process incoming manual post email responses")
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--email-file', dest='email', help='File containing email (default: stdin)'),)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--email-file', dest='email', help='File containing email (default: stdin)')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
email = options.get('email', None)
|
||||
|
|
|
@ -4,7 +4,6 @@ import os
|
|||
import json
|
||||
import codecs
|
||||
import gzip
|
||||
from optparse import make_option
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
@ -30,18 +29,25 @@ class Command(BaseCommand):
|
|||
"\n"
|
||||
" List URLs which are not covered:\n"
|
||||
" $ manage.py {name} --absolute --sections=url | grep False\n"
|
||||
"\n"
|
||||
).format(**locals())
|
||||
"\n".format(**locals())
|
||||
)
|
||||
args = "[[master_json] latest_json]"
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--sections', default='template,url,code', dest='sections',
|
||||
help='Specify which kinds of coverage changes to show. Default: %default'),
|
||||
make_option('--release', dest='release',
|
||||
|
||||
def create_parser(self, prog_name, subcommand):
|
||||
import argparse
|
||||
parser = super(Command, self).create_parser(prog_name, subcommand)
|
||||
parser.formatter_class = argparse.RawDescriptionHelpFormatter
|
||||
return parser
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--sections', default='template,url,code', dest='sections',
|
||||
help='Specify which kinds of coverage changes to show. Default: %(default)s\n')
|
||||
parser.add_argument('--release', dest='release',
|
||||
help='Which release to use as baseline. Default is the latest release in '
|
||||
'the release coverage file.'),
|
||||
make_option('--absolute', dest='absolute', action='store_true', default=False,
|
||||
help='Show absolute figures instead of changes from last release.'),
|
||||
)
|
||||
'the release coverage file.')
|
||||
parser.add_argument('--absolute', dest='absolute', action='store_true', default=False,
|
||||
help='Show absolute figures instead of changes from last release.')
|
||||
|
||||
|
||||
diff_line_format = "%-58s %8s %8s\n"
|
||||
list_line_format = "%-68s %8s\n"
|
||||
|
|
|
@ -4,8 +4,6 @@ import os
|
|||
import copy
|
||||
import syslog
|
||||
import pkg_resources
|
||||
from optparse import make_option
|
||||
#from optparse import make_option
|
||||
|
||||
from trac.core import TracError
|
||||
from trac.env import Environment
|
||||
|
@ -30,17 +28,16 @@ syslog.openlog(logtag, syslog.LOG_PID, syslog.LOG_USER)
|
|||
class Command(BaseCommand):
|
||||
help = "Create group wikis for WGs, RGs and Areas which don't have one."
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--wiki-dir-pattern', dest='wiki_dir_pattern',
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--wiki-dir-pattern', dest='wiki_dir_pattern',
|
||||
default=settings.TRAC_WIKI_DIR_PATTERN,
|
||||
help='A pattern with %s placeholder for group wiki path'),
|
||||
make_option('--svn-dir-pattern', dest='svn_dir_pattern',
|
||||
help='A pattern with %s placeholder for group wiki path')
|
||||
parser.add_argument('--svn-dir-pattern', dest='svn_dir_pattern',
|
||||
default=settings.TRAC_SVN_DIR_PATTERN,
|
||||
help='A pattern with %s placeholder for group svn path'),
|
||||
make_option('--group-list', '-g', dest='group_list', help='Limit processing to groups with the given acronyms (a comma-separated list)'),
|
||||
make_option('--dummy-run', '-n', default=False, action='store_true', dest='dummy_run', help='Make no changes, just show what would be done'),
|
||||
)
|
||||
|
||||
help='A pattern with %s placeholder for group svn path')
|
||||
parser.add_argument('--group-list', '-g', dest='group_list', help='Limit processing to groups with the given acronyms (a comma-separated list)')
|
||||
parser.add_argument('--dummy-run', '-n', default=False, action='store_true', dest='dummy_run', help='Make no changes, just show what would be done')
|
||||
|
||||
def note(self, msg):
|
||||
if self.verbosity > 1:
|
||||
self.stdout.write(msg)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import sys
|
||||
|
||||
from optparse import make_option
|
||||
from textwrap import dedent
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
@ -46,11 +45,11 @@ class Command(BaseCommand):
|
|||
|
||||
help = dedent(__doc__).strip()
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--force',
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--force',
|
||||
action='store_true', dest='overwrite', default=False,
|
||||
help='Overwrite existing passwords in the auth_user table.'),
|
||||
)
|
||||
help='Overwrite existing passwords in the auth_user table.')
|
||||
|
||||
|
||||
args = '[path [path [...]]]'
|
||||
|
||||
|
|
|
@ -38,14 +38,13 @@ python manage.py makefixture --format=xml --indent=4 YourModel[3] AnotherModel a
|
|||
#known issues:
|
||||
#no support for generic relations
|
||||
#no support for one-to-one relations
|
||||
from optparse import make_option
|
||||
from django.core import serializers
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.management.base import CommandError
|
||||
from django.core.management.base import LabelCommand
|
||||
from django.db.models.fields.related import ForeignKey
|
||||
from django.db.models.fields.related import ManyToManyField
|
||||
from django.db.models.loading import get_models
|
||||
from django.apps import apps
|
||||
|
||||
DEBUG = True
|
||||
|
||||
|
@ -56,16 +55,17 @@ def model_name(m):
|
|||
class Command(LabelCommand):
|
||||
help = 'Output the contents of the database as a fixture of the given format.'
|
||||
args = 'modelname[pk] or modelname[id1:id2] repeated one or more times'
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--skip-related', default=True, action='store_false', dest='propagate',
|
||||
help='Specifies if we shall not add related objects.'),
|
||||
make_option('--reverse', default=[], action='append', dest='reverse',
|
||||
help="Reverse relations to follow (e.g. 'Job.task_set')."),
|
||||
make_option('--format', default='json', dest='format',
|
||||
help='Specifies the output serialization format for fixtures.'),
|
||||
make_option('--indent', default=None, dest='indent', type='int',
|
||||
help='Specifies the indent level to use when pretty-printing output'),
|
||||
)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--skip-related', default=True, action='store_false', dest='propagate',
|
||||
help='Specifies if we shall not add related objects.')
|
||||
parser.add_argument('--reverse', default=[], action='append', dest='reverse',
|
||||
help="Reverse relations to follow (e.g. 'Job.task_set').")
|
||||
parser.add_argument('--format', default='json', dest='format',
|
||||
help='Specifies the output serialization format for fixtures.')
|
||||
parser.add_argument('--indent', default=None, dest='indent', type=int,
|
||||
help='Specifies the indent level to use when pretty-printing output')
|
||||
|
||||
def handle_reverse(self, **options):
|
||||
follow_reverse = options.get('reverse', [])
|
||||
to_reverse = {}
|
||||
|
@ -157,7 +157,7 @@ class Command(LabelCommand):
|
|||
raise CommandError("Unable to serialize database: %s" % e)
|
||||
|
||||
def get_models(self):
|
||||
return [(m, model_name(m)) for m in get_models()]
|
||||
return [(m, model_name(m)) for m in apps.get_models()]
|
||||
|
||||
def get_model_from_name(self, search):
|
||||
"""Given a name of a model, return the model object associated with it
|
||||
|
|
|
@ -2,7 +2,6 @@ import os
|
|||
import sys
|
||||
import time
|
||||
|
||||
from optparse import make_option
|
||||
from pathlib import Path
|
||||
from StringIO import StringIO
|
||||
from textwrap import dedent
|
||||
|
@ -24,11 +23,11 @@ class Command(BaseCommand):
|
|||
|
||||
help = dedent(__doc__).strip()
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--clean',
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--clean',
|
||||
action='store_true', dest='clean', default=False,
|
||||
help='Remove the current directory content before writing new models.'),
|
||||
)
|
||||
help='Remove the current directory content before writing new models.')
|
||||
|
||||
|
||||
def handle(self, *filenames, **options):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue