Run the iotile-emulate script.

    Args:
        raw_args (list): Optional list of commmand line arguments.  If not
            passed these are pulled from sys.argv.
973976
def main(raw_args=None):
    

    if raw_args is None:
        raw_args = sys.argv[1:]

    parser = build_parser()
    args = parser.parse_args(raw_args)

    if args.firmware_image is None and args.gdb is None:
        print("You must specify either a firmware image or attach a debugger with --gdb <PORT>")
        return 1

    test_args = ['qemu-system-gnuarmeclipse', '-verbose', '-verbose', '-board', 'STM32F0-Discovery',
                 '-nographic', '-monitor', 'null', '-serial', 'null', '--semihosting-config',
                 'enable=on,target=native', '-d', 'unimp,guest_errors']

    if args.firmware_image:
        test_args += ['-image', args.firmware_image]

    if args.gdb:
        test_args += ['--gdb', 'tcp::%d' % args.gdb]

    proc = subprocess.Popen(test_args, stdout=sys.stdout, stderr=sys.stderr)

    try:
        proc.communicate()
    except KeyboardInterrupt:
        proc.terminate()

    return 0
905882
def _run(method, cmd, cwd=None, shell=True, universal_newlines=True,
             stderr=STDOUT):
        """"""
        if not cmd:
            error_msg = 'Passed empty text or list'
            raise AttributeError(error_msg)
        if isinstance(cmd, six.string_types):
            cmd = str(cmd)
        if shell:
            if isinstance(cmd, list):
                cmd = ' '.join(cmd)
        else:
            if isinstance(cmd, str):
                cmd = cmd.strip().split()
        out = method(cmd, shell=shell, cwd=cwd, stderr=stderr,
                     universal_newlines=universal_newlines)
        if isinstance(out, bytes):
            out = out.decode('utf-8')
        return str(out).strip()
557925
def run_from_argv(self, argv):
        
        if (len(argv) > 2 and not argv[2].startswith('-') and
                argv[2] in self.subcommands.keys()):
            subcommand = argv[2]
            klass = self.get_subcommand(subcommand)
            parser = OptionParser(
                prog=argv[0],
                usage=klass.usage('{0} {1}'.format(argv[1], subcommand)),
                version=klass.get_version(), option_list=klass.option_list)
            options, args = parser.parse_args(argv[3:])
            args = [subcommand] + args
        else:
            parser = self.create_parser(argv[0], argv[1])
            options, args = parser.parse_args(argv[2:])

        handle_default_options(options)
        self.execute(*args, **options.__dict__)
715838
def do_python(self, arg):
        
        if self.cmdprefix:
            raise CmdError("prefix not allowed")

        # When given a Python statement, execute it directly.
        if arg:
            try:
                compat.exec_(arg, globals(), locals())
            except Exception:
                traceback.print_exc()

        # When no statement is given, spawn a Python interpreter.
        else:
            try:
                self._spawn_python_shell(arg)
            except Exception:
                e = sys.exc_info()[1]
                raise CmdError(
                    "unhandled exception when running Python console: %s" % e)
179792
def set_raw(self, *args):
        
        if not self.enabled: return
        args = map(lambda x: str(x), [x for x in args if x is not None])
        self._write_raw(';'.join(args) + 'm')
878466
def run(args = ARGV)
      opts.parse!(args)

      if !analyze_gemfile? && args.empty?
        puts opts.parser
        exit 1
      end

      print_requires(options, args)
    end
1033196
def run_args(args):
    
    return main(filename      = args.get('MDFILE')
               ,theme         = args.get('-t', 'random')
               ,cols          = args.get('-c')
               ,from_txt      = args.get('-f')
               ,c_theme       = args.get('-T')
               ,c_no_guess    = args.get('-x')
               ,do_html       = args.get('-H')
               ,no_colors     = args.get('-A')
               ,display_links = args.get('-L'))
897701
def run_from_argv(self, argv):
        
        parser = self.create_parser(argv[0], argv[1])
        args = parser.parse_args(argv[2:])
        handle_default_options(args)
        try:
            self.execute(args)
        except Exception as e:
            # self.stderr is not guaranteed to be set here
            try:
                fallback_stderr = OutputWrapper(sys.stderr, self.style.ERROR)
            except:
                fallback_stderr = self.stdout
            stderr = getattr(self, 'stderr', fallback_stderr)
            if args.traceback:
                stderr.write(traceback.format_exc())
            else:
                stderr.write('%s: %s' % (e.__class__.__name__, e))
            sys.exit(1)
302726
def _RunScript(self, script):
    
    process = subprocess.Popen(
        script, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
    while True:
      for line in iter(process.stdout.readline, b''):
        self.logger.info(line.decode('utf-8').rstrip('\n'))
      if process.poll() is not None:
        break
470858
def shell(script=None, args=()):
    
    if script:
        sys.argv = sys.argv[2:]  # strip ['oq', 'shell']
        runpy.run_path(script, run_name='__main__')
        return
    o = OpenQuake()  # noqa
    try:
        import IPython
        IPython.embed(banner1='IPython shell with a global object "o"')
    except ImportError:
        import code
        code.interact(banner='Python shell with a global object "o"',
                      local=dict(o=o))
745571
def _run_argparser(self, argv):
        
        if self._parser is None:
            raise ValueError('Link was not given a parser on initialization')
        args = self._parser.parse_args(argv)
        self.update_args(args.__dict__)
        return args
454660
def convert_the_args(raw_args):
    
    if not raw_args:
        return ""
    if isinstance(raw_args,dict):
        out_args = ", ".join([ "{}={}".format(k,v) for k,v in raw_args.iteritems() ])
        
    elif isinstance(raw_args,(list,tuple)):
        new_list = []
        for x in raw_args:
            if isinstance(x,basestring):
                new_list.append(x)
            elif isinstance(x,dict):
                new_list.append( ", ".join([ "{}={}".format(k,v) for k,v in x.iteritems() ]) )
            else:
                raise ValueError("Error preparing the getters")
        out_args = ", ".join(new_list)
    else:
        raise ValueError("Couldn't recognize list of getters")
    return out_args
484348
def run_from_argv(self, argv):
        
        option = '--testrunner='
        for arg in argv[2:]:
            if arg.startswith(option):
                self.test_runner = arg[len(option):]
                break
        super(Command, self).run_from_argv(argv)
390661
def run(self, args):
        

        # run a subprocess and put the stdout and stderr on the pipe object
        try:
            pipe = subprocess.Popen(
                args,
                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            )
        except OSError as e:
            if e.errno == errno.ENOENT:
                # File not found.
                # This is equivalent to getting exitcode 127 from sh
                raise exceptions.ShellError(
                    ' '.join(args), 127, '', '',
                )

        # pipe.wait() ends up hanging on large files. using
        # pipe.communicate appears to avoid this issue
        stdout, stderr = pipe.communicate()

        # if pipe is busted, raise an error (unlike Fabric)
        if pipe.returncode != 0:
            raise exceptions.ShellError(
                ' '.join(args), pipe.returncode, stdout, stderr,
            )

        return stdout, stderr
197125
def run(self, args=None):
        

        args = args or self.parser.parse_args()

        if args.debug:
            logging.basicConfig(level=logging.DEBUG)

        if args.version:
            print(version.VERSION)
            sys.exit(0)
678553
def _run(passedArgs=None, stderr=None, stdout=None, exitFn=None):
    

    description = """Finds the next available file-name in a sequence.

    This program will create a file of zero size and will output the path to it
    on STDOUT. No files which exist will be altered in this operation and
    concurrent invocations of this program will return separate files. In case
    of conflict, this program will attempt to generate a new file name up to
    'maxattempts' number of times before failing. (See --max-attempts)

    The sequence will start from the base argument (See --base, default: 0).

    This program will look for the next file in the sequence ignoring any gaps.
    Hence, if the files "a.0.txt" and "a.3.txt" exist, then the next file
    returned will be "a.4.txt" when called with prefix="a." and suffix=".txt".

    Returns:
        Path of the file which follows the provided pattern and can be opened
        for writing.

        Otherwise, it prints an error (wrong path, drive full, illegal
        character in filename, etc.) to stderr and exits with a non-zero error
        code.
    """

    argParser = _argparse.ArgumentParser(
            description=description,
            formatter_class=_argparse.RawTextHelpFormatter)

    argParser.add_argument('prefix',
                           help='Prefix for the sequence of files.')
    argParser.add_argument('suffix',
                           help='Suffix for the sequence of files.',
                           nargs='?',
                           default='')
    argParser.add_argument('folder',
                           help='The folder where the file will be created.',
                           nargs='?',
                           default=_os.getcwd())
    argParser.add_argument('-m', '--max-attempts',
                           help='Number of attempts to make before giving up.',
                           default=10)
    argParser.add_argument('-b', '--base',
                           help='From where to start counting (default: 0).',
                           default=0)

    passedArgs = passedArgs if passedArgs is not None else _sys.argv[1:]
    args = argParser.parse_args(passedArgs)

    stdout = _sys.stdout if stdout is None else stdout
    stderr = _sys.stderr if stderr is None else stderr

    try:
        nextFile = findNextFile(args.folder, prefix=args.prefix,
                                suffix=args.suffix,
                                maxattempts=args.max_attempts,
                                base=args.base)
        # The newline will be converted to the correct platform specific line
        # ending as `sys.stdout` is opened in non-binary mode.
        # Hence, we do not need to explicitly print out `\r\n` for Windows.
        stdout.write(nextFile + u'\n')
    except OSError as e:
        stderr.write(_os.strerror(e.errno) + u'\n')
        _sys.exit(e.errno)
973339
def main(argv=None):
    """"""
    parser = argparse.ArgumentParser(description="Parser benchmark")

    parser.add_argument("--debug", default=False, action="store_true", help="Enable debugging")
    parser.add_argument("--repetitions", type=int, default=10, help="Number of repetitions")
    parser.add_argument("--line-count", type=int, default=5000, help="Number of lines to parse")

    args = parser.parse_args(argv)
    run(args)