コード例 #1
0
ファイル: opt_parser.py プロジェクト: idimitrakopoulos/onomix
commonOptionsGroup.add_option("-S", "--silent", action="store_true", dest="silent", default=False,
                              help="Silent mode (don't send any email notifications)")

commonOptionsGroup.add_option("-i", "--identifier", dest="identifier", help="A unique identifier",
                              metavar="<IDENTIFIER>")

parser.add_option_group(commonOptionsGroup)

# Logging Options
loggingOptionsGroup = OptionGroup(parser, "Logging Options", "(Regulate the logging of the script. Default loglevel: INFO)")
loggingOptionsGroup.add_option("-v", "--verbose",        action="store_const",       const=1, dest="verbose",        help="Verbose mode (loglevel: DEBUG)")
parser.add_option_group(loggingOptionsGroup)


# Parse arguments
(options, args) = parser.parse_args()


# Make sure all mandatory options are provided
for m in mandatory_options:
    if not options.__dict__[m]:
        log.critical("Mandatory option '" + m + "' is missing\n")
        parser.print_help()
        sys.exit()


# Set logging level
if options.verbose == 1:
    log.root.handlers[0].setLevel(logging.DEBUG)
    logging.getLogger(properties.default_logger).handlers[0].setLevel(logging.DEBUG)
コード例 #2
0
ファイル: opt_parser.py プロジェクト: cefn/espedite
parser.add_option_group(mainOptionsGroup)

# # Common Options
# commonOptionsGroup = OptionGroup(parser, "Common Options", "(Common throughout all actions supported by the script)")
# parser.add_option_group(commonOptionsGroup)

# Logging Options
loggingOptionsGroup = OptionGroup(parser, "Logging Options", "(Regulate the logging of the script. Default loglevel: INFO)")
loggingOptionsGroup.add_option("-v", "--verbose",        action="store_const",       const=1, dest="verbose",        help="Verbose mode (loglevel: DEBUG)")
parser.add_option_group(loggingOptionsGroup)


# Parse arguments
(options, args) = parser.parse_args()

# Make sure all mandatory options are provided
for m in mandatory_options:
    if not options.__dict__[m]:
        log.critical("Mandatory option '" + m + "' is missing\n")
        parser.print_help()
        sys.exit()

# Make path absolute in case it was given as . or ../ etc
# options.path = os.path.abspath(options.path)

# Set logging level
if options.verbose == 1:
    log.root.handlers[0].setLevel(logging.DEBUG)
    logging.getLogger(properties.default_logger).handlers[0].setLevel(logging.DEBUG)
コード例 #3
0
ファイル: opt_parser.py プロジェクト: idimitrakopoulos/PyJi
for i in range(len(sys.argv)):
    if (sys.argv[i] == '-a') or (sys.argv[i] == '--action'):
        action = sys.argv[i+1]

if action == None:
    action_usage()
    sys.exit()

# Make sure actions are recognised
found = 0
for va in valid_actions:
    if (action == va) or ((action) and (action).startswith("_")): # this way we allow any custom _XXXX actions
        found=1
        break
if found != 1:
    if (action): log.critical("Unrecognized action '" + action + "'\n")
    action_usage()
    sys.exit()

# Init Optparser
parser = OptionParser(
    version="%prog \n\n version: '" + properties.version + "'\n revision: '" + properties.revision + "'\n build date: '" + properties.build_date + "'")

# Add common options
if (action):
    # The pinnacle of all options :-) (determines what other options will be added to the parser)
    parser.add_option("-a", "--action", dest="action",
                      help="Choose one of the following actions '" + ", ".join(valid_actions) + "' (mandatory)",
                      metavar="<ACTION>")

    # Jira Options