本文整理汇总了Python中ClusterShell.CLI.OptionParser.OptionParser.add_option方法的典型用法代码示例。如果您正苦于以下问题:Python OptionParser.add_option方法的具体用法?Python OptionParser.add_option怎么用?Python OptionParser.add_option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClusterShell.CLI.OptionParser.OptionParser
的用法示例。
在下文中一共展示了OptionParser.add_option方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from ClusterShell.CLI.OptionParser import OptionParser [as 别名]
# 或者: from ClusterShell.CLI.OptionParser.OptionParser import add_option [as 别名]
def main():
"""clush script entry point"""
sys.excepthook = clush_excepthook
# Default values
nodeset_base, nodeset_exclude = NodeSet(), NodeSet()
#
# Argument management
#
usage = "%prog [options] command"
parser = OptionParser(usage)
parser.add_option("--nostdin", action="store_true", dest="nostdin",
help="don't watch for possible input from stdin")
parser.install_nodes_options()
parser.install_display_options(verbose_options=True)
parser.install_filecopy_options()
parser.install_ssh_options()
(options, args) = parser.parse_args()
#
# Load config file and apply overrides
#
config = ClushConfig(options)
# Should we use ANSI colors for nodes?
if config.color == "auto":
color = sys.stdout.isatty() and (options.gatherall or \
sys.stderr.isatty())
else:
color = config.color == "always"
try:
# Create and configure display object.
display = Display(options, config, color)
except ValueError, exc:
parser.error("option mismatch (%s)" % exc)
示例2: main
# 需要导入模块: from ClusterShell.CLI.OptionParser import OptionParser [as 别名]
# 或者: from ClusterShell.CLI.OptionParser.OptionParser import add_option [as 别名]
def main():
"""clush script entry point"""
sys.excepthook = clush_excepthook
#
# Argument management
#
usage = "%prog [options] command"
parser = OptionParser(usage)
parser.add_option("-n", "--nostdin", action="store_true", dest="nostdin",
help="don't watch for possible input from stdin")
parser.install_groupsconf_option()
parser.install_clush_config_options()
parser.install_nodes_options()
parser.install_display_options(verbose_options=True)
parser.install_filecopy_options()
parser.install_connector_options()
(options, args) = parser.parse_args()
set_std_group_resolver_config(options.groupsconf)
#
# Load config file and apply overrides
#
config = ClushConfig(options, options.conf)
# Initialize logging
if config.verbosity >= VERB_DEBUG:
logging.basicConfig(level=logging.DEBUG)
logging.debug("clush: STARTING DEBUG")
else:
logging.basicConfig(level=logging.CRITICAL)
# Should we use ANSI colors for nodes?
if config.color == "auto":
color = sys.stdout.isatty() and (options.gatherall or \
sys.stderr.isatty())
else:
color = config.color == "always"
try:
# Create and configure display object.
display = Display(options, config, color)
except ValueError as exc:
parser.error("option mismatch (%s)" % exc)
if options.groupsource:
# Be sure -a/g -s source work as espected.
std_group_resolver().default_source_name = options.groupsource
# Compute the nodeset and warn for possible use of shell pathname
# expansion (#225)
wnodelist = []
xnodelist = []
if options.nodes:
wnodelist = [NodeSet(nodes) for nodes in options.nodes]
if options.exclude:
xnodelist = [NodeSet(nodes) for nodes in options.exclude]
for (opt, nodelist) in (('w', wnodelist), ('x', xnodelist)):
for nodes in nodelist:
if len(nodes) == 1 and exists(str(nodes)):
display.vprint_err(VERB_STD, "Warning: using '-%s %s' and "
"local path '%s' exists, was it expanded "
"by the shell?" % (opt, nodes, nodes))
# --hostfile support (#235)
for opt_hostfile in options.hostfile:
try:
fnodeset = NodeSet()
with open(opt_hostfile) as hostfile:
for line in hostfile.read().splitlines():
fnodeset.updaten(nodes for nodes in line.split())
display.vprint_err(VERB_DEBUG,
"Using nodeset %s from hostfile %s"
% (fnodeset, opt_hostfile))
wnodelist.append(fnodeset)
except IOError as exc:
# re-raise as OSError to be properly handled
errno, strerror = exc.args
raise OSError(errno, strerror, exc.filename)
# Instantiate target nodeset from command line and hostfile
nodeset_base = NodeSet.fromlist(wnodelist)
# Instantiate filter nodeset (command line only)
nodeset_exclude = NodeSet.fromlist(xnodelist)
# Specified engine prevails over default engine
DEFAULTS.engine = options.engine
# Do we have nodes group?
task = task_self()
task.set_info("debug", config.verbosity >= VERB_DEBUG)
if config.verbosity == VERB_DEBUG:
std_group_resolver().set_verbosity(1)
#.........这里部分代码省略.........
示例3: main
# 需要导入模块: from ClusterShell.CLI.OptionParser import OptionParser [as 别名]
# 或者: from ClusterShell.CLI.OptionParser.OptionParser import add_option [as 别名]
def main(args=sys.argv):
"""clush script entry point"""
sys.excepthook = clush_excepthook
# Default values
nodeset_base, nodeset_exclude = NodeSet(), NodeSet()
#
# Argument management
#
usage = "%prog [options] command"
parser = OptionParser(usage)
parser.add_option("--nostdin", action="store_true", dest="nostdin",
help="don't watch for possible input from stdin")
parser.install_nodes_options()
parser.install_display_options(verbose_options=True)
parser.install_filecopy_options()
parser.install_ssh_options()
(options, args) = parser.parse_args(args[1:])
#
# Load config file and apply overrides
#
config = ClushConfig(options)
# Should we use ANSI colors for nodes?
if config.color == "auto":
color = sys.stdout.isatty() and (options.gatherall or \
sys.stderr.isatty())
else:
color = config.color == "always"
# Create and configure display object.
display = Display(options, config, color)
#
# Compute the nodeset
#
if options.nodes:
nodeset_base = NodeSet.fromlist(options.nodes)
if options.exclude:
nodeset_exclude = NodeSet.fromlist(options.exclude)
if options.groupsource:
# Be sure -a/g -s source work as espected.
STD_GROUP_RESOLVER.default_sourcename = options.groupsource
# FIXME: add public API to enforce engine
Task._std_default['engine'] = options.engine
# Do we have nodes group?
task = task_self()
task.set_info("debug", config.verbosity > 1)
if config.verbosity == VERB_DEBUG:
STD_GROUP_RESOLVER.set_verbosity(1)
if options.nodes_all:
all_nodeset = NodeSet.fromall()
display.vprint(VERB_DEBUG, "Adding nodes from option -a: %s" % \
all_nodeset)
nodeset_base.add(all_nodeset)
if options.group:
grp_nodeset = NodeSet.fromlist(options.group,
resolver=NOGROUP_RESOLVER)
for grp in grp_nodeset:
addingrp = NodeSet("@" + grp)
display.vprint(VERB_DEBUG, \
"Adding nodes from option -g %s: %s" % (grp, addingrp))
nodeset_base.update(addingrp)
if options.exgroup:
grp_nodeset = NodeSet.fromlist(options.exgroup,
resolver=NOGROUP_RESOLVER)
for grp in grp_nodeset:
removingrp = NodeSet("@" + grp)
display.vprint(VERB_DEBUG, \
"Excluding nodes from option -X %s: %s" % (grp, removingrp))
nodeset_exclude.update(removingrp)
# Do we have an exclude list? (-x ...)
nodeset_base.difference_update(nodeset_exclude)
if len(nodeset_base) < 1:
parser.error('No node to run on.')
# Set open files limit.
set_fdlimit(config.fd_max, display)
#
# Task management
#
# check for clush interactive mode
interactive = not len(args) and \
not (options.copy or options.rcopy)
# check for foreground ttys presence (input)
stdin_isafgtty = sys.stdin.isatty() and \
os.tcgetpgrp(sys.stdin.fileno()) == os.getpgrp()
#.........这里部分代码省略.........