Beispiel #1
0
def parse_args(args):
    from optparse import OptionParser

    def terminate(option, opt_str, value, parser):
        # optparser callback for an argument that terminates the options
        # list. Remaining arguments will appear in 'args'.
        setattr(parser.values, option.dest, value)
        parser.largs.extend(parser.rargs[:])
        del parser.rargs[:]

    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option("-c", action="callback", callback=terminate, dest="command",
                      type="string",
                      help="program passed in as string (terminates option list)")
    parser.add_option("-i", action="store_true", default=False, dest="interactive",
                      help="inspect interactively after running script")
    parser.add_option("-m", action="callback", callback=terminate, dest="module",
                      type="string",
                      help="run library module as script (terminates option list)")
    parser.add_option("-u", action="store_true", default=False, dest="unbuffered",
                      help="unbuffered binary stdout and stderr (a tad)")
    parser.add_option("-v", dest = "target_version", default="2.5",
                      help="specify Python version to use, default is 2.5")

    options, args = parser.parse_args(args)
    return options, args
Beispiel #2
0
def process_options(pkg_version, sys_argv, option_list=None):
    """Handle debugger options. Set `option_list' if you are writing
    another main program and want to extend the existing set of debugger
    options.

    The options dicionary from opt_parser is return. sys_argv is
    also updated."""
    usage_str="""%prog [debugger-options]]

    Client connection to an out-of-process trepan3k debugger session"""

    ## serverChoices = ('TCP','FIFO', None) # we use PID for now.

    optparser = OptionParser(usage=usage_str, option_list=option_list,
                             version="%%prog version %s" % pkg_version)

    optparser.add_option("-H", "--host", dest="host", default='127.0.0.1',
                         action="store", type='string', metavar='IP-OR-HOST',
                         help="connect IP or host name.")
    optparser.add_option("-P", "--port", dest="port", default=1027,
                         action="store", type='int', metavar='NUMBER',
                         help="Use TCP port number NUMBER for out-of-process connections.")
    optparser.add_option("--pid", dest="pid", default=0,
                         action="store", type='int', metavar='NUMBER',
                         help="Use PID to get FIFO names for out-of-process connections.")

    optparser.disable_interspersed_args()

    sys.argv = list(sys_argv)
    (opts, sys.argv) = optparser.parse_args()

    return opts, sys.argv
Beispiel #3
0
def parseOptions(args):
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option("--minlevel",
                      type="int", dest="minimumInterestingLevel",
                      default=jsInteresting.JS_OVERALL_MISMATCH,
                      help="minimum js/jsInteresting.py level for lithium to consider the testcase interesting")
    parser.add_option("--timeout",
                      type="int", dest="timeout",
                      default=10,
                      help="timeout in seconds")
    parser.add_option("--flags",
                      dest="flagsSpaceSep",
                      default="",
                      help="space-separated list of one set of flags")
    options, args = parser.parse_args(args)
    if len(args) != 3:
        raise Exception("Wrong number of positional arguments. Need 3 (knownPath, jsengine, infilename).")
    options.knownPath = args[0]
    options.jsengine = args[1]
    options.infilename = args[2]
    options.flags = options.flagsSpaceSep.split(" ") if options.flagsSpaceSep else []
    if not os.path.exists(options.jsengine):
        raise Exception("js shell does not exist: " + options.jsengine)

    # For jsInteresting:
    options.valgrind = False
    options.shellIsDeterministic = True  # We shouldn't be in compareJIT with a non-deterministic build
    options.collector = createCollector.createCollector("jsfunfuzz")

    return options
def main():
    from optparse import OptionParser

    ## set up CLI
    description = __doc__
    parser = OptionParser(description=description)
    parser.disable_interspersed_args()
    parser.add_option("-o", "--outfile", help="Where to write fugure")
    parser.add_option("-f", "--format", choices=['pdf','png'], help="Figure format")
    parser.add_option("-r", "--reads", help="directory to put output and support files into")
    parser.add_option("-b", "--bins", default=50, type="int", help="Number of histogram bins")

    (options, args) = parser.parse_args()

    # configure matplotlib
    backend = options.format
    if backend=='png':
        backend='agg'
    matplotlib.use(backend)
    import matplotlib.pyplot as plt

    # get list of read lengths
    readLengths=[]
    readsFormat = fastaOrFastq(options.reads)
    for record in SeqIO.parse(options.reads, readsFormat):
        readLengths.append(len(record))

    # plot
    plt.hist(readLengths,bins=options.bins)
    plt.savefig(options.outfile,format=options.format)
def parseOptions(args):
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option("--valgrind",
                      action="store_true", dest="valgrind",
                      default=False,
                      help="use valgrind with a reasonable set of options")
    parser.add_option("--submit",
                      action="store_true", dest="submit",
                      default=False,
                      help="submit to fuzzmanager (if interesting)")
    parser.add_option("--minlevel",
                      type="int", dest="minimumInterestingLevel",
                      default=JS_FINE + 1,
                      help="minimum js/jsInteresting.py level for lithium to consider the testcase interesting")
    parser.add_option("--timeout",
                      type="int", dest="timeout",
                      default=120,
                      help="timeout in seconds")
    options, args = parser.parse_args(args)
    if len(args) < 2:
        raise Exception("Not enough positional arguments")
    options.knownPath = args[0]
    options.jsengineWithArgs = args[1:]
    options.collector = createCollector.createCollector("jsfunfuzz")
    if not os.path.exists(options.jsengineWithArgs[0]):
        raise Exception("js shell does not exist: " + options.jsengineWithArgs[0])
    options.shellIsDeterministic = inspectShell.queryBuildConfiguration(options.jsengineWithArgs[0], 'more-deterministic')

    return options
Beispiel #6
0
def parse_options(command, option_list=[], expected_arguments=(),
                  unbounded_args=False):
  """
  Parse the arguments to command using the given option list.

  If unbounded_args is true then there must be at least as many extra arguments
  as specified by extra_arguments (the first argument is always CLUSTER).
  Otherwise there must be exactly the same number of arguments as
  extra_arguments.
  """

  config_file_name = "%s/%s" % (DEFAULT_CONFIG_DIR_NAME, CONFIG_FILENAME)
  usage = """%%prog %s [options] %s

Options may also be specified in a configuration file called
%s located in the user's home directory.
Options specified on the command line take precedence over any in the
configuration file.""" % (command, " ".join(expected_arguments),
                          config_file_name)
  parser = OptionParser(usage=usage, version="%%prog %s" % VERSION,
                        option_list=option_list)
  parser.disable_interspersed_args()
  (options, args) = parser.parse_args(sys.argv[2:])
  if unbounded_args:
    if len(args) < len(expected_arguments):
      parser.error("incorrect number of arguments")
  elif len(args) != len(expected_arguments):
    parser.error("incorrect number of arguments")
  return (vars(options), args)
Beispiel #7
0
def main():
    usage = "usage: %prog [options] [broker-url]"
    epilog = """\
The worker needs Filetracker server configured. If no FILETRACKER_URL is
present in the environment, a sensible default is generated, using the same
host as the Celery broker uses, with default Filetracker port."""
    parser = OptionParser(usage=usage, epilog=epilog)
    parser.disable_interspersed_args()

    app = Celery(loader=Loader)
    cmd = WorkerCommand(app)
    for x in cmd.get_options():
        parser.add_option(x)

    options, args = parser.parse_args()

    if len(args) > 1:
        parser.error("Unexpected arguments: " + " ".join(args[1:]))
    if args:
        broker_url = args[0]
        os.environ["CELERY_BROKER_URL"] = args[0]

    if "FILETRACKER_URL" not in os.environ:
        default_filetracker_host = None
        if "CELERY_BROKER_URL" in os.environ:
            default_filetracker_host = _host_from_url(os.environ["CELERY_BROKER_URL"])
        if not default_filetracker_host:
            default_filetracker_host = "127.0.0.1"
        os.environ["FILETRACKER_URL"] = "http://%s:%d" % (default_filetracker_host, DEFAULT_FILETRACKER_PORT)

    return cmd.run(**vars(options))
Beispiel #8
0
def parseOptions(args):
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option("--minlevel",
                      type="int", dest="minimumInterestingLevel",
                      default=jsInteresting.JS_OVERALL_MISMATCH,
                      help="minimum js/jsInteresting.py level for lithium to consider the testcase interesting")
    parser.add_option("--timeout",
                      type="int", dest="timeout",
                      default=10,
                      help="timeout in seconds")
    parser.add_option("--flags",
                      dest="flagsSpaceSep",
                      default="",
                      help="space-separated list of one set of flags")
    options, args = parser.parse_args(args)
    if len(args) != 3:
        raise Exception("Wrong number of positional arguments. Need 3 (knownPath, jsengine, infilename).")
    options.knownPath = args[0]
    options.jsengine = args[1]
    options.infilename = args[2]
    options.flags = options.flagsSpaceSep.split(" ") if options.flagsSpaceSep else []
    if not os.path.exists(options.jsengine):
        raise Exception("js shell does not exist: " + options.jsengine)
    return options
Beispiel #9
0
def parseOptions(args):
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option(
        "--valgrind",
        action="store_true",
        dest="valgrind",
        default=False,
        help="use valgrind with a reasonable set of options",
    )
    parser.add_option(
        "--minlevel",
        type="int",
        dest="minimumInterestingLevel",
        default=JS_FINE + 1,
        help="minimum js/jsInteresting.py level for lithium to consider the testcase interesting",
    )
    parser.add_option("--timeout", type="int", dest="timeout", default=120, help="timeout in seconds")
    options, args = parser.parse_args(args)
    if len(args) < 2:
        raise Exception("Not enough positional arguments")
    options.knownPath = args[0]
    options.jsengineWithArgs = args[1:]
    if not os.path.exists(options.jsengineWithArgs[0]):
        raise Exception("js shell does not exist: " + options.jsengineWithArgs[0])
    return options
def parseOpts():
  usage = 'Usage: %prog [options] <testLog> <path to gcno.tar.bz2>'
  parser = OptionParser(usage)
  # See http://docs.python.org/library/optparse.html#optparse.OptionParser.disable_interspersed_args
  parser.disable_interspersed_args()

  # Define the output base directory.
  parser.add_option('-o', '--output-dir',
                    dest='outputDir',
                    default="/tmp/gcda-unpacked",
                    help='Output directory for info and log files.')

  parser.add_option('-d', '--debug',
                    dest='debug',
                    action='store_true',
                    default=False,
                    help='Debugging mode, be more verbose and don\'t delete temporary files.')

  parser.add_option('-c', '--ccov',
                    dest='ccovPath',
                    default='/src/mozilla-tools/mozilla-coverage/ccov.py',
                    help='Path to CCOV script.')

  parser.add_option('-g', '--gcov-version',
                    dest='gcovVersion',
                    default='4.5',
                    help='GCOV version to specify when calling LCOV.')


  (options, args) = parser.parse_args()

  if len(args) < 2:
      parser.error('Not enough arguments')

  return (options, args)
Beispiel #11
0
def hdf2bag(pargs):
    import roslib #@UnresolvedImport
    roslib.load_manifest('bootstrapping_adapter') #@UnresolvedImport

    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()

    (options, args) = parser.parse_args(pargs) #@UnusedVariable

    if len(args) != 1:
        msg = 'I expect only one filename.'
        raise Exception(msg)

    basedir = args[0]
    global_config_file = os.path.join(basedir, 'robot_info.yaml')
    if not os.path.exists(global_config_file):
        raise Exception('Configuration file %r not found.' %
                         global_config_file)

    global_config = yaml.load(open(global_config_file))
    print global_config.__repr__()
    for hdf_filename in glob(os.path.join(basedir, '*.h5')):
        bag_filename = os.path.splitext(hdf_filename)[0] + '.bag'
        id_episode = os.path.basename(os.path.splitext(hdf_filename)[0])
        pg('hdf2bag_conversion',
           dict(hdf=hdf_filename,
                bag=bag_filename,
                id_robot=global_config['id_robot'],
                id_actuators=global_config['id_actuators'],
                id_sensors=global_config['id_sensors'],
                id_episode=id_episode,
                id_environment=global_config['id_environment'],
                commands_spec=global_config['commands_spec']))
Beispiel #12
0
def main():
    import sys

    from optparse import OptionParser

    parser = OptionParser(usage="usage: %prog [options] SCRIPT-TO-RUN [SCRIPT-ARGUMENTS]")

    parser.add_option("-s", "--steal-output", action="store_true"),
    parser.add_option("--pre-run", metavar="COMMAND", help="Run command before each program run", default="")
    parser.disable_interspersed_args()
    options, args = parser.parse_args()

    if len(args) < 1:
        parser.print_help()
        sys.exit(2)

    mainpyfile = args[0]
    from os.path import exists, dirname

    if not exists(mainpyfile):
        print "Error:", mainpyfile, "does not exist"
        sys.exit(1)

    sys.argv = args

    from pudb import runscript

    runscript(mainpyfile, pre_run=options.pre_run, steal_output=options.steal_output)
Beispiel #13
0
def process_options(debugger_name, pkg_version, sys_argv, option_list=None):
    """Handle debugger options. Set `option_list' if you are writing
    another main program and want to extend the existing set of debugger
    options.

    The options dicionary from opt_parser is return. sys_argv is
    also updated."""
    usage_str="""%prog [debugger-options] [python-script [script-options...]]

       Runs the extended python debugger"""

    # serverChoices = ('TCP','FIFO', None)

    optparser = OptionParser(usage=usage_str, option_list=option_list,
                             version="%%prog version %s" % pkg_version)

    optparser.add_option("-F", "--fntrace", dest="fntrace",
                         action="store_true", default=False,
                         help="Show functions before executing them. " +
                         "This option also sets --batch")
    optparser.add_option("--basename", dest="basename",
                         action="store_true", default=False,
                         help="Filenames strip off basename, "
                         "(e.g. for regression tests)")
    optparser.add_option("--different", dest="different",
                         action="store_true", default=True,
                         help="Consecutive stops should have different "
                         "positions")
    optparser.disable_interspersed_args()

    sys.argv = list(sys_argv)
    (opts, sys.argv) = optparser.parse_args()
    dbg_opts = {}

    return opts, dbg_opts, sys.argv
def create_parser():
    from optparse import OptionParser
    parser = OptionParser(usage=USAGE)
    # We don't want options intended for the Mrs Program to go to Mrs Fulton.
    parser.disable_interspersed_args()

    parser.add_option('-n', dest='nslaves', type='int',
            help='Number of slaves')
    parser.add_option('-N', '--name', dest='name', help='Name of job')
    parser.add_option('-o', '--output', dest='output',
            help='Output (stdout) file')
    parser.add_option('-e', '--stderr', dest='stderr', default='',
            help='Output (stderr) file')
    parser.add_option('-t', '--time', dest='time', type='float',
            help='Wallclock time (in hours)')
    parser.add_option('-m', '--memory', dest='memory', type='int',
            help='Amount of memory per node (in MB)')
    parser.add_option('-s', dest='slaves_per_job', type='int',
            help='Number of slaves in each PBS job', default=0)
    parser.add_option('--interpreter', dest='interpreter', action='store',
            help='Python interpreter to run', default=DEFAULT_INTERPRETER)
    parser.add_option('-f', dest='force', action='store_true',
            help='Force output, even if the output file already exists')
    parser.add_option('--nodespec', dest='nodespec',
            help='Extra node spec options (colon-separated PBS syntax)')
    parser.add_option('-l', '--resource-list', dest='resource_list',
            help='Extra resource requests (comma-separated PBS syntax)')

    parser.set_defaults(n=1, name=QSUB_NAME_DEFAULT)
    return parser
Beispiel #15
0
def main():
    from clang.cindex import Index
    from pprint import pprint

    from optparse import OptionParser, OptionGroup

    # TODO: global opts

    parser = OptionParser("usage: %prog [options] {filename} [clang-args*]")
    parser.disable_interspersed_args()
    (opts, args) = parser.parse_args()

    if len(args) > 0:
        args.append('-c')
        args.append('-ObjC')
        args.append('-m64')
        args.append('-fobjc-arc')

        tu = Index.create().parse(None, args)
        if tu:
            create_go_source(tu.cursor)
        else:
            parser.error("unable to load input")

    else:
        parser.error('invalid number arguments')
Beispiel #16
0
def main():
    from clang.cindex import Index
    from pprint import pprint

    from optparse import OptionParser, OptionGroup

    global opts

    parser = OptionParser("usage: %prog [options] {filename} [clang-args*]")
    parser.add_option("", "--show-ids", dest="showIDs",
                      help="Don't compute cursor IDs (very slow)",
                      default=False)
    parser.add_option("", "--max-depth", dest="maxDepth",
                      help="Limit cursor expansion to depth N",
                      metavar="N", type=int, default=None)
    parser.disable_interspersed_args()
    (opts, args) = parser.parse_args()

    if len(args) == 0:
        parser.error('invalid number arguments')

    index = Index.create()
    tu = index.parse(None, args)
    if not tu:
        parser.error("unable to load input")

    pprint(('diags', map(get_diag_info, tu.diagnostics)))
    pprint(('nodes', get_info(tu.cursor)))
Beispiel #17
0
def main():
    usage = "usage: %prog [options] [broker-url]"
    epilog = """\
The worker needs Filetracker server configured. If no FILETRACKER_URL is
present in the environment, a sensible default is generated, using the same
host as the Celery broker uses, with default Filetracker port."""
    parser = OptionParser(usage=usage, epilog=epilog)
    parser.disable_interspersed_args()

    os.environ.setdefault('CELERY_CONFIG_MODULE', 'sio.celery.default_config')
    app = Celery()
    cmd = WorkerCommand(app)
    for x in cmd.get_options():
        parser.add_option(x)

    options, args = parser.parse_args()

    if len(args) > 1:
        parser.error("Unexpected arguments: " + ' '.join(args[1:]))
    if args:
        broker_url = args[0]
        os.environ['CELERY_BROKER_URL'] = args[0]

    if 'FILETRACKER_URL' not in os.environ:
        default_filetracker_host = None
        if 'CELERY_BROKER_URL' in os.environ:
            default_filetracker_host = \
                    _host_from_url(os.environ['CELERY_BROKER_URL'])
        if not default_filetracker_host:
            default_filetracker_host = '127.0.0.1'
        os.environ['FILETRACKER_URL'] = 'http://%s:%d' \
                % (default_filetracker_host, DEFAULT_FILETRACKER_PORT)

    return cmd.run(**vars(options))
Beispiel #18
0
def main():
    """Build a shell and place it in the autoBisect cache."""

    usage = 'Usage: %prog [options]'
    parser = OptionParser(usage)
    parser.disable_interspersed_args()

    parser.set_defaults(
        buildOptions="",
    )

    # Specify how the shell will be built.
    # See buildOptions.py for details.
    parser.add_option('-b', '--build',
                      dest='buildOptions',
                      help='Specify build options, e.g. -b "--disable-debug --enable-optimize" ' +
                      '(python buildOptions.py --help)')

    parser.add_option('-r', '--rev',
                      dest='revision',
                      help='Specify revision to build')

    options = parser.parse_args()[0]
    options.buildOptions = buildOptions.parseShellOptions(options.buildOptions)

    with LockDir(getLockDirPath(options.buildOptions.repoDir)):
        if options.revision:
            shell = CompiledShell(options.buildOptions, options.revision)
        else:
            localOrigHgHash = hgCmds.getRepoHashAndId(options.buildOptions.repoDir)[0]
            shell = CompiledShell(options.buildOptions, localOrigHgHash)

        obtainShell(shell, updateToRev=options.revision)
        print shell.getShellCacheFullPath()
Beispiel #19
0
    def parse_options(self, command, argv, option_list=[], expected_arguments=[],
                      unbounded_args=False):
        """
        Parse the arguments to command using the given option list.

        If unbounded_args is true then there must be at least as many extra arguments
        as specified by extra_arguments (the first argument is always CLUSTER).
        Otherwise there must be exactly the same number of arguments as
        extra_arguments.
        """

        usage = "%%prog CLUSTER [options] %s" % \
            (" ".join([command] + expected_arguments[:]),)

        parser = OptionParser(usage=usage, version="%%prog %s" % VERSION,
                            option_list=option_list)

        parser.disable_interspersed_args()
        (options, args) = parser.parse_args(argv)
        if unbounded_args:
            if len(args) < len(expected_arguments):
                parser.error("incorrect number of arguments")
        elif len(args) != len(expected_arguments):
            parser.error("incorrect number of arguments")

        return (vars(options), args)
def main(args=sys.argv[1:]):
    """console_script entry point"""

    # set up an option parser
    usage = '%prog [options] [command] ...'
    description = __doc__
    parser = OptionParser(usage=usage, description=description)
    parser.add_option('-s', '--strict', dest='strict',
                      action='store_true', default=False,
                      help='adhere strictly to errors')
    parser.disable_interspersed_args()

    options, args = parser.parse_args(args)

    if not args:
        HelpCLI(parser)(options, args)
        parser.exit()

    # get the command
    command = args[0]
    if command not in commands:
        parser.error("Command must be one of %s (you gave '%s')" % (', '.join(sorted(commands.keys())), command))

    handler = commands[command](parser)
    handler(options, args[1:])
Beispiel #21
0
def parse_options():
    parser = OptionParser()
    parser.add_option('--output-directory')
    parser.add_option('--interfaces-info-file')
    parser.add_option('--write-file-only-if-changed', type='int', default='1')
    parser.add_option('--generate-dart-blink',
                      action='append',
                      type='string',
                      dest='blink_global_entries',
                      nargs=2,
                      help="Pickle file directory and idl file list (dart:blink)")

    parser.add_option('--generate-globals',
                      action='append',
                      type='string',
                      dest='global_entries',
                      nargs=2,
                      help="Pickle file directory and idl file list (global class table)")

    # ensure output comes last, so command line easy to parse via regexes
    parser.disable_interspersed_args()

    options, args = parser.parse_args()
    if options.output_directory is None:
        parser.error('Must specify output directory using --output-directory.')
    options.write_file_only_if_changed = bool(options.write_file_only_if_changed)
    if bool(options.global_entries) or bool(options.blink_global_entries):
        return options, None
    if len(args) != 1:
        parser.error('Must specify exactly 1 input file as argument, but %d given.' % len(args))
    filename = os.path.realpath(args[0])
    return options, filename
Beispiel #22
0
def parse_options():
    parser = OptionParser()
    parser.add_option('--cache-directory',
                      help='cache directory, defaults to output directory')
    parser.add_option('--generate-impl',
                      action="store_true", default=False)
    parser.add_option('--output-directory')
    parser.add_option('--impl-output-directory')
    parser.add_option('--interfaces-info-file')
    parser.add_option('--component-info-file')
    parser.add_option('--write-file-only-if-changed', type='int')
    # FIXME: We should always explicitly specify --target-component and
    # remove the default behavior.
    parser.add_option('--target-component',
                      help='target component to generate code, defaults to '
                      'component of input idl file')
    # ensure output comes last, so command line easy to parse via regexes
    parser.disable_interspersed_args()

    options, args = parser.parse_args()
    if options.output_directory is None:
        parser.error('Must specify output directory using --output-directory.')
    options.write_file_only_if_changed = bool(options.write_file_only_if_changed)
    if len(args) != 1:
        parser.error('Must specify exactly 1 input file as argument, but %d given.' % len(args))
    idl_filename = os.path.realpath(args[0])
    return options, idl_filename
Beispiel #23
0
def main():
    usage = '%prog [options] "<input file>"'
    parser = OptionParser(usage=usage, version=__version__)
    parser.disable_interspersed_args()
    parser.add_option(
        "-o", "--outfile",
        dest="outfile",
        default=None,
        help="Save output to the given file.",
        metavar="<file path>"
    )
    parser.add_option(
        "--bzip2",
        action="store_true",
        dest="bzip2",
        default=False,
        help="bzip2-compress the result into a self-executing python script."
    )
    parser.add_option(
        "--gzip",
        action="store_true",
        dest="gzip",
        default=False,
        help="gzip-compress the result into a self-executing python script."
    )
    options, args = parser.parse_args()
    try:
        source = open(args[0]).read()
    except Exception, e:
        print e
        parser.print_help()
        sys.exit(2)
Beispiel #24
0
def main(args=None):
    usage = dedent("""\
    CLI for Pulp instances providing Docker content

    %prog [options] directive [directive-options]""")
    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()
    parser.add_option('-C', '--cert', default=False,
                      help='specify a certificate file, use with -K')
    parser.add_option('-K', '--key', default=False,
                      help='specify a key file, use with -C')
    parser.add_option('-d', '--debug', default=False, action='store_true')
    parser.add_option('-s', '--server', default='qa',
                      help='a Pulp environment to execute against')
    parser.add_option('-c', '--config-file',
                      default=dockpulp.DEFAULT_CONFIG_FILE,
                      help='config file to use [default: %default]')
    opts, args = parser.parse_args(args)
    cmd = find_directive('do_', args)
    try:
        cmd(opts, args[1:])
    except dockpulp.errors.DockPulpConfigError, pe:
        log.error('Configuration error: %s' % str(pe))
        log.error('')
        log.error('Something is wrong in /etc/dockpulp.conf, /etc/dockpulpdistributors.json,')
        log.error('or /etc/dockpulpdistributions.json')
        log.error('Or you mistyped an option you are passing to --server')
        sys.exit(1)
Beispiel #25
0
class CommandLine(object):

    def run(self, argv):

        self.parser = OptionParser(usage="%prog command [option]", version="%s" % (release.version))

        self.parser.disable_interspersed_args()
        self.parser.print_help = self._help

        options, args = self.parser.parse_args(argv[1:])

        if not args:
            self.parser.error('incorrect number of arguments')

        cmdname = args[0]
        if cmdname not in COMMANDS:
            self.parser.error('unknown command "%s"' % cmdname)


        return COMMANDS[cmdname]().run(args[1:])

    def _help(self):

        print self.parser.format_help()
        print "Commands:"
        longest = max([len(command) for command in COMMANDS])
        format = "  %%-%ds %%s" % max(8, longest + 1)
        commands = COMMANDS.items()
        commands.sort()
        for name, command in commands:
            print format % (name, command.description)
Beispiel #26
0
    def create_parser(self):

        # Generate command line parser
        parser = OptionParser(usage="sfi [options] command [command_options] [command_args]",
                             description="Commands: gid,list,show,remove,add,update,nodes,slices,resources,create,delete,start,stop,reset")
        parser.add_option("-r", "--registry", dest="registry",
                         help="root registry", metavar="URL", default=None)
        parser.add_option("-s", "--slicemgr", dest="sm",
                         help="slice manager", metavar="URL", default=None)
        default_sfi_dir = os.path.expanduser("~/.sfi/")
        parser.add_option("-d", "--dir", dest="sfi_dir",
                         help="config & working directory - default is " + default_sfi_dir,
                         metavar="PATH", default=default_sfi_dir)
        parser.add_option("-u", "--user", dest="user",
                         help="user name", metavar="HRN", default=None)
        parser.add_option("-a", "--auth", dest="auth",
                         help="authority name", metavar="HRN", default=None)
        parser.add_option("-v", "--verbose", action="count", dest="verbose", default=0,
                         help="verbose mode - cumulative")
        parser.add_option("-D", "--debug",
                          action="store_true", dest="debug", default=False,
                          help="Debug (xml-rpc) protocol messages")
        parser.add_option("-p", "--protocol", dest="protocol", default="xmlrpc",
                         help="RPC protocol (xmlrpc or soap)")
        parser.add_option("-k", "--hashrequest",
                         action="store_true", dest="hashrequest", default=False,
                         help="Create a hash of the request that will be authenticated on the server")
        parser.add_option("-t", "--timeout", dest="timeout", default=None,
                         help="Amout of time tom wait before timing out the request")
        parser.disable_interspersed_args()

        return parser
Beispiel #27
0
def main():

    global opts
    global prob_exprs
    global prob_lines
    global g_sym_var_count
    global sym_table
    global call_table

    
    parser = OptionParser("usage: %prog [options] {filename} [clang-args*]")
    parser.add_option("", "--show-ids", dest="showIDs",
                      help="Compute cursor IDs (very slow)",
                      action="store_true", default=False)
    parser.add_option("", "--max-depth", dest="maxDepth",
                      help="Limit cursor expansion to depth N",
                      metavar="N", type=int, default=None)
    parser.disable_interspersed_args()
    (opts, args) = parser.parse_args()

    if len(args) != 2:
        parser.error('invalid number arguments')
    
    src_fl_name = args[0]
    unit_name = args[1]
    
    print analyze(src_fl_name, unit_name)[0]
Beispiel #28
0
def parse():
  usage = """%prog [options] <init-script> [init-options]"""
  parser = OptionParser(usage=usage)
  parser.disable_interspersed_args()
  
  parser.add_option('-i', '--image', help='The image to use when deploying (default: builchimp/indy)')
  parser.add_option('-n', '--name', help='The container name under which to deploy Indy volume container (default: indy)')
  parser.add_option('-N', '--noservice', action='store_true', help='Do not try to restart a systemd service')
  parser.add_option('-r', '--release', action='store_true', help='Treat the metadata as version metadata, not snapshot metadata')
  parser.add_option('-s', '--service', help='The systemd service to manage when redeploying (default: indy-server)')
  parser.add_option('-S', '--unsafe-ssl', action='store_true', help='Disable verification of SSL certificate (DANGEROUS)')
  parser.add_option('-u', '--url', help='URL to maven-metadata.xml to watch for updates')
  parser.add_option('-v', '--verbose', action='store_true', help='Turn on verbose feedback')
  parser.add_option('-V', '--versionfile', help='File to track the last deployed version of Indy')
  
  opts, args = parser.parse_args()
  
  if opts.verbose is True:
    print "Args: '%s'" % " ".join(args)
  init_cmd_template = " ".join(args)
  if not '{url}' in init_cmd_template:
    init_cmd_template += " --url='{url}'"
  
  print "Init command template:\n  %s" % init_cmd_template
  return (opts, init_cmd_template)
Beispiel #29
0
def main(argv):
    op = OptionParser(usage=USAGE, description=DESCRIPTION)
    op.disable_interspersed_args()
    op.add_option(
        "--ccache",
        help="location of ccache (default: %s)" % DEFAULT_CCACHE)
    op.add_option(
        "--compression",
        help="use compression",
        action="store_true")
    op.add_option(
        "-d", "--directory",
        help="where to create the temporary directory with the cache and" \
             " other files (default: %s)" \
            % DEFAULT_DIRECTORY)
    op.add_option(
        "--hardlink",
        help="use hard links",
        action="store_true")
    op.add_option(
        "-n", "--times",
        help="number of times to compile the file (default: %d)" \
            % DEFAULT_TIMES,
        type="int")
    op.add_option(
        "-v", "--verbose",
        help="print progress messages",
        action="store_true")
    op.set_defaults(
        ccache=DEFAULT_CCACHE,
        directory=DEFAULT_DIRECTORY,
        times=DEFAULT_TIMES)
    (options, args) = op.parse_args(argv[1:])
    if len(args) < 2:
        op.error("Missing arguments; pass -h/--help for help")

    global verbose
    verbose = options.verbose

    options.ccache = abspath(options.ccache)

    compiler = find_in_path(args[0])
    if compiler is None:
        op.error("Could not find %s in PATH" % args[0])
    if "ccache" in basename(realpath(compiler)):
        op.error(
            "%s seems to be a symlink to ccache; please specify the path to"
            " the real compiler instead" % compiler)

    print "Compilation command: %s -c -o %s.o" % (
        " ".join(args),
        splitext(argv[-1])[0])
    print "Compression:", on_off(options.compression)
    print "Hardlink:", on_off(options.hardlink)

    tmp_dir = "%s/perfdir.%d" % (abspath(options.directory), getpid())
    recreate_dir(tmp_dir)
    result = test(tmp_dir, options, args[:-1], args[-1])
    rmtree(tmp_dir)
    print_result(result)
Beispiel #30
0
    def __init__(self, command_line_args):
        parser = OptionParser(usage="%prog [options] <back end command> [args]")
        parser.disable_interspersed_args()
        parser.add_option("--sgf-dir", metavar="PATHNAME")
        parser.add_option("--filename-template", metavar="TEMPLATE",
                          help="eg '%03d.sgf'")
        opts, args = parser.parse_args(command_line_args)

        if not args:
            parser.error("must specify a command")
        self.subprocess_command = args

        self.filename_template = "%04d.sgf"
        try:
            opts.filename_template % 3
        except Exception:
            pass
        else:
            self.filename_template = opts.filename_template

        self.sgf_dir = opts.sgf_dir
        if self.sgf_dir:
            self.check_sgf_dir()
            self.do_savesgf = True
        else:
            self.do_savesgf = False
Beispiel #31
0
def main(args):
    parser = OptionParser(usage='%prog [ options ... ] URI [ FILES ]',
                          description='Analyze repository modifications',
                          version=VERSION)
    parser.disable_interspersed_args()
    parser.add_option('-g',
                      '--debug',
                      dest='debug',
                      action="store_true",
                      default=False,
                      help="Run in debug mode")
    parser.add_option('-c',
                      '--config-file',
                      dest='config_file',
                      metavar='FILE',
                      help="Use a custom configuration file")
    parser.add_option('-r',
                      '--revision',
                      dest='revision',
                      metavar='REV',
                      help='Revision to analyze (HEAD)')
    parser.add_option('-f',
                      '--fast',
                      dest='fast',
                      action="store_true",
                      default=False,
                      help="Run faster but moves and copies are not detected")
    parser.add_option('-o',
                      '--output',
                      dest='output',
                      default='text',
                      help='Output type [text|db|xml|csv] (%default)')
    add_outputs_options(parser)

    # Save default values and pass an emtpy Values object to
    # parser_args, so that default values are not set. We need it
    # to know whether a value has been provided by the user or not
    # After parsing the command line we complete the config options
    # with the default values for the options that have not been set
    # by the parser or by a config file
    defaults = parser.get_default_values()
    options, args = parser.parse_args(args, values=Values())

    try:
        config = Config(options.config_file)
    except AttributeError:
        config = Config()

    config.update(options.__dict__)
    config.add(defaults.__dict__)

    if not args:
        parser.error("missing required repository URI")
        return 1

    parser.destroy()

    if config.debug:
        import repositoryhandler.backends
        repositoryhandler.backends.DEBUG = True

    uri = args[0]
    files = args[1:]
    files_from_stdin = (files and files[0] == '-')

    # Create repository
    path = uri_to_filename(uri)
    if path is not None:
        try:
            repo = create_repository_from_path(path)
        except RepositoryUnknownError:
            printerr(
                "Path %s doesn't seem to point to a repository supported by guilty",
                (path, ))
            return 1
        except Exception, e:
            printerr("Unknown error creating repository for path %s (%s)",
                     (path, str(e)))
            return 1
        uri = repo.get_uri_for_path(path)
Beispiel #32
0
def main(config_filenames, exception_handler_class=ExceptionHandler):
    """
    Entry point into the launcher. Any extra necessary values will be pulled
    from the given configuration files.

    @param config_filenames: ordered list of files to load configuration from
    @type  config_filenames: list

    @return: exit code suitable to return to the shell launching the client
    """

    # Command line argument handling
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option(
        '-u',
        '--username',
        dest='username',
        action='store',
        default=None,
        help=
        _('credentials for the Pulp server; if specified will bypass the stored certificate'
          ))
    parser.add_option(
        '-p',
        '--password',
        dest='password',
        action='store',
        default=None,
        help=_(
            'credentials for the Pulp server; must be specified with --username'
        ))
    parser.add_option('--debug',
                      dest='debug',
                      action='store_true',
                      default=False,
                      help=_('enables debug logging'))
    parser.add_option('--config',
                      dest='config',
                      default=None,
                      help=_('absolute path to the configuration file'))
    parser.add_option('--map',
                      dest='print_map',
                      action='store_true',
                      default=False,
                      help=_('prints a map of the CLI sections and commands'))

    options, args = parser.parse_args()

    # Configuration and Logging
    if options.config is not None:
        config_filenames = [options.config]
    config = _load_configuration(config_filenames)
    logger = _initialize_logging(config, debug=options.debug)

    # General UI pieces
    prompt = _create_prompt(config)
    exception_handler = exception_handler_class(prompt, config)

    # REST Bindings
    username = options.username
    password = options.password
    if username and not password:
        prompt_msg = 'Enter password: '******'Login cancelled'))
            sys.exit(os.EX_NOUSER)

    server = _create_bindings(config, logger, username, password)

    # Client context
    context = ClientContext(server, config, logger, prompt, exception_handler)
    cli = PulpCli(context)
    context.cli = cli

    # Load extensions into the UI in the context
    extensions_dir = config['filesystem']['extensions_dir']
    extensions_dir = os.path.expanduser(extensions_dir)

    role = config['client']['role']
    try:
        extensions_loader.load_extensions(extensions_dir, context, role)
    except extensions_loader.LoadFailed, e:
        prompt.write(
            _('The following extensions failed to load: %(f)s' %
              {'f': ', '.join(e.failed_packs)}))
        prompt.write(
            _('More information on the failures can be found in %(l)s' %
              {'l': config['logging']['filename']}))
        return os.EX_OSFILE
Beispiel #33
0
def parseOpts():
    usage = 'Usage: %prog [options]'
    parser = OptionParser(usage)
    # http://docs.python.org/library/optparse.html#optparse.OptionParser.disable_interspersed_args
    parser.disable_interspersed_args()

    parser.set_defaults(
        resetRepoFirst=False,
        startRepo=None,
        endRepo='default',
        testInitialRevs=True,
        output='',
        watchExitCode=None,
        useInterestingnessTests=False,
        parameters=
        '-e 42',  # http://en.wikipedia.org/wiki/The_Hitchhiker%27s_Guide_to_the_Galaxy
        compilationFailedLabel='skip',
        buildOptions="",
        useTreeherderBinaries=False,
        nameOfTreeherderBranch='mozilla-inbound',
    )

    # Specify how the shell will be built.
    # See buildOptions.py for details.
    parser.add_option(
        '-b',
        '--build',
        dest='buildOptions',
        help=
        'Specify js shell build options, e.g. -b "--enable-debug --32" (python buildOptions.py --help)'
    )
    parser.add_option(
        '-B',
        '--browser',
        dest='browserOptions',
        help='Specify browser build options, e.g. -b "-c mozconfig"')

    parser.add_option(
        '--resetToTipFirst',
        dest='resetRepoFirst',
        action='store_true',
        help='First reset to default tip overwriting all local changes. ' +
        'Equivalent to first executing `hg update -C default`. ' +
        'Defaults to "%default".')

    # Specify the revisions between which to bisect.
    parser.add_option(
        '-s',
        '--startRev',
        dest='startRepo',
        help=
        'Earliest changeset/build numeric ID to consider (usually a "good" cset). '
        + 'Defaults to the earliest revision known to work at all/available.')
    parser.add_option(
        '-e',
        '--endRev',
        dest='endRepo',
        help=
        'Latest changeset/build numeric ID to consider (usually a "bad" cset). '
        +
        'Defaults to the head of the main branch, "default", or latest available build.'
    )
    parser.add_option(
        '-k',
        '--skipInitialRevs',
        dest='testInitialRevs',
        action='store_false',
        help=
        'Skip testing the -s and -e revisions and automatically trust them ' +
        'as -g and -b.')

    # Specify the type of failure to look for.
    # (Optional -- by default, internalTestAndLabel will look for exit codes that indicate a crash or assert.)
    parser.add_option(
        '-o',
        '--output',
        dest='output',
        help='Stdout or stderr output to be observed. Defaults to "%default". '
        + 'For assertions, set to "ssertion fail"')
    parser.add_option(
        '-w',
        '--watchExitCode',
        dest='watchExitCode',
        type='int',
        help='Look out for a specific exit code. Only this exit code will be '
        + 'considered "bad".')
    parser.add_option(
        '-i',
        '--useInterestingnessTests',
        dest='useInterestingnessTests',
        action="store_true",
        help="Interpret the final arguments as an interestingness test.")

    # Specify parameters for the js shell.
    parser.add_option(
        '-p',
        '--parameters',
        dest='parameters',
        help=
        'Specify parameters for the js shell, e.g. -p "-a --ion-eager testcase.js".'
    )

    # Specify how to treat revisions that fail to compile.
    # (You might want to add these to kbew.knownBrokenRanges in knownBrokenEarliestWorking.py.)
    parser.add_option(
        '-l',
        '--compilationFailedLabel',
        dest='compilationFailedLabel',
        help='Specify how to treat revisions that fail to compile. ' +
        '(bad, good, or skip) Defaults to "%default"')

    parser.add_option(
        '-T',
        '--useTreeherderBinaries',
        dest='useTreeherderBinaries',
        action="store_true",
        help='Use treeherder binaries for quick bisection, assuming a fast ' +
        'internet connection. Defaults to "%default"')
    parser.add_option(
        '-N',
        '--nameOfTreeherderBranch',
        dest='nameOfTreeherderBranch',
        help='Name of the branch to download. Defaults to "%default"')

    (options, args) = parser.parse_args()
    if options.browserOptions:
        assert not options.buildOptions
        options.browserOptions = buildBrowser.parseOptions(
            options.browserOptions.split())
        options.skipRevs = ' + '.join(
            kbew.knownBrokenRangesBrowser(options.browserOptions))
    else:
        options.buildOptions = buildOptions.parseShellOptions(
            options.buildOptions)
        options.skipRevs = ' + '.join(
            kbew.knownBrokenRanges(options.buildOptions))

    options.paramList = [
        sps.normExpUserPath(x) for x in options.parameters.split(' ') if x
    ]
    # First check that the testcase is present.
    if '-e 42' not in options.parameters and not os.path.isfile(
            options.paramList[-1]):
        print '\nList of parameters to be passed to the shell is: ' + ' '.join(
            options.paramList)
        print
        raise Exception('Testcase at ' + options.paramList[-1] +
                        ' is not present.')

    assert options.compilationFailedLabel in ('bad', 'good', 'skip')

    extraFlags = []

    if options.useInterestingnessTests:
        if len(args) < 1:
            print 'args are: ' + args
            parser.error('Not enough arguments.')
        if not options.browserOptions:
            for a in args:
                if a.startswith("--flags="):
                    extraFlags = a[8:].split(' ')
        options.testAndLabel = externalTestAndLabel(options, args)
    else:
        assert not options.browserOptions  # autoBisect doesn't have a built-in way to run the browser
        if len(args) >= 1:
            parser.error('Too many arguments.')
        options.testAndLabel = internalTestAndLabel(options)

    if options.browserOptions:
        earliestKnownQuery = kbew.earliestKnownWorkingRevForBrowser(
            options.browserOptions)
    else:
        earliestKnownQuery = kbew.earliestKnownWorkingRev(
            options.buildOptions, options.paramList + extraFlags,
            options.skipRevs)

    earliestKnown = ''

    if not options.useTreeherderBinaries:
        earliestKnown = hgCmds.getRepoHashAndId(options.buildOptions.repoDir,
                                                repoRev=earliestKnownQuery)[0]

    if options.startRepo is None:
        if options.useTreeherderBinaries:
            options.startRepo = 'default'
        else:
            options.startRepo = earliestKnown
    # elif not (options.useTreeherderBinaries or hgCmds.isAncestor(options.buildOptions.repoDir, earliestKnown, options.startRepo)):
    #     raise Exception('startRepo is not a descendant of kbew.earliestKnownWorkingRev for this configuration')
    #
    # if not options.useTreeherderBinaries and not hgCmds.isAncestor(options.buildOptions.repoDir, earliestKnown, options.endRepo):
    #     raise Exception('endRepo is not a descendant of kbew.earliestKnownWorkingRev for this configuration')

    if options.parameters == '-e 42':
        print "Note: since no parameters were specified, we're just ensuring the shell does not crash on startup/shutdown."

    if options.nameOfTreeherderBranch != 'mozilla-inbound' and not options.useTreeherderBinaries:
        raise Exception(
            'Setting the name of branches only works for treeherder shell bisection.'
        )

    return options
Beispiel #34
0
def _main(args, default_sender='socket'):
    errs = 0
    main_opts = OptionParser(
        usage="%prog [OPTIONS] COMMAND [COMMAND-OPTIONS] [COMMAND-ARGS]",
        description="""Create events to be consumed by the harness.""")
    main_opts.disable_interspersed_args()
    #If there is no COMMAND specified, stdin is processed line by line.
    main_opts.add_option(
        "-c",
        "--command",
        action="append",
        dest="commands",
        help="Run COMMAND. This option could be specified multiple times.",
        metavar="COMMAND",
        nargs=1,
        type="string")
    main_opts.add_option("-x",
                         "--nostdin",
                         action="store_true",
                         dest="nostdin",
                         help="Do not process stdin if there is no COMMAND",
                         default=False)
    main_opts.add_option("--help-commands",
                         action="callback",
                         nargs=0,
                         callback=help_commands,
                         callback_kwargs={'help': True},
                         help="Print short help on available commands.")
    main_opts.add_option("--list-commands",
                         action="callback",
                         nargs=0,
                         callback=help_commands,
                         help="Print list of available commands.")
    main_opts.add_option("-i",
                         "--print-id",
                         action="store_true",
                         dest="print_id",
                         help="Print event id on stderr.")
    main_opts.add_option("-I",
                         "--print-all-ids",
                         action="store_true",
                         dest="print_all_ids",
                         help="Print all event ids on stderr.")
    main_opts.add_option("-S",
                         "--use-socket",
                         action="store_const",
                         const="socket",
                         dest="sender",
                         help="Use socket for communication with server.")
    main_opts.add_option("--use-stdout",
                         action="store_const",
                         const="stdout",
                         dest="sender",
                         help="""Use stdout for communication with server.
                NOTE: Don't use this unless you know what you are doing.""")
    opts, args = main_opts.parse_args(args)
    the_task = beahlib.get_task(
        make_sender(opts.sender or default_sender, opts))
    if opts.commands:
        for line in opts.commands:
            if not _run(shlex.split(line, True), the_task.send,
                        opts.print_all_ids):
                errs += 1
    if not args:
        if not opts.nostdin:
            # FIXME: process stdin
            pass
    else:
        if not _run(args, the_task.send, opts.print_id or opts.print_all_ids):
            errs += 1
    return errs
Beispiel #35
0
def main():
    global g_opts

    def glob_from_dir(in_root, in_patterns):
        files = []
        for root, dirnames, filenames in os.walk(in_root):
            for pattern in in_patterns:
                for filename in fnmatch.filter(filenames, pattern):
                    files.append(wpath(os.path.join(root, filename)))
        return files

    def path_opt(opt, opt_str, value, parser):
        p = wpath(os.path.abspath(value))
        setattr(parser.values, opt.dest, p)

    def file_opt(opt, opt_str, value, parser):
        p = wpath(os.path.abspath(value))
        l = getattr(parser.values, opt.dest)
        Collect_Parsing_TUs(p, 'x64', 'Release', l)

    def glob_opt(opt, opt_str, value, parser):
        r = getattr(parser.values, 'root')
        l = getattr(parser.values, opt.dest)
        patterns = [p for p in value.split()]
        for f in glob_from_dir(r, patterns):
            l[f] = Parsing_TU(f)

    def tu_opt(opt, opt_str, value, parser):
        l = getattr(parser.values, opt.dest)
        l.extend([p for p in value.split()])

    def clang_opt(opt, opt_str, value, parser):
        print(opt_str, value)
        if opt_str == '-I' or opt_str == '--inc-dir':
            parser.values.clang_args.append(f"-I{wpath(value)}")

    def clang_opt(opt, opt_str, value, parser):
        assert value is None
        args = []
        for arg in parser.rargs:
            if arg[:2] == "--" and len(arg) > 2:
                break
            args.append(arg)
        del parser.rargs[:len(args)]
        l = getattr(parser.values, opt.dest)
        l.extend(args)

    parser = OptionParser("usage: %prog [options] [clang-args*]")

    parser.add_option("-v",
                      "--verbose",
                      dest="verbose",
                      help="Increase verbose level.",
                      action="count",
                      default=0)

    parser.add_option("-i",
                      "--show-diags",
                      dest="show_diags",
                      help="Show diagnostics.",
                      action="store_true",
                      default=False)

    parser.add_option("-w",
                      "--show-warnings",
                      dest="show_warnings",
                      help="Show parsing warnings.",
                      action="store_true",
                      default=False)

    parser.add_option("-s",
                      "--stop-on-diags",
                      dest="stop_on_diags",
                      help="Stop if any diagnotics if found.",
                      action="store_true",
                      default=False)

    parser.add_option("-r",
                      "--root",
                      dest="root",
                      help="Define the source code root directory.",
                      type="string",
                      action="callback",
                      callback=path_opt,
                      default=None)

    parser.add_option("-e",
                      "--ref",
                      dest="ref_file",
                      help="Output the reference nodes to the given file.",
                      type="string",
                      action="callback",
                      callback=path_opt,
                      default=None)

    parser.add_option("-d",
                      "--decl",
                      dest="decl_file",
                      help="Output the declaration nodes to the given file.",
                      type="string",
                      action="callback",
                      callback=path_opt,
                      default=None)

    parser.add_option(
        "-f",
        "--file",
        dest="files",
        help=
        "Source file(s) to parse. This option could be used more than one time.",
        type="string",
        action="callback",
        callback=file_opt,
        default={})

    parser.add_option(
        "-x",
        "--no-file",
        dest="no_files",
        help=
        "Source file(s) to not parse. This option could be used more than one time.",
        type="string",
        action="callback",
        callback=file_opt,
        default={})

    parser.add_option(
        "-g",
        "--glob",
        dest="files",
        help=
        "Recursively glob source file(s) to parse. Example: -g \"*.c\" or -g \"*.c, *.h\". This option could be used more than one time.",
        type="string",
        action="callback",
        callback=glob_opt,
        default={})

    parser.add_option("",
                      "--no-headers",
                      dest="no_headers",
                      help="Do not process c/c++ header files.",
                      action="store_true",
                      default=False)

    parser.add_option("-u",
                      "--unused",
                      dest="unused",
                      help="Search for unused dead code entities.",
                      action="store_true",
                      default=False)

    parser.add_option(
        "",
        "--unused-output",
        dest="unused_file",
        help="Output unused section of code into the given file.",
        type="string",
        action="callback",
        callback=path_opt,
        default=None)

    parser.add_option(
        "",
        "--allow",
        dest="allow_file",
        help=
        "Provide a file containing a white and black lists of code USRs used to seed analyzing processing.",
        type="string",
        action="callback",
        callback=path_opt,
        default=None)

    parser.add_option("-a",
                      "--ast",
                      dest="ast_file",
                      help="Output the AST to the given file.",
                      type="string",
                      action="callback",
                      callback=path_opt,
                      default=None)

    parser.add_option(
        "",
        "--ast-max-depth",
        dest="ast_max_depth",
        help=
        "Maximum depth of the outputed AST. A value <= 0 stands for an unlimited depth.",
        type="int",
        action="store",
        default=0)

    parser.add_option(
        "",
        "--ast-tu",
        dest="ast_tus",
        help=
        "Restrict the AST outout to the given TU file(s). This option could be used more than one time.",
        type="string",
        action="callback",
        callback=tu_opt,
        default=[])

    parser.add_option("",
                      "--full-ast",
                      dest="full_ast",
                      help="Output the full AST w/o any filtering.",
                      action="store_true",
                      default=False)

    parser.add_option("-t",
                      "--trace",
                      dest="trace",
                      help="Trace a USR.",
                      type="string",
                      default=None)

    parser.add_option(
        "-c",
        "--clang",
        dest="clang_args",
        help=
        "Pass arbitrary arguments to clang processing. See https://clang.llvm.org/docs/CommandGuide/clang.html",
        action="callback",
        callback=clang_opt,
        default=[])

    parser.disable_interspersed_args()
    (g_opts, args) = parser.parse_args()

    if args:
        parser.error(f"Unexpected args {args}")

    if not g_opts.root:
        parser.error(
            "Must specified a root folder. Use --help to see options.")

    # filter out excluded source files
    if g_opts.no_files and g_opts.files:
        for f in g_opts.no_files.keys():
            if f in g_opts.files:
                del g_opts.files[f]

    # filter out source files not in specified root folder
    if g_opts.files:
        files = [f for f in g_opts.files.keys()]
        for f in files:
            if not is_path_in_project(f):
                del g_opts.files[f]

    if not g_opts.files:
        parser.error("No source file(s)! Use --help to see options.")

    if g_opts.no_headers:
        input_files = g_opts.files
        g_opts.files = {}
        for f, tu in input_files.items():
            r, ext = os.path.splitext(f)
            if not ext or not ext in default_c_header_extensions:
                g_opts.files[f] = tu

    if g_opts.allow_file:
        init_allow_list(open(g_opts.allow_file, "r").readlines())
    else:
        init_allow_list(default_allow_list)

    clang_args = g_opts.clang_args or default_clang_options

    if g_opts.verbose > 0:
        print(f"root: {g_opts.root}")
        print(f"allow-L-list: {allow_Llist}")
        print(f"allow-D-list: {allow_Dlist}")
        print(f"allow-M-list: {allow_Mlist}")
        print(f"ast-file: {g_opts.ast_file}")
        print(f"ast-max-depth: {g_opts.ast_max_depth}")
        print(f"ast-tus: {g_opts.ast_tus}")
        print(f"ref-file: {g_opts.ref_file}")
        print(f"decl-file: {g_opts.decl_file}")
        print(f"unused-file: {g_opts.unused_file}")
        print(f"clang-args: {clang_args}")
        print(f"input-files ({len(g_opts.files)}):")
        for f in g_opts.files:
            print(f"\t\"{f}\"")

    tus = {}
    top_decls = {}
    orphan_decls = {}
    errors = []
    dois = {}

    start_tm = time.time()

    index = Index.create()

    for f, ftu in g_opts.files.items():
        print(f"@@ Parsing \"{f}\" ...")

        try:
            tu_clang_args = [i for i in clang_args]
            for hdir in ftu.additional_directories:
                tu_clang_args += ['-I', hdir]
            if ftu.precompile_header:
                tu_clang_args += ['-include', ftu.precompile_header]
            if g_opts.verbose > 1:
                print(f"@@ Args {tu_clang_args}")
            tu = index.parse(f, tu_clang_args)
        except TranslationUnitLoadError:
            print(
                f"cindex.TranslationUnitLoadError received while parsing input \"{f}\""
            )
            print("Fatal parsing error. Aborted.")
            exit(1)

        if not tu:
            print(f"Unable to load input \"{f}\"")
            print("Fatal parsing error. Aborted.")
            exit(1)

        # check diags
        # see https://clang.llvm.org/docs/DiagnosticsReference.html
        for d in tu.diagnostics:

            def print_diag_info(diag):
                print(f"{str(diag.format(Diagnostic._FormatOptionsMask))}")

            if d.severity == Diagnostic.Fatal:
                print_diag_info(d)
                print("Fatal parsing error. Aborted.")
                exit(1)

            if g_opts.show_diags:
                if d.severity > Diagnostic.Warning:
                    errors.append(d)
                if d.severity > Diagnostic.Warning or g_opts.show_warnings:
                    print_diag_info(d)

        if len(tu.diagnostics) > 0 and g_opts.stop_on_diags:
            print(f"({len(tu.diagnostics)}) diags found so far... Stopped.")
            exit(1)

        tus[f] = tu
        collect_top_declarations(top_decls, tu.cursor)

    if len(top_decls) == 0:
        print("No top declarations. Exit")
        exit(1)

    if g_opts.verbose > 0:
        print(f"#top-decls: {len(top_decls)}")

    dois_collect(dois, top_decls, orphan_decls)

    if g_opts.verbose > 0:
        print(f"#clang-errors: {len(errors)}")
        print(f"#dois: {len(dois)}")
        print(f"#orphans: {len(orphan_decls)}")

    dois_connect(dois)

    if g_opts.ast_file:
        pp_ast = pprint.PrettyPrinter(indent=4,
                                      width=99,
                                      compact=False,
                                      sort_dicts=False,
                                      stream=open(g_opts.ast_file, "w"))
        for f, tu in tus.items():
            if not g_opts.ast_tus or any(t in node_location_file(tu.cursor)
                                         for t in g_opts.ast_tus):
                pp_ast.pprint(
                    fmt_node_rec(tu.cursor, filtering_off=g_opts.full_ast))

    if g_opts.decl_file:
        with open(g_opts.decl_file, "w") as output:
            for usr, doi in dois.items():
                output.write(
                    f"DOI: doi-usr {usr}: {fmt_oneline_node(doi.node)}: in/out {len(doi.in_refs)}/{len(doi.out_refs)}\n"
                )
            for usr, decls in orphan_decls.items():
                for d in decls:
                    output.write(f"ORPHAN: usr {usr}: {fmt_oneline_node(d)}\n")

    if g_opts.ref_file:
        with open(g_opts.ref_file, "w") as output:
            for usr, doi in dois.items():
                in_ids = [cursor_id(r.node) for r in doi.in_refs]
                out_ids = [cursor_id(r.node) for r in doi.out_refs]
                output.write(
                    f"DOI: doi-usr {usr}: id {cursor_id(doi.node)}: in-refs {sorted(in_ids)}: out-refs {sorted(out_ids)}\n"
                )

    if g_opts.unused or g_opts.unused_file:
        unused_output = open(g_opts.unused_file,
                             "w") if g_opts.unused_file else sys.stdout
        dois_track_unused(dois, unused_output)

    end_tm = time.time()
    print(f"Completed in {round(end_tm-start_tm,1)}s")
Beispiel #36
0
def action_exec(name, args):
    """execute a command against a published root"""

    parser = OptionParser("""\
usage: %%prog %(name)s [options] ... test command args ...

Executes the given command against the latest published build. The syntax for
commands (and exit code) is exactly the same as for the 'bisect' tool, so this
command is useful for testing bisect test commands.

See 'bisect' for more notermation on the exact test syntax.\
""" % locals())

    parser.add_option("-b",
                      "--build",
                      dest="build_name",
                      metavar="STR",
                      help="name of build to fetch",
                      action="store",
                      default=DEFAULT_BUILDER)
    parser.add_option("-s",
                      "--sandbox",
                      dest="sandbox",
                      help="directory to use as a sandbox",
                      action="store",
                      default=None)
    parser.add_option("",
                      "--min-rev",
                      dest="min_rev",
                      help="minimum revision to test",
                      type="int",
                      action="store",
                      default=None)
    parser.add_option("",
                      "--max-rev",
                      dest="max_rev",
                      help="maximum revision to test",
                      type="int",
                      action="store",
                      default=None)
    parser.add_option("",
                      "--near",
                      dest="near_build",
                      help="use a build near NAME",
                      type="str",
                      action="store",
                      metavar="NAME",
                      default=None)

    parser.disable_interspersed_args()

    (opts, args) = parser.parse_args(args)

    if opts.build_name is None:
        parser.error("no build name given (see --build)")

    available_builds = list(llvmlab.fetch_builds(opts.build_name))
    available_builds.sort()
    available_builds.reverse()

    if opts.min_rev is not None:
        available_builds = [
            b for b in available_builds if b.revision >= opts.min_rev
        ]
    if opts.max_rev is not None:
        available_builds = [
            b for b in available_builds if b.revision <= opts.max_rev
        ]

    if len(available_builds) == 0:
        fatal("No builds available for builder name: %s" % opts.build_name)

    # Find the best match, if requested.
    if opts.near_build:
        build = get_best_match(available_builds, opts.near_build)
        if not build:
            parser.error("no match for build %r" % opts.near_build)
    else:
        # Otherwise, take the latest build.
        build = available_builds[0]

    test_result, _ = execute_sandboxed_test(opts.sandbox,
                                            opts.build_name,
                                            build,
                                            args,
                                            verbose=True,
                                            show_command_output=True)

    print '%s: %s' % (
        ('FAIL', 'PASS')[test_result], build.tobasename(include_suffix=False))

    raise SystemExit(test_result != True)
Beispiel #37
0
    def cmdline_main(self):
        op = OptionParser(usage='%prog [options] command [args...] ')
        self.oparser = op

        op.disable_interspersed_args()

        op.add_option('-d',
                      '--debug',
                      dest='debug',
                      default=False,
                      action='store_true',
                      help='turn on debugging output')

        op.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      default=False,
                      action='store_true',
                      help='verbose output')

        op.add_option('-V',
                      '--very-verbose',
                      dest='very_verbose',
                      default=False,
                      action='store_true',
                      help='lots of debug output')

        op.add_option('-s',
                      '--service',
                      dest='service_host',
                      metavar='HOST',
                      default=self.service_host,
                      help='Freebase HTTP service address:port')

        op.add_option('-S',
                      '--sandbox',
                      dest='use_sandbox',
                      default=False,
                      action='store_true',
                      help='shortcut for --service=sandbox-freebase.com')

        op.add_option('-c',
                      '--cookiejar',
                      dest='cookiefile',
                      metavar='FILE',
                      default=self.cookiefile,
                      help='Cookie storage file (will be created if missing)')
        options, args = op.parse_args()

        if len(args) < 1:
            op.error('required subcommand missing')

        loglevel = logging.WARNING
        if options.verbose:
            loglevel = logging.INFO
        if options.very_verbose:
            loglevel = logging.DEBUG

        console.setLevel(loglevel)
        log.setLevel(loglevel)

        if options.use_sandbox:
            self.service_host = 'api.sandbox-freebase.com'
        else:
            self.service_host = options.service_host

        self.cookiefile = options.cookiefile
        #self.progpath = sys.argv[0]

        self.init()

        self.mss.log.setLevel(loglevel)
        self.mss.log.addHandler(console)

        self.import_commands('freebase.fcl.commands')
        self.import_commands('freebase.fcl.mktype')
        self.import_commands('freebase.fcl.schema')

        subcmd = args.pop(0)

        if subcmd in self.commands:
            cmd = self.commands[subcmd]

            if cmd.oparser is not None:
                options, args = cmd.oparser.parse_args(args)
                kws = options.__dict__
            else:
                kws = {}

            self.dispatch(cmd, args, kws)
        else:
            self.oparser.error('unknown subcommand %r, try "%s help"' %
                               (subcmd, self.progpath))

        self.save()
Beispiel #38
0
def _parse_options(arguments):
    ''' Parses sysconfig subcommands'''

    usage = "\t%prog unconfigure [-s] [-g system] " + \
            "[--destructive]" + \
            "\n\t%prog configure [-s] [-g system] " + \
            "[-c config_profile.xml | dir] [--destructive]" + \
            "\n\t%prog create-profile [-g system] " + \
            "[-o output_file] [-l logfile] [-v verbosity] [-b]"

    parser = OptionParser(usage=usage)

    try:
        i = arguments.index(DASH_G)
        try:
            if ' ' in arguments[i + 1]:
                parser.error("groupings must be a comma separated list")
                sys.exit(SU_FATAL_ERR)
        except IndexError:
            # Not necessarily an error if there isn't something at the
            # index value. The user may have passed in configuration with
            # no options, which defaults to system
            pass
    except ValueError:
        # no -g option found
        pass

    # This allows parsing of different subcommand options. It stops
    # parsing after the subcommand is populated.
    parser.disable_interspersed_args()
    (options, sub_cmd) = parser.parse_args(arguments)
    parser.enable_interspersed_args()

    if not sub_cmd:
        parser.error("Subcommand not specified\n"
            "Please select one of the following subcommands: "
            "%s" % SUBCOMMANDS)

    if sub_cmd[0] == CONFIGURE or sub_cmd[0] == UNCONFIGURE:
        # Set up valid options shared by configure and unconfigure subcommands.
        parser.add_option("-g", dest="grouping", action="callback",
                          callback=vararg_callback,
                          help="Grouping to %s" % sub_cmd[0])
        parser.add_option("-s", action="store_true",
                          dest="shutdown", default=False,
                          help="Shuts down the system after the "
                          "unconfiguration")
        parser.add_option("--destructive", dest="destructive",
                          default=False, action="store_true",
                          help="Do not preserve system data for a "
                          "group")

        # configure subcommand additionally supports '-c profile'.
        if sub_cmd[0] == CONFIGURE:
            parser.add_option("-c", dest="profile",
                              help="Custom site profile to use")

        (options, sub_cmd) = parse_unconfig_args(parser, arguments)
    elif sub_cmd[0] == CREATE_PROFILE:
        parser.add_option("-g", dest="grouping",
                          help=_("Grouping to configure"),
                          default=SC_GROUP_SYSTEM)
        parser.add_option("-o", dest="profile", metavar="FILE",
                          help=_("Saves created system configuration profile "
                          "into FILE.\t\t[default: %default]"),
                          default=DEFAULT_SC_LOCATION)
        parser.add_option("-l", "--log-location", dest="logname",
                          help=_("Set log location to FILE "
                          "(default: %default)"),
                          metavar="FILE", default=DEFAULT_LOG_LOCATION)
        parser.add_option("-v", "--log-level", dest="log_level",
                          default=DEFAULT_LOG_LEVEL,
                          help=_("Set log verbosity to LEVEL. In order of "
                          "increasing verbosity, valid values are 'error' "
                          "'warn' 'info' 'debug' or 'input'\n[default:"
                          " %default]"),
                          choices=["error", "warn", "info", "debug", "input"],
                          metavar="LEVEL")
        parser.add_option("-b", "--no-color", action="store_true",
                          dest="force_bw", default=False,
                          help=_("Force the tool to run in "
                          "black and white. This may be useful on some SPARC "
                          "machines with unsupported frame buffers\n"))
        (options, sub_cmd) = parse_create_profile_args(parser, arguments)
    else:
        parser.error("Invalid subcommand \n"
            "Please select one of the following subcommands: "
            "%s" % SUBCOMMANDS)

    return (options, sub_cmd)
Beispiel #39
0
def main():
    optparser = OptionParser(usage=usage_str)
    optparser.add_option(
        "--token",
        dest="api_token",
        default=os.getenv('QDS_API_TOKEN'),
        help=
        "api token for accessing Qubole. must be specified via command line or passed in via environment variable QDS_API_TOKEN"
    )

    optparser.add_option(
        "--url",
        dest="api_url",
        default=os.getenv('QDS_API_URL'),
        help=
        "base url for QDS REST API. defaults to https://api.qubole.com/api ")

    optparser.add_option(
        "--version",
        dest="api_version",
        default=os.getenv('QDS_API_VERSION'),
        help="version of REST API to access. defaults to v1.2")

    optparser.add_option(
        "--poll_interval",
        dest="poll_interval",
        type=int,
        default=os.getenv('QDS_POLL_INTERVAL'),
        help=
        "interval for polling API for completion and other events. defaults to 5s"
    )

    optparser.add_option(
        "--skip_ssl_cert_check",
        dest="skip_ssl_cert_check",
        action="store_true",
        default=False,
        help=
        "skip verification of server SSL certificate. Insecure: use with caution."
    )

    optparser.add_option("-v",
                         dest="verbose",
                         action="store_true",
                         default=False,
                         help="verbose mode - info level logging")

    optparser.add_option("--vv",
                         dest="chatty",
                         action="store_true",
                         default=False,
                         help="very verbose mode - debug level logging")

    optparser.disable_interspersed_args()
    (options, args) = optparser.parse_args()

    if options.chatty:
        logging.basicConfig(level=logging.DEBUG)
    elif options.verbose:
        logging.basicConfig(level=logging.INFO)
    else:
        logging.basicConfig(level=logging.WARN)

    if options.api_token is None:
        sys.stderr.write("No API Token provided\n")
        usage(optparser)

    if options.api_url is None:
        options.api_url = "https://api.qubole.com/api/"

    if options.api_version is None:
        options.api_version = "v1.2"

    if options.poll_interval is None:
        options.poll_interval = 5

    if options.skip_ssl_cert_check is None:
        options.skip_ssl_cert_check = False
    elif options.skip_ssl_cert_check:
        log.warn("Insecure mode enabled: skipping SSL cert verification\n")

    Qubole.configure(api_token=options.api_token,
                     api_url=options.api_url,
                     version=options.api_version,
                     poll_interval=options.poll_interval,
                     skip_ssl_cert_check=options.skip_ssl_cert_check)

    if len(args) < 1:
        sys.stderr.write("Missing first argument containing subcommand\n")
        usage(optparser)

    a0 = args.pop(0)
    if a0 in CommandClasses:
        return cmdmain(a0, args)

    if a0 == "account":
        return accountmain(args)

    if a0 == "cluster":
        api_version_number = float(options.api_version[1:])
        return clustermain(args, api_version_number)

    if a0 == "action":
        return actionmain(args)

    if a0 == "scheduler":
        return schedulermain(args)

    if a0 == "report":
        return reportmain(args)

    if a0 == "dbtap":
        return dbtapmain(args)

    if a0 == "group":
        return groupmain(args)

    if a0 == "role":
        return rolemain(args)

    if a0 == "app":
        return appmain(args)

    if a0 == "nezha":
        return nezhamain(args)

    if a0 == "user":
        return usermain(args)
    if a0 == "template":
        return templatemain(args)

    cmdset = set(CommandClasses.keys())
    sys.stderr.write("First command must be one of <%s>\n" % "|".join(
        cmdset.union([
            "cluster", "action", "scheduler", "report", "dbtap", "role",
            "group", "app", "account", "nezha", "user", "template"
        ])))
    usage(optparser)
Beispiel #40
0
    print("Printing all THROW EXPRessions and the name, location and children")
    for c in root.findall(".//CXX_THROW_EXPR"):
        print(c.attrib['extent.start'])
        # To access definations inside a THROW EXPRESSIONS, use XML parser techniques

    print("\n")

    print("Printing all TRY and the name, location and children")
    for c in root.findall(".//CXX_TRY_STMT"):
        print(c.attrib['extent.start'])
        # To access definations inside a TRY EXPRESSIONS, use XML parser techniques
        # a TRY STMT has CATCH STMT as its children


parser = OptionParser("usage: %prog [options] {filename} [clang-args*]")
parser.disable_interspersed_args()
(opts, args) = parser.parse_args()

index = Index.create()
tu = index.parse(None, args)

if not tu:
    parser.error("unable to load input")

root = Element("STATICROOT")
root = get_info(tu.cursor, root)
root.set('id', str(0))
# print(ET.tostring(root, encoding='utf8').decode('utf8'))
xmlstr = minidom.parseString(ET.tostring(root)).toprettyxml(indent="   ")
with open(str(args[0].split('.')[0]) + "_clang.xml", "w") as f:
    f.write(xmlstr)
Beispiel #41
0
def main():
    """
    Parse command line arguments and execute ssh_connect()
    """
    usage = (
        #'Usage:\n'
        '\t%prog [options] <user> <host> [port]\n'
        '...or...\n'
        '\t%prog [options] <ssh://user@host[:port]>')
    parser = OptionParser(usage=usage, version=__version__)
    parser.disable_interspersed_args()
    try:
        parser.add_option(
            "-c",
            "--command",
            dest="command",
            default='ssh',
            help=_(
                "Path to the ssh command.  Default: 'ssh' (which usually means "
                "/usr/bin/ssh)."),
            metavar="'<filepath>'")
    except TypeError:
        print("ERROR: You're using an older version of Python that has a bug "
              "with the OptionParser module (see "
              "http://bugs.python.org/issue9161).")
        print("To resolve this problem you have two options:\n"
              " * Edit this script (%s) and remove this line (at the top):\n"
              "    from __future__ import unicode_literals\n"
              " * Upgrade your version of Python to the latest." %
              APPLICATION_PATH)
        raw_input(_("[Press Enter to close this terminal]"))
        sys.exit(1)
    parser.add_option(
        "-a",
        "--args",
        dest="additional_args",
        default=None,
        help=_("Any additional arguments that should be passed to the ssh "
               "command.  It is recommended to wrap these in quotes."),
        metavar="'<args>'")
    parser.add_option(
        "-S",
        dest="socket",
        default=None,
        help=_("Path to the control socket for connection sharing (see master "
               "mode and 'man ssh')."),
        metavar="'<filepath>'")
    parser.add_option(
        "--sshfp",
        dest="sshfp",
        default=False,
        action="store_true",
        help=_("Enable the use of SSHFP in verifying host keys. See:  "
               "http://en.wikipedia.org/wiki/SSHFP#SSHFP"))
    parser.add_option(
        "--randomart",
        dest="randomart",
        default=False,
        action="store_true",
        help=_(
            "Enable the VisualHostKey (randomart hash host key) option when "
            "connecting."))
    parser.add_option("--logo",
                      dest="logo",
                      default=False,
                      action="store_true",
                      help=_("Display the logo image inline in the terminal."))
    parser.add_option("--logo_path",
                      dest="logo_path",
                      default=None,
                      help=_("Provide the logo path (implies --logo)."))
    parser.add_option(
        "--default_host",
        dest="default_host",
        default="localhost",
        help=_(
            "The default host that will be used for outbound connections if "
            "no hostname is provided.  Default: localhost"),
        metavar="'<hostname>'")
    parser.add_option(
        "--default_port",
        dest="default_port",
        default='22',
        help=_(
            "The default port that will be used for outbound connections if "
            "no port is provided.  Default: 22"),
        metavar="'<port>'")
    parser.add_option(
        "--auth_only",
        dest="auth_only",
        default=False,
        help=_(
            "Skip asking for host information (hostname and port) and ask for "
            "credentials only (you probably want to use --default_host and "
            "--default_port as well)."))
    parser.add_option("--config",
                      dest="config",
                      default=None,
                      help=_("Provide an ssh config file location"))
    (options, args) = parser.parse_args()
    if options.logo_path:
        options.logo = True
    # NOTE: This also means you can't use these characters in things like
    #       usernames or passwords (if using autoConnectURL).
    try:
        if len(args) == 1:
            parsed = parse_url(args[0])
            if parsed['scheme'] == 'telnet':
                telnet_connect(parsed['user'], parsed['host'], parsed['port'])
            else:
                openssh_connect(parsed['user'],
                                parsed['host'],
                                parsed['port'],
                                command=options.command,
                                password=parsed['password'],
                                sshfp=options.sshfp,
                                randomart=options.randomart,
                                identities=parsed.get('identities', []),
                                additional_args=options.additional_args,
                                socket=options.socket,
                                config=options.config,
                                debug=parsed.get('debug', False))
        elif len(args) == 2:  # No port given, assume 22
            openssh_connect(args[0],
                            args[1],
                            options.default_port,
                            command=options.command,
                            sshfp=options.sshfp,
                            randomart=options.randomart,
                            additional_args=options.additional_args,
                            socket=options.socket,
                            config=options.config)
        elif len(args) == 3:
            openssh_connect(args[0],
                            args[1],
                            args[2],
                            command=options.command,
                            sshfp=options.sshfp,
                            randomart=options.randomart,
                            additional_args=options.additional_args,
                            socket=options.socket,
                            config=options.config)
    except Exception:
        pass  # Something ain't right.  Try the interactive entry method...
    password = None
    try:
        identities = []
        protocol = None
        script_dir = os.path.dirname(os.path.abspath(__file__))
        logo_path = os.path.join(script_dir, 'logo.png')
        logo = None
        # Only show the logo image if running inside Gate One
        if options.logo:
            if options.logo_path:
                if options.logo_path.startswith(os.sep):
                    logo_path = options.logo_path
                else:
                    logo_path = os.path.join(script_dir, options.logo_path)
            if 'GO_TERM' in os.environ.keys() and os.path.exists(logo_path):
                with open(logo_path) as f:
                    logo = f.read()
                    # stdout instead of print so we don't get an extra newline
                    sys.stdout.write(logo)
        url = None
        user = None
        port = None
        validated = False
        debug = False
        invalid_hostname_err = _(
            'Error:  You must enter a valid hostname or IP address.')
        invalid_port_err = _('Error:  You must enter a valid port (1-65535).')
        invalid_user_err = _('Error:  You must enter a valid username.')
        default_host_str = " [%s]" % options.default_host
        default_port_str = "Port [%s]" % options.default_port
        if options.default_host == "":
            default_host_str = ""
        # Set a pre-connection title
        print("\x1b]0;SSH Connect\007")
        if options.auth_only:
            url = options.default_host
        while not validated:
            if not url:
                url = raw_input(
                    _("[Press Shift-F1 for help]\n\nHost/IP or ssh:// URL%s: "
                      % default_host_str))
            if bad_chars(url):
                raw_input(invalid_hostname_err)
                url = None
                continue
            if not url:
                if options.default_host:
                    host = options.default_host
                    protocol = 'ssh'
                    validated = True
                else:
                    raw_input(invalid_hostname_err)
                    continue
            elif url.find('://') >= 0:
                parsed = parse_url(url)
                protocol = parsed['scheme']
                user = parsed['user']
                host = parsed['host']
                port = parsed['port']
                password = parsed['password']
                identities = parsed.get('identities', [])
                debug = parsed.get('debug', False)
            else:
                # Always assume SSH unless given a telnet:// URL
                protocol = 'ssh'
                host = url
            if valid_hostname(host, allow_underscore=True):
                validated = True
            else:
                # Double-check: It might be an IPv6 address
                # IPv6 addresses must be wrapped in brackets:
                if '[' in host and ']' in host:
                    no_brackets = host.strip('[]')
                    if valid_ip(no_brackets):
                        validated = True
                    else:
                        url = None
                        raw_input(invalid_hostname_err)
                else:
                    if valid_ip(host):
                        validated = True
                    else:
                        url = None
                        raw_input(invalid_hostname_err)
        validated = False
        if options.auth_only:
            port = options.default_port
        while not validated:
            if not port:
                port = raw_input(_("%s: " % default_port_str))
                if not port:
                    port = options.default_port
            try:
                port = int(port)
                if port <= 65535 and port > 1:
                    validated = True
                else:
                    port = None
                    raw_input(invalid_port_err)
            except ValueError:
                port = None
                raw_input(invalid_port_err)
        validated = False
        while not validated:
            if not user:
                user = raw_input("User: "******"\x1b]0;ssh://%s@%s\007" % (user, host))
            # Special escape handler (so the rest of the plugin knows the
            # connect string)
            connect_string = "{0}@{1}:{2}".format(user, host, port)
            print(
                "\x1b]_;ssh|set;connect_string;{0}\007".format(connect_string))
            openssh_connect(user,
                            host,
                            port,
                            command=options.command,
                            password=password,
                            sshfp=options.sshfp,
                            randomart=options.randomart,
                            identities=identities,
                            additional_args=options.additional_args,
                            socket=options.socket,
                            config=options.config,
                            debug=debug)
        elif protocol == 'telnet':
            if user:
                print(_('Connecting to telnet://%s@%s:%s' %
                        (user, host, port)))
                # Set title
                print("\x1b]0;telnet://%s@%s\007" % (user, host))
            else:
                print(_('Connecting to telnet://%s:%s' % (host, port)))
                # Set title
                print("\x1b]0;telnet://%s\007" % host)
            telnet_connect(user, host, port)
        else:
            print(_('Unknown protocol "%s"' % protocol))
    except (EOFError):
        sys.exit(1)  # User probably just pressed Ctrl-D
    except Exception as e:  # Catch all
        print(_("Got Exception: %s" % e))
        import traceback
        traceback.print_exc(file=sys.stdout)
        print("Please open up a new issue at https://github.com/liftoff"
              "/GateOne/issues and paste the above information.")
        raw_input(_("[Press any key to close this terminal]"))
        sys.exit(1)
Beispiel #42
0
def action_bisect(name, args):
    """find first failing build using binary search"""

    parser = OptionParser("""\
usage: %%prog %(name)s [options] ... test command args ...

Look for the first published build where a test failed, using the builds on
llvmlab. The command arguments are executed once per build tested, but each
argument is first subject to string interpolation. The syntax is
"%%(VARIABLE)FORMAT" where FORMAT is a standard printf format, and VARIABLE is
one of:

  'sandbox'   - the path to the sandbox directory.
  'path'      - the path to the build under test.
  'revision'  - the revision number of the build.
  'build'     - the build number of the build under test.
  'clang'     - the path to the clang binary of the build if it exists.
  'clang++'   - the path to the clang++ binary of the build if it exists.
  'libltodir' - the path to the directory containing libLTO.dylib, if it
   exists.

Each test is run in a sandbox directory. By default, sandbox directories are
temporary directories which are created and destroyed for each test (see
--sandbox).

For use in auxiliary test scripts, each test is also run with each variable
available in the environment as TEST_<variable name> (variables are converted
to uppercase). For example, a test script could use "TEST_PATH" to find the
path to the build under test.

The stdout and stderr of the command are logged to files inside the sandbox
directory. Use an explicit sandbox directory if you would like to look at
them.

It is possible to run multiple distinct commands for each test by separating
them in the command line arguments by '----'. The failure of any command causes
the entire test to fail.\
""" % locals())

    parser.add_option("-b",
                      "--build",
                      dest="build_name",
                      metavar="STR",
                      help="name of build to fetch",
                      action="store",
                      default=DEFAULT_BUILDER)
    parser.add_option("-s",
                      "--sandbox",
                      dest="sandbox",
                      help="directory to use as a sandbox",
                      action="store",
                      default=None)
    parser.add_option("-v",
                      "--verbose",
                      dest="verbose",
                      help="output more test notermation",
                      action="store_true",
                      default=False)
    parser.add_option("-V",
                      "--very-verbose",
                      dest="very_verbose",
                      help="output even more test notermation",
                      action="store_true",
                      default=False)
    parser.add_option("",
                      "--show-output",
                      dest="show_command_output",
                      help="display command output",
                      action="store_true",
                      default=False)
    parser.add_option("",
                      "--single-step",
                      dest="single_step",
                      help="single step instead of binary stepping",
                      action="store_true",
                      default=False)
    parser.add_option("",
                      "--min-rev",
                      dest="min_rev",
                      help="minimum revision to test",
                      type="int",
                      action="store",
                      default=None)
    parser.add_option("",
                      "--max-rev",
                      dest="max_rev",
                      help="maximum revision to test",
                      type="int",
                      action="store",
                      default=None)

    parser.disable_interspersed_args()

    (opts, args) = parser.parse_args(args)

    if opts.build_name is None:
        parser.error("no build name given (see --build)")

    # Very verbose implies verbose.
    opts.verbose |= opts.very_verbose

    start_time = time.time()
    available_builds = list(llvmlab.fetch_builds(opts.build_name))
    available_builds.sort()
    available_builds.reverse()
    if opts.very_verbose:
        note("fetched builds in %.2fs" % (time.time() - start_time, ))

    if opts.min_rev is not None:
        available_builds = [
            b for b in available_builds if b.revision >= opts.min_rev
        ]
    if opts.max_rev is not None:
        available_builds = [
            b for b in available_builds if b.revision <= opts.max_rev
        ]

    def predicate(item):
        # Run the sandboxed test.
        test_result, _ = execute_sandboxed_test(
            opts.sandbox,
            opts.build_name,
            item,
            args,
            verbose=opts.verbose,
            very_verbose=opts.very_verbose,
            show_command_output=opts.show_command_output or opts.very_verbose)

        # Print status.
        print '%s: %s' % (('FAIL', 'PASS')[test_result],
                          item.tobasename(include_suffix=False))

        return test_result

    if opts.single_step:
        for item in available_builds:
            if predicate(item):
                break
        else:
            item = None
    else:
        if opts.min_rev is None or opts.max_rev is None:
            # Gallop to find initial search range, under the assumption that we
            # are most likely looking for something at the head of this list.
            search_space = algorithm.gallop(predicate, available_builds)
        else:
            # If both min and max revisions are specified,
            # don't gallop - bisect the given range.
            search_space = available_builds
        item = algorithm.bisect(predicate, search_space)

    if item is None:
        fatal('unable to find any passing build!')

    print '%s: first working build' % item.tobasename(include_suffix=False)
    index = available_builds.index(item)
    if index == 0:
        print 'no failing builds!?'
    else:
        print '%s: next failing build' % available_builds[
            index - 1].tobasename(include_suffix=False)
Beispiel #43
0
    def __init__(self):
        sys.excepthook = self.excepthook
        INIPATH = None
        INITITLE = INFO.TITLE
        INIICON = INFO.ICON
        usage = "usage: %prog [options] myfile.ui"
        parser = OptionParser(usage=usage)
        parser.disable_interspersed_args()
        parser.add_options(options)
        # remove [-ini filepath] that linuxcnc adds if being launched as a screen
        # keep a reference of that path
        for i in range(len(sys.argv)):
            if sys.argv[i] =='-ini':
                # delete -ini
                del sys.argv[i]
                # pop out the ini path
                INIPATH = sys.argv.pop(i)
                break
        (opts, args) = parser.parse_args()

        # so web engine can load local images
        sys.argv.append("--disable-web-security")

        # initialize QApp so we can pop up dialogs now.
        self.app = MyApplication(sys.argv)

        # we import here so that the QApp is initialized before
        # the Notify library is loaded because it uses DBusQtMainLoop
        # DBusQtMainLoop must be initialized after to work properly
        from qtvcp import qt_makepins, qt_makegui

        # ToDo: pass specific log levels as an argument, or use an INI setting
        if opts.debug:
            # Log level defaults to INFO, so set lower if in debug mode
            logger.setGlobalLevel(logger.DEBUG)
        if opts.verbose:
            # Log level defaults to INFO, so set lowest if in verbose mode
            logger.setGlobalLevel(logger.VERBOSE)
            LOG.verbose('VERBOSE DEBUGGING ON')

        # a specific path has been set to load from or...
        # no path set but -ini is present: default qtvcp screen...or
        # oops error
        if args:
            basepath=args[0]
        elif INIPATH:
            basepath = "qt_cnc"
        else:
            print(parser.print_help())
            sys.exit(0)
        # set paths using basename
        error = PATH.set_paths(basepath, bool(INIPATH))
        if error:
            sys.exit(0)

        # keep track of python version during this transition
        ver = 'Python 3'

        #################
        # Screen specific
        #################
        if INIPATH:
            LOG.info('green<Building A Linuxcnc Main Screen with {}>'.format(ver))
            import linuxcnc
            # pull info from the INI file
            self.inifile = linuxcnc.ini(INIPATH)
            self.inipath = INIPATH

            # if no handler file specified, use stock test one
            if not opts.usermod:
                LOG.info('No handler file specified on command line')
                target =  os.path.join(PATH.CONFIGPATH, '%s_handler.py' % PATH.BASENAME)
                source =  os.path.join(PATH.SCREENDIR, 'tester/tester_handler.py')
                if PATH.HANDLER is None:
                    message = ("""
Qtvcp encountered an error; No handler file was found.
Would you like to copy a basic handler file into your config folder?
This handler file will allow display of your screen and basic keyboard jogging.

The new handlerfile's path will be:
%s

Pressing cancel will close linuxcnc.""" % target)
                    rtn = QtWidgets.QMessageBox.critical(None, "QTVCP Error", message,QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
                    if rtn == QtWidgets.QMessageBox.Ok:
                        try:
                            shutil.copy(source, target)
                        except IOError as e:
                            LOG.critical("Unable to copy handler file. %s" % e)
                            sys.exit(0)
                        except:
                            LOG.critical("Unexpected error copying handler file:", sys.exc_info())
                            sys.exit(0)
                        opts.usermod = PATH.HANDLER = target
                    else:
                        LOG.critical('No handler file found or specified. User requested stopping')
                else:
                    opts.usermod = PATH.HANDLER

            # specify the HAL component name if missing
            if opts.component is None:
                LOG.info('No HAL component base name specified on command line using: {}'.format(PATH.BASENAME))
                opts.component = PATH.BASENAME

        #################
        # VCP specific
        #################
        else:
            LOG.info('green<Building A VCP Panel with {}>'.format(ver))
            # if no handler file specified, use stock test one
            if not opts.usermod:
                LOG.info('No handler file specified - using {}'.format(PATH.HANDLER))
                opts.usermod = PATH.HANDLER

            # specify the HAL component name if missing
            if opts.component is None:
                LOG.info('No HAL component base name specified - using: {}'.format(PATH.BASENAME))
                opts.component = PATH.BASENAME

        ############################
        # International translation
        ############################
        if PATH.LOCALEDIR is not None:
            translator = QtCore.QTranslator()
            translator.load(PATH.LOCALEDIR)
            self.app.installTranslator(translator)
            #QtCore.QCoreApplication.installTranslator(translator)
            #print(self.app.translate("MainWindow", 'Machine Log'))

        ##############
        # Build ui
        ##############

        #if there was no component name specified use the xml file name
        if opts.component is None:
            opts.component = PATH.BASENAME

        # initialize HAL
        try:
            self.halcomp = hal.component(opts.component)
            self.hal = Qhal(self.halcomp, hal)
        except:
            LOG.critical("Asking for a HAL component using a name that already exists?")
            raise Exception('"Asking for a HAL component using a name that already exists?')

        # initialize the window
        window = qt_makegui.VCPWindow(self.hal, PATH)

        # give reference to user command line options
        if opts.useropts:
            window.USEROPTIONS_ = opts.useropts
        else:
            window.USEROPTIONS_ = None

        # load optional user handler file
        if opts.usermod:
            LOG.debug('Loading the handler file')
            window.load_extension(opts.usermod)
            try:
                window.web_view = QWebView()
            except:
                window.web_view = None
            # do any class patching now
            if "class_patch__" in dir(window.handler_instance):
                window.handler_instance.class_patch__()
            # add filter to catch keyboard events
            LOG.debug('Adding the key events filter')
            myFilter = qt_makegui.MyEventFilter(window)
            self.app.installEventFilter(myFilter)

        # actually build the widgets
        window.instance()

        # title
        if INIPATH:
            if (INITITLE == ""):
                INITITLE='QTvcp-Screen-%s'% opts.component
            title = INITITLE
        else:
            title = 'QTvcp-Panel-%s'% opts.component
        window.setWindowTitle(title)

        # make QT widget HAL pins
        self.panel = qt_makepins.QTPanel(self.hal, PATH, window, opts.debug)

        # call handler file's initialized function
        if opts.usermod:
            if "initialized__" in dir(window.handler_instance):
                LOG.debug('''Calling the handler file's initialized__ function''')
                window.handler_instance.initialized__()
            # add any external handler override user commands
            if INFO.USER_COMMAND_FILE is None:
                INFO.USER_COMMAND_FILE = os.path.join(PATH.CONFIGPATH,'.{}rc'.format(PATH.BASEPATH))
            INFO.USER_COMMAND_FILE = INFO.USER_COMMAND_FILE.replace('CONFIGFOLDER',PATH.CONFIGPATH)
            INFO.USER_COMMAND_FILE = INFO.USER_COMMAND_FILE.replace('WORKINGFOLDER',PATH.WORKINGDIR)

            window.handler_instance.call_user_command_(window.handler_instance, INFO.USER_COMMAND_FILE)

        # All Widgets should be added now - synch them to linuxcnc
        STATUS.forced_update()

        # call a HAL file after widgets built
        if opts.halfile:
            if opts.halfile[-4:] == ".tcl":
                cmd = ["haltcl", opts.halfile]
            else:
                cmd = ["halcmd", "-f", opts.halfile]
            res = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr)
            if res:
                print("'%s' exited with %d" %(' '.join(cmd), res), file=sys.stderr)
                self.shutdown()

        # User components are set up so report that we are ready
        LOG.debug('Set HAL ready')
        self.halcomp.ready()

        # embed us into an X11 window (such as AXIS)
        if opts.parent:
            try:
                from qtvcp.lib import xembed
                window = xembed.reparent_qt_to_x11(window, opts.parent)
                forward = os.environ.get('AXIS_FORWARD_EVENTS_TO', None)
                LOG.critical('Forwarding events to AXIS is not well tested yet')
                if forward:
                    xembed.XEmbedForwarding(window, forward)
            except Exception as e:
                LOG.critical('Embedding error:{}'.format(e))

        # push the window id for embedment into an external program
        if opts.push_XID:
            wid = int(window.winId())
            print(wid, file=sys.stdout)
            sys.stdout.flush()

        # for window resize and or position options
        if "+" in opts.geometry:
            LOG.debug('-g option: moving window')
            try:
                j =  opts.geometry.partition("+")
                pos = j[2].partition("+")
                window.move( int(pos[0]), int(pos[2]) )
            except Exception as e:
                LOG.critical("With -g window position data:\n {}".format(e))
                parser.print_help()
                self.shutdown()
        if "x" in opts.geometry:
            LOG.debug('-g option: resizing')
            try:
                if "+" in opts.geometry:
                    j =  opts.geometry.partition("+")
                    t = j[0].partition("x")
                else:
                    t = opts.geometry.partition("x")
                window.resize( int(t[0]), int(t[2]) )
            except Exception as e:
                LOG.critical("With -g window resize data:\n {}".format(e))
                parser.print_help()
                self.shutdown()

        # always on top
        if opts.always_top:
            window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)

        # theme (styles in QT speak) specify a qss file
        if opts.theme:
            window.apply_styles(opts.theme)
        # apply qss file or default theme
        else:
            window.apply_styles()

        LOG.debug('Show window')
        # maximize
        if opts.maximum:
            window.showMaximized()
        # fullscreen
        elif opts.fullscreen:
            window.showFullScreen()
        else:
            self.panel.set_preference_geometry()

        window.show()
        if INIPATH:
            self.postgui()
            self.postgui_cmd()
            if (INIICON == ""):
                window.setWindowIcon(QtGui.QIcon(os.path.join(PATH.IMAGEDIR, 'linuxcncicon.png')))
            else:
                window.setWindowIcon(QtGui.QIcon(os.path.join(PATH.CONFIGPATH, INIICON)))
        else:
            window.setWindowIcon(QtGui.QIcon(os.path.join(PATH.IMAGEDIR, 'linuxcnc-wizard.gif')))

        # catch control c and terminate signals
        signal.signal(signal.SIGTERM, self.shutdown)
        signal.signal(signal.SIGINT, self.shutdown)

        if opts.usermod and "before_loop__" in dir(window.handler_instance):
            LOG.debug('''Calling the handler file's before_loop__ function''')
            window.handler_instance.before_loop__()

        LOG.info('Preference path: {}'.format(PATH.PREFS_FILENAME))
        # start loop
        self.app.exec_()

        # now shut it all down
        self.shutdown()
Beispiel #44
0
    def __init__(self):
        sys.excepthook = self.excepthook
        INIPATH = None
        usage = "usage: %prog [options] myfile.ui"
        parser = OptionParser(usage=usage)
        parser.disable_interspersed_args()
        parser.add_options(options)
        # remove [-ini filepath] that linuxcnc adds if being launched as a screen
        # keep a reference of that path
        for i in range(len(sys.argv)):
            if sys.argv[i] =='-ini':
                # delete -ini
                del sys.argv[i]
                # pop out the ini path
                INIPATH = sys.argv.pop(i)
                break

        (opts, args) = parser.parse_args()

        # initialize QApp so we can pop up dialogs now. 
        self.app = QtWidgets.QApplication(sys.argv)

        # we import here so that the QApp is initialized before
        # the Notify library is loaded because it uses DBusQtMainLoop
        # DBusQtMainLoop must be initialized after to work properly
        from qtvcp import qt_makepins, qt_makegui

        # ToDo: pass specific log levels as an argument, or use an INI setting
        if not opts.debug:
            # Log level defaults to DEBUG, so set higher if not debug
            logger.setGlobalLevel(logger.INFO)

        # a specific path has been set to load from or...
        # no path set but -ini is present: default qtvcp screen...or
        # oops error
        if args:
            basepath=args[0]
        elif INIPATH:
            basepath = "qt_cnc"
        else:
            PATH.set_paths()

        # set paths using basename
        PATH.set_paths(basepath, bool(INIPATH))

        #################
        # Screen specific
        #################
        if INIPATH:
            LOG.info('green<Building A Linuxcnc Main Screen>')
            import linuxcnc
            # internationalization and localization
            import locale, gettext
            # pull info from the INI file
            self.inifile = linuxcnc.ini(INIPATH)
            self.inipath = INIPATH
            # screens require more path info
            PATH.add_screen_paths()

            # International translation
            locale.setlocale(locale.LC_ALL, '')
            locale.bindtextdomain(PATH.DOMAIN, PATH.LOCALEDIR)
            gettext.install(PATH.DOMAIN, localedir=PATH.LOCALEDIR, unicode=True)
            gettext.bindtextdomain(PATH.DOMAIN, PATH.LOCALEDIR)

            # if no handler file specified, use stock test one
            if not opts.usermod:
                LOG.info('No handler file specified on command line')
                target =  os.path.join(PATH.CONFIGPATH, '%s_handler.py' % PATH.BASENAME)
                source =  os.path.join(PATH.SCREENDIR, 'tester/tester_handler.py')
                if PATH.HANDLER is None:
                    message = ("""
Qtvcp encountered an error; No handler file was found.
Would you like to copy a basic handler file into your config folder?
This handker file will allow display of your screen and basic keyboard jogging.

The new handlerfile's path will be:
%s

Pressing cancel will close linuxcnc.""" % target)
                    rtn = QtWidgets.QMessageBox.critical(None, "QTVCP Error", message,QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
                    if rtn == QtWidgets.QMessageBox.Ok:
                        try:
                            shutil.copy(source, target)
                        except IOError as e:
                            LOG.critical("Unable to copy handler file. %s" % e)
                            sys.exit(0)
                        except:
                            LOG.critical("Unexpected error copying handler file:", sys.exc_info())
                            sys.exit(0)
                        opts.usermod = PATH.HANDLER = target
                    else:
                        LOG.critical('No handler file found or specified. User requested stopping')
                else:
                    opts.usermod = PATH.HANDLER

            # specify the HAL component name if missing
            if opts.component is None:
                LOG.info('No HAL component base name specified on command line using: {}'.format(PATH.BASENAME))
                opts.component = PATH.BASENAME

        #################
        # VCP specific
        #################
        else:
            LOG.info('green<Building A VCP Panel>')
            # if no handler file specified, use stock test one
            if not opts.usermod:
                LOG.info('No handler file specified - using {}'.format(PATH.HANDLER))
                opts.usermod = PATH.HANDLER

            # specify the HAL component name if missing
            if opts.component is None:
                LOG.info('No HAL component base name specified - using: {}'.format(PATH.BASENAME))
                opts.component = PATH.BASENAME

        ##############
        # Build ui
        ##############

        #if there was no component name specified use the xml file name
        if opts.component is None:
            opts.component = PATH.BASENAME

        # initialize HAL
        try:
            self.halcomp = hal.component(opts.component)
            self.hal = QComponent(self.halcomp)
        except:
            LOG.critical("Asking for a HAL component using a name that already exists?")
            sys.exit(0)

        # initialize the window
        window = qt_makegui.VCPWindow(self.hal, PATH)
 
        # load optional user handler file
        if opts.usermod:
            LOG.debug('Loading the handler file')
            window.load_extension(opts.usermod)
            # do any class patching now
            if "class_patch__" in dir(window.handler_instance):
                window.handler_instance.class_patch__()
            # add filter to catch keyboard events
            LOG.debug('Adding the key events filter')
            myFilter = qt_makegui.MyEventFilter(window)
            self.app.installEventFilter(myFilter)

        # actually build the widgets
        window.instance()

        # make QT widget HAL pins
        self.panel = qt_makepins.QTPanel(self.hal, PATH, window, opts.debug)

        # call handler file's initialized function
        if opts.usermod:
            if "initialized__" in dir(window.handler_instance):
                LOG.debug('''Calling the handler file's initialized__ function''')
                window.handler_instance.initialized__()
        # All Widgets should be added now - synch them to linuxcnc
        STATUS.forced_update()

        # User components are set up so report that we are ready
        LOG.debug('Set HAL ready')
        self.halcomp.ready()

        # embed us into an X11 window (such as AXIS)
        if opts.parent:
            window = xembed.reparent_qt_to_x11(window, opts.parent)
            forward = os.environ.get('AXIS_FORWARD_EVENTS_TO', None)
            LOG.critical('Forwarding events to AXIS is not well tested yet')
            if forward:
                xembed.XEmbedFowarding(window, forward)

        # push the window id for embedment into an external program
        if opts.push_XID:
            wid = int(window.winId())
            print >> sys.stdout,wid
            sys.stdout.flush()

        # for window resize and or position options
        if "+" in opts.geometry:
            LOG.debug('-g option: moving window')
            try:
                j =  opts.geometry.partition("+")
                pos = j[2].partition("+")
                window.move( int(pos[0]), int(pos[2]) )
            except:
                LOG.critical("With window position data")
                parser.print_usage()
                sys.exit(1)
        if "x" in opts.geometry:
            LOG.debug('-g option: resizing')
            try:
                if "+" in opts.geometry:
                    j =  opts.geometry.partition("+")
                    t = j[0].partition("x")
                else:
                    t = window_geometry.partition("x")
                window.resize( int(t[0]), int(t[2]) )
            except:
                LOG.critical("With window resize data")
                parser.print_usage()
                sys.exit(1)

        # always on top
        if opts.always_top:
            window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)

        # theme (styles in QT speak) specify a qss file
        if opts.theme:
            window.apply_styles(opts.theme)
        # appy qss file or default theme
        else:
            window.apply_styles()

        # title
        if INIPATH:
            title = 'QTvcp-Screen-%s'% opts.component
        else:
            title = 'QTvcp-Panel-%s'% opts.component
        window.setWindowTitle(title)

        LOG.debug('Show window')
        # maximize
        if opts.maximum:
            window.showMaximized()
        # fullscreen
        elif opts.fullscreen:
            window.showFullScreen()
        else:
            self.panel.set_preference_geometry()
        window.show()
        if INIPATH:
            self.postgui()

        # catch control c and terminate signals
        signal.signal(signal.SIGTERM, self.shutdown)
        signal.signal(signal.SIGINT, self.shutdown)

        if opts.usermod and "before_loop__" in dir(window.handler_instance):
            LOG.debug('''Calling the handler file's before_loop__ function''')
            window.handler_instance.before_loop__()

        LOG.info('Preference path: {}'.format(PATH.PREFS_FILENAME))
        # start loop
        self.app.exec_()

        # now shut it all down
        self.shutdown()
Beispiel #45
0
def main():
    """ creates a HAL component.
        parsees a glade XML file with gtk.builder or libglade
        calls gladevcp.makepins with the specified XML file
        to create pins and register callbacks.
        main window must be called "window1"
    """
    global gladevcp_debug
    (progdir, progname) = os.path.split(sys.argv[0])

    usage = "usage: %prog [options] myfile.ui"
    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()
    parser.add_options(options)

    (opts, args) = parser.parse_args()

    if not args:
        parser.print_help()
        sys.exit(1)

    BASE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), ".."))
    libdir = os.path.join(BASE, "lib", "python")
    sys.path.append(libdir)
    arhmidir = os.path.join(BASE, "lib", "python", "arhmi")
    sys.path.append(arhmidir)

    gladevcp_debug = debug = opts.debug
    xmlname = args[0]

    #if there was no component name specified use the xml file name
    if opts.component is None:
        opts.component = os.path.splitext(os.path.basename(xmlname))[0]

    builder = gtk.Builder()
    # try loading as a gtk.builder project
    try:
        builder.add_from_file(xmlname)
    except:
        #         #try loading as a libglade project
        #         try:
        #             dbg("**** GLADE VCP INFO:    Not a GtkBuilder project, trying to load as a GTK builder project")
        #             builder = gtk.glade.XML(xmlname)
        #             builder = GladeBuilder(builder)
        try:
            # for arhmi applications
            LOCALEDIR = os.path.join(BASE, "share", "locale")
            o = "plasma"
            gettext.install(o, localedir=LOCALEDIR, unicode=True)
            gtk.glade.bindtextdomain(o, LOCALEDIR)
            gtk.glade.textdomain(o)

            base = os.path.abspath(
                os.path.join(os.path.dirname(sys.argv[0]), ".."))
            sharedir = os.path.join(base, "share", "linuxcnc")
            gladefile = os.path.join(sharedir, xmlname)
            builder.add_from_file(gladefile)
        except Exception, e:
            print >> sys.stderr, "**** GLADE VCP ERROR:    With xml file: %s : %s" % (
                xmlname, e)
            sys.exit(0)
Beispiel #46
0
def cli():
    #Command line interface
    usage = """usage: %prog --good=[changeset] --bad=[changeset] [options] \n       %prog --single=[changeset] -e
            """

    parser = OptionParser(usage=usage, version="%prog " + progVersion)
    parser.disable_interspersed_args()

    group1 = OptionGroup(parser, "Global Options", "")
    group1.add_option(
        "-j",
        "--cores",
        dest="cores",
        default=cpuCount(),
        help=
        "Max simultaneous make jobs (default: %default, the number of cores on this system)",
        metavar="[numjobs]")
    group1.add_option("-m",
                      "--mozconfig",
                      dest="mozconf",
                      help="external mozconfig if so desired",
                      metavar="[mozconf path]",
                      default=False)

    group1.add_option("-f",
                      "--freshtrunk",
                      action="store_true",
                      dest="makeClean",
                      default=False,
                      help="Delete old trunk and use a fresh one")

    group1.add_option(
        "-d",
        "--deletetrunk",
        action="store_true",
        dest="deleteTrunk",
        default=False,
        help=
        "Cleanup Flag: deletes the temp directory / trunk generated. Do not use with other flags, this is just for convenient cleanup."
    )


    group2 = OptionGroup(parser, "Bisector Options",
                                        "These are options for bisecting on changesets. Dates are retrieved from pushlog " \
                                        "and are not as reliable as exact changeset numbers.")
    group2.add_option("-g",
                      "--good",
                      dest="good",
                      help="Last known good revision",
                      metavar="[changeset or date]")
    group2.add_option("-b",
                      "--bad",
                      dest="bad",
                      help="Broken commit revision",
                      metavar="[changeset or date]")

    group3 = OptionGroup(parser, "Single Changeset Options",
                         "These are options for building a single changeset")

    group3.add_option("-s",
                      "--single",
                      dest="single",
                      help="Build a single changeset",
                      metavar="[changeset]")

    group3.add_option("-e",
                      "--run",
                      action="store_true",
                      dest="run",
                      default=False,
                      help="run a single changeset")

    group4 = OptionGroup(
        parser, "Binary building options",
        "These are options for building binaries from a single changeset")

    group4.add_option("-x",
                      "--binary",
                      action="store_true",
                      dest="binary",
                      default=False,
                      help="build binary and return path to it")

    group4.add_option(
        "-q",
        "--revision",
        dest="revision",
        default=None,
        metavar="[changeset]",
        help="revision number for single changeset to build binary from")

    group5 = OptionGroup(parser, "Automatic Testing Options",
                                        "Options for using an automated test instead of interactive prompting for bisection. " \
                                        "Please read documentation on how to write testing functions for this script.")

    group5.add_option("-c", "--condition", dest="condition", default=None, metavar="[condtest.py -opt1 -opt2]",
                                        help="External condition for bisecting. " \
                                             "Note: THIS MUST BE THE LAST OPTION CALLED.")

    group6 = OptionGroup(
        parser, "Remote Options",
        "If you don't have a build environment you can push to tryserver to build. Warning: not recommended -- very very slow. Uses a trypusher server (see http://github.com/samliu/moztrypusher). Another option here is to use mozilla's remote build cache to avoid a lot of building. Warning: breaks support for the automated test."
    )
    group6.add_option("-t",
                      "--try",
                      action="store_true",
                      dest="trypusher",
                      help="Build remotely with trypusher",
                      default=False)

    group6.add_option("-n",
                      "--host",
                      dest="tryhost",
                      metavar="[trypusher server hostname]",
                      help="Trypusher host",
                      default="localhost")

    group6.add_option("-p",
                      "--port",
                      dest="tryport",
                      metavar="[trypusher server port]",
                      help="Trypusher Port",
                      default=8080)

    group2.add_option(
        "-r",
        "--remote",
        action="store_true",
        dest="remote",
        help="Use remote build cache to avoid extra builds (NOT YET WORKING)",
        default=False)

    group7 = OptionGroup(
        parser, "Broken and Unstable Options",
        "Caution: use these options at your own risk.  "
        "They aren't recommended.")

    group7.add_option(
        "-R",
        "--repo",
        dest="repoURL",
        help="alternative mercurial repo to bisect NOTE: NEVER BEEN TESTED",
        metavar="valid repository url")

    parser.add_option_group(group1)
    parser.add_option_group(group2)
    parser.add_option_group(group3)
    parser.add_option_group(group4)
    parser.add_option_group(group5)
    parser.add_option_group(group6)
    parser.add_option_group(group7)
    (options, args_for_condition) = parser.parse_args()

    # If a user only wants to make clean or has supplied no options:
    if (not options.good or not options.bad
        ) and not options.single and not options.deleteTrunk:
        if options.makeClean:
            #Make a clean trunk and quit.
            commitBuilder = Builder(clean=options.makeClean)
        else:
            # Not enough relevant parameters were given
            # Print a help message and quit.
            print """Use -h flag for available options."""
            print """To bisect, you must specify both a good and a bad date. (-g and -b flags are not optional)."""
            print """You can also use the --single=[chset] flag to build and --run to run a single changeset."""
        quit()

    # Set up a trunk for either bisection or build.
    mozConfiguration = options.mozconf
    commitBuilder = Builder(clean=options.makeClean,
                            mozconf=mozConfiguration,
                            tryhost=options.tryhost,
                            tryport=options.tryport,
                            remote=options.remote,
                            tryPusher=options.trypusher,
                            deleteTrunk=options.deleteTrunk)

    if options.cores:
        commitBuilder.cores = options.cores
        commitBuilder.mozconfigure()

    # For building single commits:
    if options.single:
        if options.run:
            commitBuilder.buildAndRun(changeset=options.single)
            print "Firefox successfully built and ran!"
        elif options.binary:
            commitBuilder.getBinary(revision=options.single)
        else:
            commitBuilder.build(changeset=options.single)
            print "Local trunk built. Not running."

    # For bisections:
    elif options.good and options.bad:
        print "Begin interactive commit bisect!\n"

        if options.repoURL:
            commitBuilder.repoURL = options.repoURL
            print "Using alternative repository " + options.repoURL

        conditionscript = None
        if options.condition:
            conditionscript = ximport.importRelativeOrAbsolute(
                options.condition)

        if options.remote:
            #Build remotely!
            pass

        commitBuilder.bisect(options.good,
                             options.bad,
                             testcondition=conditionscript,
                             args_for_condition=args_for_condition)

    # Should not get here.
    else:
        print "Invalid input. Please try again."
Beispiel #47
0
multiprocess tasks. Things will break (at least synchronization for sure) if
multiple clients will attempt to read answers from stdin.

"""

import os
import sys
import shlex
from optparse import OptionParser
from beah.core import event
from beah.core.constants import RC, LOG_LEVEL
import beah.misc
import beahlib

no_opts = OptionParser()
no_opts.disable_interspersed_args()


def proc_evt_extend_watchdog(cmd, args):
    """Extend watchdog."""
    no_opts.prog = cmd
    no_opts.usage = "%prog SECONDS"
    no_opts.description = "Extend watchdog."
    opts, args = no_opts.parse_args(args)
    if args:
        timeout = beah.misc.canonical_time(args[0])
    else:
        print >> sys.stderr, "WARNING: SECONDS not specified. Extending for 1 more day."
        timeout = 24 * 3600
    return [event.extend_watchdog(timeout)]
Beispiel #48
0
def make_option_parser():
    from optparse import OptionParser
    parser = OptionParser(
        usage="""%prog [-h|--help] [OPTIONS] [SUBCOMMAND ARGS...]
or %prog help SUBCOMMAND

For a list of available subcommands, use %prog help.

Use %prog without arguments for an interactive session.
Call a subcommand directly for a "single-shot" use.
Call %prog with a level name as argument to start an interactive
session from that level.

See the crm(8) man page or call %prog help for more details.""",
        version="%prog " + config.CRM_VERSION)
    parser.disable_interspersed_args()
    parser.add_option(
        "-f",
        "--file",
        dest="filename",
        metavar="FILE",
        help="Load commands from the given file. If a dash (-) " +
        "is used in place of a file name, crm will read commands " +
        "from the shell standard input (stdin).")
    parser.add_option(
        "-c",
        "--cib",
        dest="cib",
        metavar="CIB",
        help="Start the session using the given shadow CIB file. " +
        "Equivalent to `cib use <CIB>`.")
    parser.add_option(
        "-D",
        "--display",
        dest="display",
        metavar="OUTPUT_TYPE",
        help=
        "Choose one of the output options: plain, color-always, color, or uppercase. "
        + "The default is color if the terminal emulation supports colors, " +
        "else plain.")
    parser.add_option(
        "-F",
        "--force",
        action="store_true",
        default=False,
        dest="force",
        help="Make crm proceed with applying changes where it would normally "
        +
        "ask the user to confirm before proceeding. This option is mainly useful "
        + "in scripts, and should be used with care.")
    parser.add_option("-n",
                      "--no",
                      action="store_true",
                      default=False,
                      dest="ask_no",
                      help="Automatically answer no when prompted")
    parser.add_option(
        "-w",
        "--wait",
        action="store_true",
        default=False,
        dest="wait",
        help="Make crm wait for the cluster transition to finish " +
        "(for the changes to take effect) after each processed line.")
    parser.add_option(
        "-H",
        "--history",
        dest="history",
        metavar="DIR|FILE|SESSION",
        help="A directory or file containing a cluster report to load " +
        "into history, or the name of a previously saved history session.")
    parser.add_option("-d",
                      "--debug",
                      action="store_true",
                      default=False,
                      dest="debug",
                      help="Print verbose debugging information.")
    parser.add_option(
        "-R",
        "--regression-tests",
        action="store_true",
        default=False,
        dest="regression_tests",
        help="Enables extra verbose trace logging used by the regression " +
        "tests. Logs all external calls made by crmsh.")
    parser.add_option(
        "--scriptdir",
        dest="scriptdir",
        metavar="DIR",
        help="Extra directory where crm looks for cluster scripts, or a list "
        + "of directories separated by semi-colons (e.g. /dir1;/dir2;etc.).")
    parser.add_option("-X",
                      dest="profile",
                      metavar="PROFILE",
                      help="Collect profiling data and save in PROFILE.")
    parser.add_option(
        "-o",
        "--opt",
        action="append",
        type="string",
        metavar="OPTION=VALUE",
        help="Set crmsh option temporarily. If the options are saved using" +
        "+options save+ then the value passed here will also be saved." +
        "Multiple options can be set by using +-o+ multiple times.")
    return parser
Beispiel #49
0
def main():
    """
    Sets up our command line options, prints the usage/help (if warranted), and
    runs :py:func:`pyminifier.pyminify` with the given command line options.
    """
    usage = '%prog [options] "<input file>"'
    if '__main__.py' in sys.argv[0]:  # python -m pyminifier
        usage = 'pyminifier [options] "<input file>"'
    parser = OptionParser(usage=usage, version=__version__)
    parser.disable_interspersed_args()
    parser.add_option("-o",
                      "--outfile",
                      dest="outfile",
                      default=None,
                      help="Save output to the given file.",
                      metavar="<file path>")
    parser.add_option(
        "-d",
        "--destdir",
        dest="destdir",
        default="./minified",
        help=("Save output to the given directory. "
              "This option is required when handling multiple files. "
              "Defaults to './minified' and will be created if not present. "),
        metavar="<file path>")
    parser.add_option(
        "--nominify",
        action="store_true",
        dest="nominify",
        default=False,
        help="Don't bother minifying (only used with --pyz).",
    )
    parser.add_option(
        "--use-tabs",
        action="store_true",
        dest="tabs",
        default=False,
        help="Use tabs for indentation instead of spaces.",
    )
    parser.add_option(
        "--bzip2",
        action="store_true",
        dest="bzip2",
        default=False,
        help=(
            "bzip2-compress the result into a self-executing python script.  "
            "Only works on stand-alone scripts without implicit imports."))
    parser.add_option(
        "--gzip",
        action="store_true",
        dest="gzip",
        default=False,
        help=("gzip-compress the result into a self-executing python script.  "
              "Only works on stand-alone scripts without implicit imports."))
    if lzma:
        parser.add_option(
            "--lzma",
            action="store_true",
            dest="lzma",
            default=False,
            help=
            ("lzma-compress the result into a self-executing python script.  "
             "Only works on stand-alone scripts without implicit imports."))
    parser.add_option(
        "--pyz",
        dest="pyz",
        default=None,
        help=(
            "zip-compress the result into a self-executing python script. "
            "This will create a new file that includes any necessary implicit"
            " (local to the script) modules.  Will include/process all files "
            "given as arguments to pyminifier.py on the command line."),
        metavar="<name of archive>.pyz")
    parser.add_option(
        "-O",
        "--obfuscate",
        action="store_true",
        dest="obfuscate",
        default=False,
        help=("Obfuscate all function/method names, variables, and classes.  "
              "Default is to NOT obfuscate."))
    parser.add_option("--obfuscate-classes",
                      action="store_true",
                      dest="obf_classes",
                      default=False,
                      help="Obfuscate class names.")
    parser.add_option("--obfuscate-functions",
                      action="store_true",
                      dest="obf_functions",
                      default=False,
                      help="Obfuscate function and method names.")
    parser.add_option("--obfuscate-variables",
                      action="store_true",
                      dest="obf_variables",
                      default=False,
                      help="Obfuscate variable names.")
    parser.add_option(
        "--obfuscate-import-methods",
        action="store_true",
        dest="obf_import_methods",
        default=False,
        help=
        "Obfuscate globally-imported mouled methods (e.g. 'Ag=re.compile').")
    parser.add_option(
        "--obfuscate-builtins",
        action="store_true",
        dest="obf_builtins",
        default=False,
        help="Obfuscate built-ins (i.e. True, False, object, Exception, etc).")
    parser.add_option(
        "--replacement-length",
        dest="replacement_length",
        default=1,
        help=(
            "The length of the random names that will be used when obfuscating "
            "identifiers."),
        metavar="1")
    parser.add_option(
        "--nonlatin",
        action="store_true",
        dest="use_nonlatin",
        default=False,
        help=(
            "Use non-latin (unicode) characters in obfuscation (Python 3 only)."
            "  WARNING: This results in some SERIOUSLY hard-to-read code."))
    parser.add_option(
        "--prepend",
        dest="prepend",
        default=None,
        help=("Prepend the text in this file to the top of our output.  "
              "e.g. A copyright notice."),
        metavar="<file path>")
    options, files = parser.parse_args()
    if not files:
        parser.print_help()
        sys.exit(2)
    pyminify(options, files)
    def main(self, argv):
        """
        The main entry point for the build-apidocs command

        @param argv: The list of arguments passed to the build-apidocs command
        """

        parser = OptionParser(usage='build [options] %s VERSION' %
                              (self.command_name, ))
        parser.disable_interspersed_args()
        options, args = parser.parse_args(argv)

        if len(args) != 1:
            parser.error('Wrong number of arguments. This command expects a '
                         'version number only.')

        buildversion = args[0]

        tmpdir = gettempdir()
        workingbranch_dir = self.workingbranch_dir
        build_dir = self.build_dir

        # Check for yuidoc dependencies
        for r in pkg_resources.parse_requirements(YUIDOC_DEPENDENCIES):
            if not pkg_resources.working_set.find(r):
                raise BuildError('Unsatisfied yuidoc dependency: %r' % (r, ))

        # download and cache yuidoc
        yuizip_path = os.path.join(tmpdir, os.path.basename(YUIDOC_URL))
        if os.path.exists(yuizip_path):
            self.log.debug('Using cached YUI doc')

            def producer_local():
                yield open(yuizip_path).read()

            producer = producer_local
        else:
            self.log.debug('Downloading YUI Doc')

            def producer_remote():
                with open(yuizip_path, 'w') as yuizip:
                    download = urlopen(YUIDOC_URL)
                    while True:
                        bytes = download.read(1024 * 10)
                        if not bytes:
                            break
                        else:
                            yuizip.write(bytes)
                            yield bytes

            producer = producer_remote

        checksum = hashlib.md5()
        for bytes in producer():
            checksum.update(bytes)

        actual_md5 = checksum.hexdigest()
        if actual_md5 != YUIDOC_MD5:
            raise BuildError('YUI Doc checksum error. File: %s, '
                             'Expected: %s, '
                             'Got: %s' % (yuizip_path, YUIDOC_MD5, actual_md5))
        else:
            self.log.debug('YUI Doc checksum verified')

        # Remove any existing apidocs so that we can track removed files
        shutil.rmtree(os.path.join(build_dir, 'docs', 'apidocs'), True)

        yuidoc_dir = os.path.join(build_dir, 'yuidoc')

        # extract yuidoc folder from the downloaded zip file
        self.log.debug('Extracting YUI Doc from %s to %s' %
                       (yuizip_path, yuidoc_dir))
        zip = ZipFile(yuizip_path)
        zip.extractall(build_dir,
                       (m for m in zip.namelist() if m.startswith('yuidoc')))

        # Use the yuidoc script that we just extracted to generate new docs
        self.log.debug('Running YUI Doc')
        check_call(
            (
                sys.executable,
                os.path.join(yuidoc_dir, 'bin', 'yuidoc.py'),
                os.path.join(workingbranch_dir, 'jarmon'),
                '--parseroutdir=%s' %
                (os.path.join(build_dir, 'docs', 'apidocs'), ),
                '--outputdir=%s' %
                (os.path.join(build_dir, 'docs', 'apidocs'), ),
                '--template=%s' % (os.path.join(
                    workingbranch_dir, 'jarmonbuild', 'yuidoc_template'), ),
                '--version=%s' % (buildversion, ),
                '--project=%s' % (JARMON_PROJECT_TITLE, ),
                '--projecturl=%s' % (JARMON_PROJECT_URL, ),
            ),
            stdout=PIPE,
            stderr=PIPE,
        )

        shutil.rmtree(yuidoc_dir)
Beispiel #51
0
def main():
    from calibre.utils.terminal import geometry
    cols = geometry()[0]

    parser = OptionParser(
        usage="usage: %prog [options] command args\n\ncommand " +
        "is one of: info, books, df, ls, cp, mkdir, touch, cat, rm, eject, test_file\n\n"
        + "For help on a particular command: %prog command",
        version=__appname__ + " version: " + __version__)
    parser.add_option(
        "--log-packets",
        help="print out packet stream to stdout. " +
        "The numbers in the left column are byte offsets that allow the packet size to be read off easily.",
        dest="log_packets",
        action="store_true",
        default=False)
    parser.remove_option("-h")
    parser.disable_interspersed_args()  # Allow unrecognized options
    options, args = parser.parse_args()

    if len(args) < 1:
        parser.print_help()
        return 1

    command = args[0]
    args = args[1:]
    dev = None
    scanner = DeviceScanner()
    scanner.scan()
    connected_devices = []

    for d in device_plugins():
        try:
            d.startup()
        except:
            print(('Startup failed for device plugin: %s' % d))
        if d.MANAGES_DEVICE_PRESENCE:
            cd = d.detect_managed_devices(scanner.devices)
            if cd is not None:
                connected_devices.append((cd, d))
                dev = d
                break
            continue
        ok, det = scanner.is_device_connected(d)
        if ok:
            dev = d
            dev.reset(log_packets=options.log_packets, detected_device=det)
            connected_devices.append((det, dev))

    if dev is None:
        print('Unable to find a connected ebook reader.', file=sys.stderr)
        shutdown_plugins()
        return 1

    for det, d in connected_devices:
        try:
            d.open(det, None)
        except:
            continue
        else:
            dev = d
            d.specialize_global_preferences(device_prefs)
            break

    try:
        if command == "df":
            total = dev.total_space(end_session=False)
            free = dev.free_space()
            where = ("Memory", "Card A", "Card B")
            print("Filesystem\tSize \tUsed \tAvail \tUse%")
            for i in range(3):
                print(
                    "%-10s\t%s\t%s\t%s\t%s" %
                    (where[i], human_readable(total[i]),
                     human_readable(total[i] - free[i]), human_readable(
                         free[i]),
                     str(0 if total[i] == 0 else int(100 *
                                                     (total[i] - free[i]) /
                                                     (total[i] * 1.))) + "%"))
        elif command == 'eject':
            dev.eject()
        elif command == "books":
            print("Books in main memory:")
            for book in dev.books():
                print(book)
            print("\nBooks on storage carda:")
            for book in dev.books(oncard='carda'):
                print(book)
            print("\nBooks on storage cardb:")
            for book in dev.books(oncard='cardb'):
                print(book)
        elif command == "mkdir":
            parser = OptionParser(
                usage=
                "usage: %prog mkdir [options] path\nCreate a directory on the device\n\npath must begin with / or card:/"
            )
            if len(args) != 1:
                parser.print_help()
                sys.exit(1)
            dev.mkdir(args[0])
        elif command == "ls":
            parser = OptionParser(
                usage=
                "usage: %prog ls [options] path\nList files on the device\n\npath must begin with / or card:/"
            )
            parser.add_option(
                "-l",
                help=
                "In addition to the name of each file, print the file type, permissions, and  timestamp  (the  modification time, in the local timezone). Times are local.",  # noqa
                dest="ll",
                action="store_true",
                default=False)
            parser.add_option(
                "-R",
                help=
                "Recursively list subdirectories encountered. /dev and /proc are omitted",
                dest="recurse",
                action="store_true",
                default=False)
            parser.remove_option("-h")
            parser.add_option("-h",
                              "--human-readable",
                              help="show sizes in human readable format",
                              dest="hrs",
                              action="store_true",
                              default=False)
            options, args = parser.parse_args(args)
            if len(args) != 1:
                parser.print_help()
                return 1
            print(ls(dev,
                     args[0],
                     recurse=options.recurse,
                     ll=options.ll,
                     human_readable_size=options.hrs,
                     cols=cols),
                  end=' ')
        elif command == "info":
            info(dev)
        elif command == "cp":
            usage="usage: %prog cp [options] source destination\nCopy files to/from the device\n\n"+\
            "One of source or destination must be a path on the device. \n\nDevice paths have the form\n"+\
            "dev:mountpoint/my/path\n"+\
            "where mountpoint is one of / or carda: or cardb:/\n\n"+\
            "source must point to a file for which you have read permissions\n"+\
            "destination must point to a file or directory for which you have write permissions"
            parser = OptionParser(usage=usage)
            parser.add_option(
                '-f',
                '--force',
                dest='force',
                action='store_true',
                default=False,
                help='Overwrite the destination file if it exists already.')
            options, args = parser.parse_args(args)
            if len(args) != 2:
                parser.print_help()
                return 1
            if args[0].startswith("dev:"):
                outfile = args[1]
                path = args[0][4:]
                if path.endswith("/"):
                    path = path[:-1]
                if os.path.isdir(outfile):
                    outfile = os.path.join(outfile, path[path.rfind("/") + 1:])
                try:
                    outfile = lopen(outfile, "wb")
                except IOError as e:
                    print(e, file=sys.stderr)
                    parser.print_help()
                    return 1
                dev.get_file(path, outfile)
                fsync(outfile)
                outfile.close()
            elif args[1].startswith("dev:"):
                try:
                    infile = lopen(args[0], "rb")
                except IOError as e:
                    print(e, file=sys.stderr)
                    parser.print_help()
                    return 1
                dev.put_file(infile, args[1][4:], replace_file=options.force)
                infile.close()
            else:
                parser.print_help()
                return 1
        elif command == "cat":
            outfile = sys.stdout
            parser = OptionParser(
                usage=
                "usage: %prog cat path\nShow file on the device\n\npath should point to a file on the device and must begin with /,a:/ or b:/"
            )
            options, args = parser.parse_args(args)
            if len(args) != 1:
                parser.print_help()
                return 1
            if args[0].endswith("/"):
                path = args[0][:-1]
            else:
                path = args[0]
            outfile = sys.stdout
            dev.get_file(path, outfile)
        elif command == "rm":
            parser = OptionParser(
                usage=
                "usage: %prog rm path\nDelete files from the device\n\npath should point to a file or empty directory on the device "
                + "and must begin with / or card:/\n\n" +
                "rm will DELETE the file. Be very CAREFUL")
            options, args = parser.parse_args(args)
            if len(args) != 1:
                parser.print_help()
                return 1
            dev.rm(args[0])
        elif command == "touch":
            parser = OptionParser(
                usage=
                "usage: %prog touch path\nCreate an empty file on the device\n\npath should point to a file on the device and must begin with /,a:/ or b:/\n\n"
                +  # noqa
                "Unfortunately, I cant figure out how to update file times on the device, so if path already exists, touch does nothing"
            )
            options, args = parser.parse_args(args)
            if len(args) != 1:
                parser.print_help()
                return 1
            dev.touch(args[0])
        elif command == 'test_file':
            parser = OptionParser(usage=(
                "usage: %prog test_file path\n"
                'Open device, copy file specified by path to device and '
                'then eject device.'))
            options, args = parser.parse_args(args)
            if len(args) != 1:
                parser.print_help()
                return 1
            path = args[0]
            from calibre.ebooks.metadata.meta import get_metadata
            mi = get_metadata(lopen(path, 'rb'),
                              path.rpartition('.')[-1].lower())
            print(
                dev.upload_books([args[0]], [os.path.basename(args[0])],
                                 end_session=False,
                                 metadata=[mi]))
            dev.eject()
        else:
            parser.print_help()
            if getattr(dev, 'handle', False):
                dev.close()
            return 1
    except DeviceLocked:
        print("The device is locked. Use the --unlock option", file=sys.stderr)
    except (ArgumentError, DeviceError) as e:
        print(e, file=sys.stderr)
        return 1
    finally:
        shutdown_plugins()

    return 0
Beispiel #52
0
class Command(object):
    def __init__(self, name, args):
        self.name = name.lower()
        self.args = args
        self.msg = "%prog SUBCOMMAND [OPTIONS]" + "\n" + "Subcommand:" + "\n"
        self.msg += util.get_message(self.name)
        self.err_msg = util.get_err_message(self.name)
        self.parser = OptionParser(usage=self.msg[:-1],
                                   prog=define.PROG,
                                   version=define.VERSION,
                                   add_help_option=False)
        self.parser.disable_interspersed_args()

    def run(self):
        if self.check_args():
            pass
        else:
            return

        if self.name == "click":
            self.run_click()
        elif self.name == "mouse":
            self.run_mouse()
        elif self.name == "wmove":
            self.run_wmove()
        elif self.name == "scroll":
            self.run_scroll()
        elif self.name == "wsize":
            self.run_wsize()
        elif self.name == "tab":
            self.run_tab()
        elif self.name == "back":
            self.run_back()
        elif self.name == "next":
            self.run_next()
        elif self.name == "reload":
            self.run_reload()
        elif self.name == "abort":
            self.run_abort()
        elif self.name == "home":
            self.run_home()
        elif self.name == "start":
            self.run_start()
        elif self.name == "restart":
            self.run_restart()
        elif self.name == "stop":
            self.run_stop()
        elif self.name == "wopen":
            self.run_wopen()
        elif self.name == "wclose":
            self.run_wclose()
        elif self.name == "search":
            self.run_search()
        elif self.name == "url":
            self.run_url()
        elif self.name == "typo":
            self.run_typo()

    def check_args(self):
        if (len(self.args) != 0) == define.command_fargs[self.name]:
            return True
        else:
            #self.parser.print_help()
            self.parser.error(self.err_msg)
            return False

    def run_click(self):
        arg = self.args[0]
        path = SCRIPT_DIR + "/click.scpt"
        if os.path.exists(path):
            pass
        else:
            self.parser.print_help()
            self.parser.error(util.get_err_option(self.name))
            return

        if arg.lower() == "c" or arg.lower() == "single" or arg.lower() == "s":
            path = path + " c"
        elif arg.lower() == "dc" or arg.lower() == "double" or arg.lower(
        ) == "d":
            path = path + " dc"
        elif arg.lower() == "tc" or arg.lower() == "triple" or arg.lower(
        ) == "t":
            path = path + " tc"
        elif arg.lower() == "rc" or arg.lower() == "right" or arg.lower(
        ) == "r":
            path = path + " rc"
        elif arg.lower() == "ctn" or arg.lower() == "tabnew" or arg.lower(
        ) == "tab_new" or arg.lower() == "tn":
            path = path + " ctn"
        else:
            self.parser.error(util.get_err_option(self.name))
            return

        self.execute(path)
        return

    def run_mouse(self):
        path = SCRIPT_DIR + "/move_mouse.scpt"
        x = 0
        y = 0
        for key in self.args:
            if key.lower() == "u" or key.lower() == "up":
                y = y - 25
            elif key.lower() == "d" or key.lower() == "down":
                y = y + 25
            elif key.lower() == "r" or key.lower() == "right":
                x = x + 25
            elif key.lower() == "l" or key.lower() == "left":
                x = x - 25

        def convert_str(num):
            if num >= 0:
                return "+%d" % num
            else:
                return "%d" % num

        if (x != 0 or y != 0) and os.path.exists(path):
            option = " %s %s" % (convert_str(x), convert_str(y))
            self.execute(path + option)
        else:
            self.parser.error(util.get_err_option(self.name))
        return

    def run_wmove(self):
        arg = self.args[0]
        path = ""
        if arg.lower() == "l" or arg.lower() == "left":
            path = SCRIPT_DIR + "/move_left.scpt"
        elif arg.lower() == "r" or arg.lower() == "right":
            path = SCRIPT_DIR + "/move_right.scpt"

        if path != "" and os.path.exists(path):
            self.execute(path)
        else:
            self.parser.error(util.get_err_option(self.name))
        return

    def run_scroll(self):
        arg = self.args[0]
        path = ""
        if arg.lower() == "u" or arg.lower() == "up":
            path = SCRIPT_DIR + "/up_scroll.scpt"
        elif arg.lower() == "d" or arg.lower() == "down":
            path = SCRIPT_DIR + "/down_scroll.scpt"
        elif arg.lower() == "r" or arg.lower() == "right":
            path = SCRIPT_DIR + "/right_scroll.scpt"
        elif arg.lower() == "l" or arg.lower() == "left":
            path = SCRIPT_DIR + "/left_scroll.scpt"

        if path != "" and os.path.exists(path):
            self.execute(path)
        else:
            self.parser.error(util.get_err_option(self.name))
        return

    def run_wsize(self):
        arg = self.args[0]
        path = ""
        if arg.lower() == "hu":
            path = SCRIPT_DIR + "/twice_h.scpt"
        elif arg.lower() == "hd":
            path = SCRIPT_DIR + "/half_h.scpt"
        elif arg.lower() == "wu":
            path = SCRIPT_DIR + "/twice_w.scpt"
        elif arg.lower() == "wd":
            path = SCRIPT_DIR + "/half_w.scpt"
        elif arg.lower() == "std" or arg.lower() == "standard" or arg.lower(
        ) == "max":
            path = SCRIPT_DIR + "/maxsize.scpt"
        elif arg.lower() == "min":
            path = SCRIPT_DIR + "/minsize.scpt"
        elif arg.lower() == "full" or arg.lower() == "presentation":
            path = SCRIPT_DIR + "/fill_title.scpt"
        elif arg.lower() == "norm" or arg.lower() == "normal":
            path = SCRIPT_DIR + "/return_fill_title.scpt"

        if path != "" and os.path.exists(path):
            self.execute(path)
        else:
            self.parser.error(util.get_err_option(self.name))
        return

    def run_tab(self):
        arg = self.args[0]
        path = ""
        if arg.lower() == "nw" or arg.lower() == "new":
            path = SCRIPT_DIR + "/tab_new.scpt"
        elif arg.lower() == "cl" or arg.lower() == "close" or arg.lower(
        ) == "rm" or arg.lower() == "remove":
            path = SCRIPT_DIR + "/tab_remove.scpt"
        elif arg.lower() == "nx" or arg.lower() == "next" or arg.lower(
        ) == "r" or arg.lower() == "right":
            path = SCRIPT_DIR + "/tab_next.scpt"
        elif arg.lower() == "bk" or arg.lower() == "back" or arg.lower(
        ) == "l" or arg.lower() == "left":
            path = SCRIPT_DIR + "/tab_back.scpt"

        if path != "" and os.path.exists(path):
            self.execute(path)
        else:
            self.parser.error(util.get_err_option(self.name))
        return

    def run_back(self):
        path = SCRIPT_DIR + "/back.scpt"
        if os.path.exists(path):
            self.execute(path)
        return

    def run_next(self):
        path = SCRIPT_DIR + "/next.scpt"
        if os.path.exists(path):
            self.execute(path)
        return

    def run_reload(self):
        path = SCRIPT_DIR + "/reload.scpt"
        if os.path.exists(path):
            self.execute(path)
        return

    def run_abort(self):
        path = SCRIPT_DIR + "/load_cancel.scpt"
        if os.path.exists(path):
            self.execute(path)
        return

    def run_home(self):
        path = SCRIPT_DIR + "/home.scpt"
        if os.path.exists(path):
            self.execute(path)
        return

    def run_start(self):
        path = SCRIPT_DIR + "/activate.scpt"
        if os.path.exists(path):
            self.execute(path)
        return

    def run_restart(self):
        path = SCRIPT_DIR + "/restart.scpt"
        if os.path.exists(path):
            self.execute(path)
        return

    def run_stop(self):
        path = SCRIPT_DIR + "/quit.scpt"
        if os.path.exists(path):
            self.execute(path)
        return

    def run_wopen(self):
        path = SCRIPT_DIR + "/reopen.scpt"
        if os.path.exists(path):
            self.execute(path)
        return

    def run_wclose(self):
        path = SCRIPT_DIR + "/close.scpt"
        if os.path.exists(path):
            self.execute(path)
        return

    def run_search(self):
        path = SCRIPT_DIR + "/search.scpt"
        if os.path.exists(path):
            for arg in self.args:
                path += " " + arg
            self.execute(path)
        return

    def run_url(self):
        path = SCRIPT_DIR + "/open_url.scpt"
        if os.path.exists(path):
            path += " " + self.args[0]
            self.execute(path)
        return

    def run_typo(self):
        path = SCRIPT_DIR + "/typo.scpt"
        if os.path.exists(path):
            for arg in self.args:
                path += " " + arg
            self.execute(path)
        return

    def execute(self, path):
        os.system(path + " >/dev/null 2>&1")
Beispiel #53
0
def main():

    # TODO: use LenientOptionParser
    parser = OptionParser(usage=usage_long)
    parser.disable_interspersed_args()
    additional_modules = []

    def load_module(option, opt_str, value, parser):  # @UnusedVariable
        additional_modules.append(value)

    additional_directories = []

    def add_directory(option, opt_str, value, parser):  # @UnusedVariable
        additional_directories.append(value)

    parser.add_option("-m", dest="module",
                  action="callback", callback=load_module,
                  type="string", help='Loads the specified module.')

    parser.add_option("-d", dest='directory', type="string",
                      action="callback", callback=add_directory,
                      help='Additional directory to search for models.')

    parser.add_option("--debug", action="store_true", default=False,
                      help="Displays debug information on the model.")

    parser.add_option("--trace", action="store_true",
                      default=False, dest="trace",
                      help="If true, try to display raw stack trace in case  "
                           " of error, instead of the usual friendly message.")

    parser.add_option("--stats", action="store_true",
                      default=False, dest="stats",
                      help="Displays execution stats, including CPU usage.")

    parser.add_option("--nocache", action="store_true", default=False,
                      help="Ignores the parsing cache.")

    (options, args) = parser.parse_args()

    # TODO: make an option to display all the known models
    # if options.debug:
    #    print "Configuration: %s" % config
    if not args:
        print(usage_short)
        sys.exit(-1)

    filename = args.pop(0)

    if options.trace:
        look_for = RuntimeError
    else:
        look_for = PGException

    try:
        config = parse_cmdline_args(args)

        pg(filename, config,
           nocache=options.nocache,
           debug=options.debug,
           stats=options.stats,
           additional_directories=additional_directories,
           additional_modules=additional_modules)

        sys.exit(0)

    except look_for as e:
        error(e)
        if not options.trace:
            info('If you run "pg" with the "--trace" option, you can see the '
                 'python details for this error.')
        sys.exit(-2)
Beispiel #54
0
def main():
    optparser = OptionParser(usage=usage_str)
    optparser.add_option(
        "--token",
        dest="api_token",
        default=os.getenv('QDS_API_TOKEN'),
        help=
        "api token for accessing Qubole. must be specified via command line or passed in via environment variable QDS_API_TOKEN"
    )

    optparser.add_option(
        "--url",
        dest="api_url",
        default=os.getenv('QDS_API_URL'),
        help=
        "base url for QDS REST API. defaults to https://api.qubole.com/api ")

    optparser.add_option(
        "--version",
        dest="api_version",
        default=os.getenv('QDS_API_VERSION'),
        help="version of REST API to access. defaults to v1.2")

    optparser.add_option(
        "--poll_interval",
        dest="poll_interval",
        type=int,
        default=os.getenv('QDS_POLL_INTERVAL'),
        help=
        "interval for polling API for completion and other events. defaults to 5s"
    )

    optparser.add_option(
        "--skip_ssl_cert_check",
        dest="skip_ssl_cert_check",
        action="store_true",
        default=False,
        help=
        "skip verification of server SSL certificate. Insecure: use with caution."
    )

    optparser.add_option(
        "--cloud_name",
        dest="cloud_name",
        default=os.getenv('CLOUD_PROVIDER'),
        help="cloud",
        choices=["AWS", "AZURE", "ORACLE_BMC", "ORACLE_OPC", "GCP"])

    optparser.add_option(
        "--base_retry_delay",
        dest="base_retry_delay",
        type=int,
        default=os.getenv('QDS_BASE_RETRY_DELAY'),
        help="base sleep interval for exponential backoff in case of "
        "retryable exceptions.Defaults to 10s.")

    optparser.add_option(
        "--max_retries",
        dest="max_retries",
        type=int,
        default=os.getenv('QDS_MAX_RETRIES'),
        help="Number of re-attempts for an api-call in case of "
        " retryable exceptions. Defaults to 5.")

    optparser.add_option("-v",
                         dest="verbose",
                         action="store_true",
                         default=False,
                         help="verbose mode - info level logging")

    optparser.add_option("--vv",
                         dest="chatty",
                         action="store_true",
                         default=False,
                         help="very verbose mode - debug level logging")

    optparser.disable_interspersed_args()
    (options, args) = optparser.parse_args()

    if options.chatty:
        logging.basicConfig(level=logging.DEBUG)
    elif options.verbose:
        logging.basicConfig(level=logging.INFO)
    else:
        logging.basicConfig(level=logging.WARN)

    if options.api_token is None:
        sys.stderr.write("No API Token provided\n")
        usage(optparser)

    if options.api_url is None:
        options.api_url = "https://api.qubole.com/api/"

    if options.api_version is None:
        options.api_version = "v1.2"

    if options.poll_interval is None:
        options.poll_interval = 5

    if options.max_retries is None:
        options.max_retries = 5

    if options.base_retry_delay is None:
        options.base_retry_delay = 10

    if options.cloud_name is None:
        options.cloud_name = "AWS"

    if options.skip_ssl_cert_check is None:
        options.skip_ssl_cert_check = False
    elif options.skip_ssl_cert_check:
        log.warn("Insecure mode enabled: skipping SSL cert verification\n")

    Qubole.configure(api_token=options.api_token,
                     api_url=options.api_url,
                     version=options.api_version,
                     poll_interval=options.poll_interval,
                     skip_ssl_cert_check=options.skip_ssl_cert_check,
                     cloud_name=options.cloud_name,
                     base_retry_delay=options.base_retry_delay,
                     max_retries=options.max_retries)

    if len(args) < 1:
        sys.stderr.write("Missing first argument containing subcommand\n")
        usage(optparser)

    a0 = args.pop(0)
    if a0 in CommandClasses:
        return cmdmain(a0, args)

    if a0 in SensorClasses:
        return sensormain(a0, args)

    if a0 == "account":
        return accountmain(args)

    if a0 == "cluster":
        api_version_number = float(options.api_version[1:])
        if api_version_number >= 2.0:
            return clustermainv2(args)
        else:
            return clustermain(args, api_version_number)

    if a0 == "action":
        return actionmain(args)

    if a0 == "scheduler":
        return schedulermain(args)

    if a0 == "report":
        return reportmain(args)

    if a0 == "dbtap":
        return dbtapmain(args)

    if a0 == "group":
        return groupmain(args)

    if a0 == "role":
        return rolemain(args)

    if a0 == "app":
        return appmain(args)

    if a0 == "nezha":
        return nezhamain(args)

    if a0 == "user":
        return usermain(args)
    if a0 == "template":
        return templatemain(args)
    if a0 == "quest":
        return questmain(args)

    cmdset = set(CommandClasses.keys())
    sys.stderr.write("First command must be one of <%s>\n" % "|".join(
        cmdset.union([
            "cluster", "action", "scheduler", "report", "dbtap", "role",
            "group", "app", "account", "nezha", "user", "template", "quest"
        ])))
    usage(optparser)
Beispiel #55
0
def main():
    global name_generator
    usage = '%prog [options] "<input file>"'
    parser = OptionParser(usage=usage, version=__version__)
    parser.disable_interspersed_args()
    parser.add_option("-o",
                      "--outfile",
                      dest="outfile",
                      default=None,
                      help="Save output to the given file.",
                      metavar="<file path>")
    parser.add_option(
        "-d",
        "--destdir",
        dest="destdir",
        default="./minified",
        help=("Save output to the given directory. "
              "This option is required when handling multiple files. "
              "Defaults to './minified' and will be created if not present. "),
        metavar="<file path>")
    parser.add_option(
        "--nominify",
        action="store_true",
        dest="nominify",
        default=False,
        help="Don't bother minifying (only used with --pyz).",
    )
    parser.add_option(
        "--use-tabs",
        action="store_true",
        dest="tabs",
        default=False,
        help="Use tabs for indentation instead of spaces.",
    )
    parser.add_option(
        "--bzip2",
        action="store_true",
        dest="bzip2",
        default=False,
        help=(
            "bzip2-compress the result into a self-executing python script.  "
            "Only works on stand-alone scripts without implicit imports."))
    parser.add_option(
        "--gzip",
        action="store_true",
        dest="gzip",
        default=False,
        help=("gzip-compress the result into a self-executing python script.  "
              "Only works on stand-alone scripts without implicit imports."))
    if lzma:
        parser.add_option(
            "--lzma",
            action="store_true",
            dest="lzma",
            default=False,
            help=
            ("lzma-compress the result into a self-executing python script.  "
             "Only works on stand-alone scripts without implicit imports."))
    parser.add_option(
        "--pyz",
        dest="pyz",
        default=None,
        help=(
            "zip-compress the result into a self-executing python script. "
            "This will create a new file that includes any necessary implicit"
            " (local to the script) modules.  Will include/process all files "
            "given as arguments to pyminifier.py on the command line."),
        metavar="<name of archive>.pyz")
    parser.add_option(
        "-O",
        "--obfuscate",
        action="store_true",
        dest="obfuscate",
        default=False,
        help=("Obfuscate all function/method names, variables, and classes.  "
              "Default is to NOT obfuscate."))
    parser.add_option("--obfuscate-classes",
                      action="store_true",
                      dest="obf_classes",
                      default=False,
                      help="Obfuscate class names.")
    parser.add_option("--obfuscate-functions",
                      action="store_true",
                      dest="obf_functions",
                      default=False,
                      help="Obfuscate function and method names.")
    parser.add_option("--obfuscate-variables",
                      action="store_true",
                      dest="obf_variables",
                      default=False,
                      help="Obfuscate variable names.")
    parser.add_option(
        "--obfuscate-import-methods",
        action="store_true",
        dest="obf_import_methods",
        default=False,
        help=
        "Obfuscate globally-imported mouled methods (e.g. 'Ag=re.compile').")
    parser.add_option(
        "--obfuscate-builtins",
        action="store_true",
        dest="obf_builtins",
        default=False,
        help="Obfuscate built-ins (i.e. True, False, object, Exception, etc).")
    parser.add_option(
        "--replacement-length",
        dest="replacement_length",
        default=1,
        help=(
            "The length of the random names that will be used when obfuscating "
            "identifiers."),
        metavar="1")
    parser.add_option(
        "--nonlatin",
        action="store_true",
        dest="use_nonlatin",
        default=False,
        help=(
            "Use non-latin (unicode) characters in obfuscation (Python 3 only)."
            "  WARNING: This results in some SERIOUSLY hard-to-read code."))
    parser.add_option(
        "--prepend",
        dest="prepend",
        default=None,
        help=("Prepend the text in this file to the top of our output.  "
              "e.g. A copyright notice."),
        metavar="<file path>")
    options, args = parser.parse_args()
    try:
        pyz_file = args[0]
    except Exception as err:  # Note: This syntax requires Python 2.6+
        print(err)  # Just in case it is something wierd
        parser.print_help()
        sys.exit(2)
    if options.pyz:
        # Check to make sure we were only passed one script (only one at a time)
        if len(args) > 1:
            print("ERROR: The --pyz option only works with one python file at "
                  "a time.")
            print("(Dependencies will be automagically included in the "
                  "resulting .pyz)")
            sys.exit(1)
        # Make our .pyz:
        compression.zip_pack(pyz_file, options)
        return None  # Make sure we don't do anything else
    # Read in our prepend text (if any)
    prepend = None
    if options.prepend:
        try:
            prepend = open(options.prepend).read()
        except Exception as err:
            print("Error reading %s:" % options.prepend)
            print(err)
    # Automatically enable --obfuscate if --nonlatin (it's implied)
    if options.use_nonlatin:
        options.obfuscate = True
    if len(args) > 1:  # We're dealing with more than one file
        name_generator = None  # So we can tell if we need to obfuscate
        if options.obfuscate or options.obf_classes \
           or options.obf_functions or options.obf_variables \
           or options.obf_builtins or options.obf_import_methods:
            # Put together that will be used for all obfuscation functions:
            identifier_length = int(options.replacement_length)
            if options.use_nonlatin:
                if sys.version_info[0] == 3:
                    name_generator = obfuscate.obfuscation_machine(
                        use_unicode=True, identifier_length=identifier_length)
                else:
                    print(
                        "ERROR: You can't use nonlatin characters without Python 3"
                    )
                    sys.exit(2)
            else:
                name_generator = obfuscate.obfuscation_machine(
                    identifier_length=identifier_length)
            table = [{}]
        cumulative_size = 0  # For size reduction stats
        cumulative_new = 0  # Ditto
        for sourcefile in args:
            # Record how big the file is so we can compare afterwards
            filesize = os.path.getsize(sourcefile)
            cumulative_size += filesize
            # Get the module name from the path
            module = os.path.split(sourcefile)[1]
            module = ".".join(module.split('.')[:-1])
            source = open(sourcefile).read()
            tokens = token_utils.listified_tokenizer(source)
            if not options.nominify:  # Perform minification
                source = minification.minify(tokens, options)
            # Have to re-tokenize for obfucation (it is quick):
            tokens = token_utils.listified_tokenizer(source)
            # Perform obfuscation if any of the related options were set
            if name_generator:
                obfuscate.obfuscate(module,
                                    tokens,
                                    options,
                                    name_generator=name_generator,
                                    table=table)
            # Convert back to text
            result = token_utils.untokenize(tokens)
            # Compress it if we were asked to do so
            if options.bzip2:
                result = compression.bz2_pack(result)
            elif options.gzip:
                result = compression.gz_pack(result)
            elif lzma and options.lzma:
                result = compression.lzma_pack(result)
            result += ("# Created by pyminifier "
                       "(https://github.com/liftoff/pyminifier)\n")
            # Either save the result to the output file or print it to stdout
            if not os.path.exists(options.destdir):
                os.mkdir(options.destdir)
            # Need the path where the script lives for the next steps:
            filepath = os.path.split(sourcefile)[1]
            path = options.destdir + '/' + filepath  # Put everything in destdir
            f = open(path, 'w')
            f.write(result)
            f.close()
            new_filesize = os.path.getsize(path)
            cumulative_new += new_filesize
            percent_saved = round(
                (float(new_filesize) / float(filesize)) * 100, 2)
            print("%s (%s) reduced to %s bytes (%s%% of original size)" %
                  (sourcefile, filesize, new_filesize, percent_saved))
        print("Overall size reduction: %s%% of original size" % round(
            (float(cumulative_new) / float(cumulative_size) * 100), 2))
    else:
        # Get the module name from the path
        module = os.path.split(args[0])[1]
        module = ".".join(module.split('.')[:-1])
        filesize = os.path.getsize(args[0])
        source = open(args[0]).read()
        # Convert the tokens from a tuple of tuples to a list of lists so we can
        # update in-place.
        tokens = token_utils.listified_tokenizer(source)
        if not options.nominify:  # Perform minification
            source = minification.minify(tokens, options)
            # Convert back to tokens in case we're obfuscating
            tokens = token_utils.listified_tokenizer(source)
        # Perform obfuscation if any of the related options were set
        if options.obfuscate or options.obf_classes or options.obf_functions \
           or options.obf_variables or options.obf_builtins \
           or options.obf_import_methods:
            identifier_length = int(options.replacement_length)
            name_generator = obfuscate.obfuscation_machine(
                identifier_length=identifier_length)
            obfuscate.obfuscate(module, tokens, options)
        # Convert back to text
        result = token_utils.untokenize(tokens)
        # Compress it if we were asked to do so
        if options.bzip2:
            result = compression.bz2_pack(result)
        elif options.gzip:
            result = compression.gz_pack(result)
        elif lzma and options.lzma:
            result = compression.lzma_pack(result)
        result += ("# Created by pyminifier "
                   "(https://github.com/liftoff/pyminifier)\n")
        # Either save the result to the output file or print it to stdout
        if options.outfile:
            f = open(options.outfile, 'w', encoding='utf-8')
            f.write(result)
            f.close()
            new_filesize = os.path.getsize(options.outfile)
            print("%s (%s) reduced to %s bytes (%s%% of original size)" %
                  (args[0], filesize, new_filesize,
                   round(float(new_filesize) / float(filesize) * 100, 2)))
        else:
            print(result)
Beispiel #56
0
def parse_options(args):
    global options

    hostname = None

    parser = OptionParser(usage='%prog [options] [user@]hostname [command]',
                          version='%prog ' + get_version_string())
    parser.disable_interspersed_args()
    parser.add_option('-l',
                      dest='username',
                      metavar='USERNAME',
                      default=None,
                      help='the user to log in as on the remote machine')
    parser.add_option('-p',
                      '--port',
                      type='int',
                      dest='port',
                      metavar='PORT',
                      default=None,
                      help='the port to connect to')
    parser.add_option('-q',
                      '--quiet',
                      action='store_true',
                      dest='quiet',
                      default=False,
                      help='suppress any unnecessary output')
    parser.add_option('-s',
                      dest='subsystem',
                      metavar='SUBSYSTEM',
                      default=None,
                      nargs=2,
                      help='the subsystem to use (ssh or sftp)')
    parser.add_option('-V',
                      action='callback',
                      callback=print_version,
                      help='display the version information and exit')
    parser.add_option('--rb-disallow-agent',
                      action='store_false',
                      dest='allow_agent',
                      default=os.getenv('RBSSH_ALLOW_AGENT') != '0',
                      help='disable using the SSH agent for authentication')
    parser.add_option(
        '--rb-local-site',
        dest='local_site_name',
        metavar='NAME',
        default=os.getenv('RB_LOCAL_SITE'),
        help='the local site name containing the SSH keys to use')

    (options, args) = parser.parse_args(args)

    if options.subsystem:
        if len(options.subsystem) != 2:
            parser.error('-s requires a hostname and a valid subsystem')
        elif options.subsystem[1] not in ('sftp', 'ssh'):
            parser.error('Invalid subsystem %s' % options.subsystem[1])

        hostname, options.subsystem = options.subsystem

    if len(args) == 0 and not hostname:
        parser.print_help()
        sys.exit(1)

    if not hostname:
        hostname = args[0]
        args = args[1:]

    return hostname, args
Beispiel #57
0
def main():
    """ creates a HAL component.
        parsees a glade XML file with gtk.builder or libglade
        calls gladevcp.makepins with the specified XML file
        to create pins and register callbacks.
        main window must be called "window1"
    """
    global gladevcp_debug
    (progdir, progname) = os.path.split(sys.argv[0])

    usage = "usage: %prog [options] myfile.ui"
    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()
    parser.add_options(options)

    (opts, args) = parser.parse_args()

    if not args:
        parser.print_help()
        sys.exit(1)

    gladevcp_debug = debug = opts.debug
    xmlname = args[0]

    #if there was no component name specified use the xml file name
    if opts.component is None:
        opts.component = os.path.splitext(os.path.basename(xmlname))[0]

    #try loading as a libglade project
    try:
        builder = gtk.glade.XML(xmlname)
        builder = GladeBuilder(builder)
    except:
        try:
            # try loading as a gtk.builder project
            print "**** GLADE VCP INFO:    Not a libglade project, trying to load as a GTK builder project"
            builder = gtk.Builder()
            builder.add_from_file(xmlname)
        except:
            print "**** GLADE VCP ERROR:    With xml file: %s" % xmlname
            sys.exit(0)

    window = builder.get_object("window1")

    window.set_title(opts.component)

    try:
        halcomp = hal.component(opts.component)
    except:
        print "*** GLADE VCP ERROR:    Asking for a HAL component using a name that already exists."
        sys.exit(0)

    panel = gladevcp.makepins.GladePanel(halcomp, xmlname, builder, None)

    # at this point, any glade HL widgets and their pins are set up.
    handlers = load_handlers(opts.usermod, halcomp, builder, opts.useropts)

    builder.connect_signals(handlers)

    if opts.parent:
        # block X errors since gdk error handling silently exits the
        # program without even the atexit handler given a chance
        gtk.gdk.error_trap_push()

        window = xembed.reparent(window, opts.parent)

        forward = os.environ.get('AXIS_FORWARD_EVENTS_TO', None)
        if forward:
            xembed.keyboard_forward(window, forward)

    window.connect("destroy", on_window_destroy)
    window.show()

    # for window resize and or position options
    if "+" in opts.geometry:
        try:
            j = opts.geometry.partition("+")
            pos = j[2].partition("+")
            window.move(int(pos[0]), int(pos[2]))
        except:
            print "**** GLADE VCP ERROR:    With window position data"
            parser.print_usage()
            sys.exit(1)
    if "x" in opts.geometry:
        try:
            if "+" in opts.geometry:
                j = opts.geometry.partition("+")
                t = j[0].partition("x")
            else:
                t = window_geometry.partition("x")
            window.resize(int(t[0]), int(t[2]))
        except:
            print "**** GLADE VCP ERROR:    With window resize data"
            parser.print_usage()
            sys.exit(1)

    if opts.gtk_workaround:
        # work around https://bugs.launchpad.net/ubuntu/+source/pygtk/+bug/507739
        # this makes widget and widget_class matches in gtkrc and theme files actually work
        dbg("activating GTK bug workaround for gtkrc files")
        for o in builder.get_objects():
            if isinstance(o, gtk.Widget):
                # retrieving the name works only for GtkBuilder files, not for
                # libglade files, so be cautious about it
                name = gtk.Buildable.get_name(o)
                if name: o.set_name(name)

    if opts.gtk_rc:
        dbg("**** GLADE VCP INFO: %s reading gtkrc file '%s'" %
            (opts.component, opts.gtk_rc))
        gtk.rc_add_default_file(opts.gtk_rc)
        gtk.rc_parse(opts.gtk_rc)

    if opts.theme:
        dbg("**** GLADE VCP INFO:    Switching %s to '%s' theme" %
            (opts.component, opts.theme))
        settings = gtk.settings_get_default()
        settings.set_string_property("gtk-theme-name", opts.theme, "")
    # This needs to be done after geometry moves so on dual screens the window maxumizes to the actual used screen size.
    if opts.maximum:
        window.window.maximize()

    if opts.halfile:
        cmd = ["halcmd", "-f", opts.halfile]
        res = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr)
        if res:
            print >> sys.stderr, "'%s' exited with %d" % (' '.join(cmd), res)
            sys.exit(res)

    # User components are set up so report that we are ready
    halcomp.ready()

    if handlers.has_key(signal_func):
        dbg("Register callback '%s' for SIGINT and SIGTERM" % (signal_func))
        signal.signal(signal.SIGTERM, handlers[signal_func])
        signal.signal(signal.SIGINT, handlers[signal_func])

    try:
        gtk.main()
    except KeyboardInterrupt:
        sys.exit(0)
    finally:
        halcomp.exit()

    if opts.parent:
        gtk.gdk.flush()
        error = gtk.gdk.error_trap_pop()
        if error:
            print "**** GLADE VCP ERROR:    X Protocol Error: %s" % str(error)
def handle_runroot(options, session, args):
    "[admin] Run a command in a buildroot"
    usage = _("usage: %prog runroot [options] <tag> <arch> <command>")
    usage += _(
        "\n(Specify the --help global option for a list of other help options)"
    )
    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()
    parser.add_option("-p",
                      "--package",
                      action="append",
                      default=[],
                      help=_("make sure this package is in the chroot"))
    parser.add_option("-m",
                      "--mount",
                      action="append",
                      default=[],
                      help=_("mount this directory read-write in the chroot"))
    parser.add_option("--skip-setarch",
                      action="store_true",
                      default=False,
                      help=_("bypass normal setarch in the chroot"))
    parser.add_option("-w", "--weight", type='int', help=_("set task weight"))
    parser.add_option("--channel-override",
                      help=_("use a non-standard channel"))
    parser.add_option("--task-id",
                      action="store_true",
                      default=False,
                      help=_("Print the ID of the runroot task"))
    parser.add_option(
        "--use-shell",
        action="store_true",
        default=False,
        help=_("Run command through a shell, otherwise uses exec"))
    parser.add_option(
        "--new-chroot",
        action="store_true",
        default=None,
        help=_(
            "Run command with the --new-chroot (systemd-nspawn) option to mock"
        ))
    parser.add_option(
        "--old-chroot",
        action="store_false",
        default=None,
        dest='new_chroot',
        help=_(
            "Run command with the --old-chroot (systemd-nspawn) option to mock"
        ))
    parser.add_option("--repo-id", type="int", help=_("ID of the repo to use"))
    parser.add_option("--nowait",
                      action="store_false",
                      dest="wait",
                      default=True,
                      help=_("Do not wait on task"))
    parser.add_option("--watch",
                      action="store_true",
                      help=_("Watch task instead of printing runroot.log"))
    parser.add_option("--quiet",
                      action="store_true",
                      default=options.quiet,
                      help=_("Do not print the task information"))

    (opts, args) = parser.parse_args(args)

    if len(args) < 3:
        parser.error(_("Incorrect number of arguments"))
        assert False  # pragma: no cover

    activate_session(session, options)
    tag = args[0]
    arch = args[1]
    if opts.use_shell:
        # everything must be correctly quoted
        command = ' '.join(args[2:])
    else:
        command = args[2:]
    try:
        kwargs = {
            'channel': opts.channel_override,
            'packages': opts.package,
            'mounts': opts.mount,
            'repo_id': opts.repo_id,
            'skip_setarch': opts.skip_setarch,
            'weight': opts.weight
        }
        # Only pass this kwarg if it is true - this prevents confusing older
        # builders with a different function signature
        if opts.new_chroot is not None:
            kwargs['new_chroot'] = opts.new_chroot

        task_id = session.runroot(tag, arch, command, **kwargs)
    except koji.GenericError as e:
        if 'Invalid method' in str(e):
            print("* The runroot plugin appears to not be installed on the"
                  " koji hub.  Please contact the administrator.")
        raise
    if opts.task_id:
        print(task_id)

    if not opts.wait:
        return

    if opts.watch:
        session.logout()
        return watch_tasks(session, [task_id],
                           quiet=opts.quiet,
                           poll_interval=options.poll_interval)

    try:
        while True:
            # wait for the task to finish
            if session.taskFinished(task_id):
                break
            time.sleep(options.poll_interval)
    except KeyboardInterrupt:
        # this is probably the right thing to do here
        print("User interrupt: canceling runroot task")
        session.cancelTask(task_id)
        raise
    sys.stdout.flush()
    if not opts.quiet:
        output = list_task_output_all_volumes(session, task_id)
        if 'runroot.log' in output:
            for volume in output['runroot.log']:
                log = session.downloadTaskOutput(task_id,
                                                 'runroot.log',
                                                 volume=volume)
                # runroot output, while normally text, can be *anything*, so
                # treat it as binary
                bytes_to_stdout(log)
    info = session.getTaskInfo(task_id)
    if info is None:
        sys.exit(1)
    state = koji.TASK_STATES[info['state']]
    if state in ('FAILED', 'CANCELED'):
        sys.exit(1)
    import os
    try:
        command = os.environ['SSH_ORIGINAL_COMMAND']
    except:
        sys.stderr.write(
            'account restricted: only non-interactive access allowed\n')
        sys.exit(-1)

    tokens = command.split()
    if 'scp' != tokens[0]:
        sys.stderr.write('account restricted: only scp is allowed\n')
        sys.exit(-2)

    scpParser = OptionParser(usage='scp [-pv] -t file', version='%prog')
    scpParser.disable_interspersed_args()
    scpParser.add_option('-p',
                         dest='PRESERVE',
                         action='store_true',
                         default=False)
    scpParser.add_option('-t',
                         dest='TRANSFER',
                         action='store_true',
                         default=False)
    scpParser.add_option('-v',
                         dest='VERBOSE',
                         action='store_true',
                         default=False)
    scpParser.error = new.instancemethod(suppress_error, scpParser,
                                         scpParser.__class__)
    try:
Beispiel #60
0
def main():
    """
    Main CLI handler.
    """

    default_title = "syrupy_" + pretty_timestamp(style=1)

    parser = OptionParser(usage=_program_usage,
            add_help_option=True,
            version=_program_version,
            description=_program_description)

    parser.add_option('-q', '--quiet',
            action='store_true',
            dest='quiet',
            default=False,
            help='do not report miscellaneous run information to stderr')

    parser.add_option('-r', '--replace',
            action='store_true',
            dest='replace',
            default=False,
            help='replace output file(s) without asking if already exists')

    parser.add_option('-t', '--title',
            action='store',
            dest='title',
            metavar="PROCESS-TITLE",
            default=default_title,
            help="name for this run (will be used as prefix for all output files); defaults to 'syrupy_<TIMESTAMP>'")

    parser.add_option('-v', '--debug-level',
            action='store',
            type='int',
            dest='debug',
            metavar="#",
            default=0,
            help='debugging information level (0, 1, 2, 3; default=%default)')

    parser.add_option('--explain',
            action='store_true',
            dest='explain',
            default=False,
            help='show detailed information on the meaning of each of the columns, ' \
                +'and then exit')

    process_opts = OptionGroup(parser, 'Process Selection', """\
By default, Syrupy tracks the process resulting from executing
COMMAND. You can also instruct Syrupy to track external
processes by using the following options, each of which specify
a criteria that a particular process must meet so as to be
monitored. Syrupy will report the resource usage of any and all
processes that meet the specified criteria, and will exit when
no processes matching all the criteria are found. If no
processes matching all the criteria are actually already running
when Syrupy starts, then Syrupy exits immediately. Note that an
instance of Syrupy automatically excludes its own process from
being tracked by itself.
        """
        )
    parser.add_option_group(process_opts)

    process_opts.add_option('-p', '--poll-pid', '--pid',
            action='store',
            dest='poll_pid',
            default=None,
            metavar='PID',
            type=int,
            help='ignore COMMAND if given, and poll external process with ' \
                +'specified PID')

    process_opts.add_option('-m', '--poll-top-memory', '--mem',
            action='store',
            dest='poll_mem',
            default=None,
            metavar='MEM',
            type=int,
            help='ignore COMMAND if given and poll top MEM processes by memory usage')

    process_opts.add_option('-c', '--poll-command',
            action='store',
            dest='poll_command',
            default=None,
            metavar='REG-EXP',
            help='ignore COMMAND if given, and poll external process with ' \
                +'command matching specified regular expression pattern')

    polling_opts = OptionGroup(parser, 'Polling Regime')
    parser.add_option_group(polling_opts)

    polling_opts.add_option('-i', '--interval',
            action='store',
            dest='poll_interval',
            default=1,
            metavar='#.##',
            type=float,
            help='polling interval in seconds (default=%default)')

    run_output_opts = OptionGroup(parser, 'Output Modes', """\
By default, Syrupy redirects the standard output and standard error of COMMAND, as well
as its own output, to log files. The following options allow you to change this behavior, either
having Syrupy write to standard output and standard error ('-S'), COMMAND write to
standard output and standard error ('-C'), or suppress all COMMAND output altogether ('-N').
        """
        )
    parser.add_option_group(run_output_opts)

    run_output_opts.add_option('-S', '--syrupy-in-front',
            action='store_true',
            dest='syrupy_in_front',
            default=False,
            help='redirect Syrupy output and miscellaneous information to ' \
                +'standard output and standard error instead of logging to files')

    run_output_opts.add_option('-C', '--command-in-front',
            action='store_true',
            dest='command_in_front',
            default=False,
            help='run COMMAND in foreground: send output and error stream of' \
                +' COMMAND to standard output and standard error, respectively')

    run_output_opts.add_option('-N', '--no-command-output',
            action='store_true',
            dest='suppress_command_output',
            default=False,
            help='suppress all output from COMMAND')

    run_output_opts.add_option('--flush-output',
            action='store_true',
            dest='flush_output',
            default=False,
            help='force flushing of stream buffers after every write')

    run_output_opts.add_option('--no-raw-process-log',
            action='store_true',
            dest='suppress_raw_process_log',
            default=False,
            help='suppress writing of raw results from process sampling')

    formatting_opts = OptionGroup(parser, 'Output Formatting')
    parser.add_option_group(formatting_opts)

    formatting_opts.add_option('--show-command',
            action='store_true',
            dest='show_command',
            default=False,
            help='show command column in output' )

    formatting_opts.add_option('--separator',
            action='store',
            dest='separator',
            default="  ",
            metavar="SEPARATOR",
            help='character(s) to used to separate columns in results' )

    formatting_opts.add_option('--no-align',
            action='store_false',
            dest='align',
            default=True,
            help='do not align/justify columns' )

    formatting_opts.add_option('--no-headers',
            action='store_false',
            dest='headers',
            default=True,
            help='do not output column headers' )

    # we need to do this to prevent options meant for COMMAND
    # being consumed by Syrupy
    parser.disable_interspersed_args()
    (opts, args) = parser.parse_args()

    if opts.explain:
        sys.stdout.write(column_help())
        sys.stdout.write("\n")
        sys.exit(0)

    if len(args) == 0 \
        and opts.poll_pid is None \
        and opts.poll_command is None \
        and opts.poll_mem is None:
        parser.print_usage()
        sys.exit(1)

    if opts.title is None and len(args) > 0:
        base_title = os.path.splitext(os.path.basename(args[0]))[0]
    else:
        base_title = opts.title

    if opts.syrupy_in_front:
        syrupy_output = sys.stdout
    else:
        fname = base_title + ".ps.log"
        if not opts.quiet:
            sys.stderr.write("SYRUPY: Writing process resource usage samples to '%s'\n" % fname)
        syrupy_output = open_file(fname, "w", replace=opts.replace)

    if opts.suppress_raw_process_log:
        raw_ps_log = None
    else:
        fname = base_title + ".ps.raw"
        if not opts.quiet:
            sys.stderr.write("SYRUPY: Writing raw process resource usage logs to '%s'\n" % fname)
        raw_ps_log = open_file(base_title + ".ps.raw", "w", replace=opts.replace)

    if opts.poll_pid is not None or opts.poll_command is not None or opts.poll_mem is not None:
        if not opts.quiet:
            if opts.poll_pid is not None:
                sys.stderr.write("SYRUPY: sampling process %d\n" % opts.poll_pid)
            elif opts.poll_mem is not None:
                sys.stderr.write("SYRUPY: sampling top %d processes by memory usage\n" % opts.poll_mem)
            else:
                sys.stderr.write("SYRUPY: sampling process with command pattern '%s'\n" % opts.poll_command)
        profile_process(pid=opts.poll_pid,
                command_pattern=opts.poll_command,
                top_mem=opts.poll_mem,
                syrupy_output=syrupy_output,
                raw_ps_log=raw_ps_log,
                poll_interval=opts.poll_interval,
                quit_poll_func=None,
                quit_if_none=True if opts.poll_pid else False,
                quit_at_time=None,
                show_command=opts.show_command,
                output_separator=opts.separator,
                align=opts.align,
                headers=opts.headers,
                flush_output=opts.flush_output,
                debug_level=opts.debug)
    else:
        command = args
        if not opts.quiet:
            sys.stderr.write("SYRUPY: Executing command '%s'\n" % (" ".join(command)))
        if opts.suppress_command_output:
            command_stdout = open(os.devnull, "w")
            command_stderr = open(os.devnull, "w")
            if not opts.quiet:
                sys.stderr.write("SYRUPY: Suppressing output of command\n")
        elif opts.command_in_front:
            command_stdout = sys.stdout
            command_stderr = sys.stderr
        else:
            cout = base_title + ".out.log"
            cerr = base_title + ".err.log"
            if not opts.quiet:
                sys.stderr.write("SYRUPY: Redirecting command output stream to '%s'\n" % cout)
            command_stdout = open_file(cout, 'w', replace=opts.replace)
            if not opts.quiet:
                sys.stderr.write("SYRUPY: Redirecting command error stream to '%s'\n" % cerr)
            command_stderr = open_file(cerr, 'w', replace=opts.replace)
        start_time, end_time = profile_command(command=command,
                command_stdout=command_stdout,
                command_stderr=command_stderr,
                syrupy_output=syrupy_output,
                raw_ps_log=raw_ps_log,
                poll_interval=opts.poll_interval,
                show_command=opts.show_command,
                output_separator=opts.separator,
                align=opts.align,
                headers=opts.headers,
                flush_output=opts.flush_output,
                debug_level=opts.debug)

        if not opts.quiet:
                final_run_report = []
                final_run_report.append("SYRUPY: Completed running: %s" % (" ".join(command)))
                final_run_report.append("SYRUPY: Started at %s" % (start_time.isoformat(' ')))
                final_run_report.append("SYRUPY: Ended at %s" % (end_time.isoformat(' ')))
                hours, mins, secs = str(end_time-start_time).split(":")
                run_time = "SYRUPY: Total run time: %s hour(s), %s minute(s), %s second(s)" % (hours, mins, secs)
                final_run_report.append(run_time)
                report = "\n".join(final_run_report) + "\n"
                sys.stderr.write(report)