def add_opts(self, optparser):
optlist = [
optparse.make_option("--oc-jstree-no-path",
dest="jstree_no_path",
action="store_true",
help="""Do not include paths to make
page less wide"""),
optparse.make_option("--oc-jstree-strip",
dest="strip_namespace",
action="store_true",
help="""Strip namespace prefixes from
path components"""),
]
g = optparser.add_option_group("OpenConfig JSTree output specific options")
g.add_options(optlist)
python类make_option()的实例源码
def add_opts(self, optparser):
optlist = [
optparse.make_option('--json-schema-debug',
dest='schema_debug',
action="store_true",
help='JSON Schema debug'),
optparse.make_option('--json-schema-path',
dest='schema_path',
help='JSON Schema path'),
optparse.make_option('--json-schema-title',
dest='schema_title',
help='JSON Schema title'),
]
group = optparser.add_option_group("JSON Schema-specific options")
group.add_options(optlist)
def dummy_plugin_content():
"""Dummy pyang content that dumps the contents of a parameter"""
return dedent("""\
import optparse
from pyang import plugin
def pyang_plugin_init():
plugin.register_plugin(FakeFixturePlugin())
class FakeFixturePlugin(plugin.PyangPlugin):
def add_opts(self, optparser):
g = optparser.add_option_group("FakeFixture Plugin Options")
g.add_options([
optparse.make_option(
"--fake-fixture-option", default="Hello World!")
])
def add_output_format(self, fmts):
self.multiple_modules = True
fmts['fake-fixture'] = self
def emit(self, ctx, modules, fd):
fd.write(ctx.opts.fake_fixture_option)""")
def __init__(self):
P4Sync.__init__(self)
self.description = "Creates a new git repository and imports from Perforce into it"
self.usage = "usage: %prog [options] //depot/path[@revRange]"
self.options += [
optparse.make_option("--destination", dest="cloneDestination",
action='store', default=None,
help="where to leave result of the clone"),
optparse.make_option("-/", dest="cloneExclude",
action="append", type="string",
help="exclude depot path"),
optparse.make_option("--bare", dest="cloneBare",
action="store_true", default=False),
]
self.cloneDestination = None
self.needsGit = False
self.cloneBare = False
# This is required for the "append" cloneExclude action
def add_opts(self, optparser):
optlist = [
optparse.make_option("--openconfig",
dest="openconfig",
action="store_true",
help="""Validate the module(s) according to
OpenConfig conventions"""),
optparse.make_option("--oc-only",
dest="openconfig_only",
action="store_true",
help="""Do not include standard lint (RFC 6087)
checking"""),
]
g = optparser.add_option_group("OpenConfig specific options")
g.add_options(optlist)
def add_opts(self, optparser):
optlist = [
optparse.make_option("--meta-only",
dest="meta_only",
action="store_true",
help="""Only produce documentation based on the
module metadata"""),
optparse.make_option("--doc-format",
dest="doc_format",
action="store",
type="string",
default="markdown",
help="""Doc output format: markdown, html"""),
optparse.make_option("--strip-ns",
dest="strip_namespace",
action="store_true",
help="""Strip namespace prefixes from
displayed paths"""),
optparse.make_option("--no-structure",
dest="no_structure",
action="store_true",
help="""Do not generate docs for structure-only nodes (e.g., containers)"""),
optparse.make_option("--doc-title",
dest="doc_title",
action="store",
type="string",
help="""Set the title of the output documentation page"""),
]
g = optparser.add_option_group("docs output specific options")
g.add_options(optlist)
def add_option(self, option, help, dest=None):
"""Options are settings specific to one single plugin; they will passed to process_task() in the options_dict.
"""
# If dest is something, store it, otherwise just use store_true
action="store_true"
if dest is not None:
action="store"
self._options.append(make_option('--{}'.format(option), action=action, help=help, dest=dest))
def add_command(self, command, help, aggressive=False):
"""Commands are actions/scans the plugin implements, with PluginXXX.process_task().
Setting aggressive to True is a warning that the command will open many simultaneous connections to the server
and should therefore not be run concurrently with other `aggressive` commands against a given server.
"""
self._commands.append(make_option('--{}'.format(command), action='store_true', help=help))
self._commands_as_text.append((command, aggressive))
def _make_option(command, help, dest):
# If dest is something, store it, otherwise just use store_true
action="store_true"
if dest is not None:
action="store"
return make_option('--' + command, action=action, help=help, dest=dest)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def get_option(self):
kwargs = dict(self.kwargs)
kwargs['help'] = kwargs['short']
for k in ['short', 'long', 'args']:
kwargs.pop(k, None)
return optparse.make_option(*self.pargs, **kwargs)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def layer_option(option, opt, value, parser):
"""
Callback for `make_option` for the `ogrinspect` `layer_key`
keyword option which may be an integer or a string.
"""
try:
dest = int(value)
except ValueError:
dest = value
setattr(parser.values, option.dest, dest)
def list_option(option, opt, value, parser):
"""
Callback for `make_option` for `ogrinspect` keywords that require
a string list. If the string is 'True'/'true' then the option
value will be a boolean instead.
"""
if value.lower() == 'true':
dest = True
else:
dest = [s for s in value.split(',')]
setattr(parser.values, option.dest, dest)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
def __init__(self):
Command.__init__(self)
self.options = [
optparse.make_option("--local", dest="rollbackLocalBranches", action="store_true")
]
self.description = "A tool to debug the multi-branch import. Don't use :)"
self.rollbackLocalBranches = False
def __init__(self):
Command.__init__(self)
P4UserMap.__init__(self)
self.options = [
optparse.make_option("--origin", dest="origin"),
optparse.make_option("-M", dest="detectRenames", action="store_true"),
# preserve the user, requires relevant p4 permissions
optparse.make_option("--preserve-user", dest="preserveUser", action="store_true"),
optparse.make_option("--export-labels", dest="exportLabels", action="store_true"),
optparse.make_option("--dry-run", "-n", dest="dry_run", action="store_true"),
optparse.make_option("--prepare-p4-only", dest="prepare_p4_only", action="store_true"),
optparse.make_option("--conflict", dest="conflict_behavior",
choices=self.conflict_behavior_choices),
optparse.make_option("--branch", dest="branch"),
]
self.description = "Submit changes from git to the perforce depot."
self.usage += " [name of git branch to submit into perforce depot]"
self.origin = ""
self.detectRenames = False
self.preserveUser = gitConfigBool("git-p4.preserveUser")
self.dry_run = False
self.prepare_p4_only = False
self.conflict_behavior = None
self.isWindows = (platform.system() == "Windows")
self.exportLabels = False
self.p4HasMoveCommand = p4_has_move_command()
self.branch = None
def __init__(self):
Command.__init__(self)
self.options = [
optparse.make_option("--import-labels", dest="importLabels", action="store_true"),
]
self.importLabels = False
self.description = ("Fetches the latest revision from perforce and "
+ "rebases the current work (branch) against it")
def make_options():
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)