Takes a list of arguments appropriate for run_command or
 preview_command and returns: [cmd, args].
 Single character symbols with be converted to command line
 switches. Example:   +:l+ becomes +-l+
431530
def prep_args(*args)
      args = args.flatten.compact
      args = args.first.to_s.split(/\s+/) if args.size == 1
      cmd = sudo? ? :sudo : args.shift
      
      # Symbols to switches. :l -> -l, :help -> --help
      args.collect! do |a|
        if a.is_a?(Symbol)
          a = (a.to_s.size == 1) ? "-#{a}" : a.to_s
        end
        a
      end
      [cmd, args]
    end
871444
def _run_command(self, commands):
        
        all_commands = {
            # Open vSwitch commands.
            'init': (None, self._cmd_init),
            'show': (self._pre_cmd_show, self._cmd_show),
            # 'emer-reset':

            # Bridge commands.
            'add-br': (self._pre_add_br, self._cmd_add_br),
            'del-br': (self._pre_get_info, self._cmd_del_br),
            'list-br': (self._pre_get_info, self._cmd_list_br),
            'br-exists': (self._pre_get_info, self._cmd_br_exists),
            'br-to-vlan': (self._pre_get_info, self._cmd_br_to_vlan),
            'br-to-parent': (self._pre_get_info, self._cmd_br_to_parent),
            'br-set-external-id': (self._pre_cmd_br_set_external_id,
                                   self._cmd_br_set_external_id),
            'br-get-external-id': (self._pre_cmd_br_get_external_id,
                                   self._cmd_br_get_external_id),

            # Port. commands
            'list-ports': (self._pre_get_info, self._cmd_list_ports),
            'add-port': (self._pre_cmd_add_port, self._cmd_add_port),
            'add-bond': (self._pre_cmd_add_bond, self._cmd_add_bond),
            'del-port': (self._pre_get_info, self._cmd_del_port),
            'port-to-br': (self._pre_get_info, self._cmd_port_to_br),

            # Interface commands.
            'list-ifaces': (self._pre_get_info, self._cmd_list_ifaces),
            'iface-to-br': (self._pre_get_info, self._cmd_iface_to_br),

            # Controller commands.
            'get-controller': (self._pre_controller, self._cmd_get_controller),
            'del-controller': (self._pre_controller, self._cmd_del_controller),
            'set-controller': (self._pre_controller, self._cmd_set_controller),
            'get-fail-mode': (self._pre_fail_mode, self._cmd_get_fail_mode),
            'del-fail-mode': (self._pre_fail_mode, self._cmd_del_fail_mode),
            'set-fail-mode': (self._pre_fail_mode, self._cmd_set_fail_mode),

            # Manager commands.
            # 'get-manager':
            # 'del-manager':
            # 'set-manager':

            # SSL commands.
            # 'get-ssl':
            # 'del-ssl':
            # 'set-ssl':

            # Auto Attach commands.
            # 'add-aa-mapping':
            # 'del-aa-mapping':
            # 'get-aa-mapping':

            # Switch commands.
            # 'emer-reset':

            # Database commands.
            'list': (self._pre_cmd_list, self._cmd_list),
            'find': (self._pre_cmd_find, self._cmd_find),
            'get': (self._pre_cmd_get, self._cmd_get),
            'set': (self._pre_cmd_set, self._cmd_set),
            'add': (self._pre_cmd_add, self._cmd_add),
            'remove': (self._pre_cmd_remove, self._cmd_remove),
            'clear': (self._pre_cmd_clear, self._cmd_clear),
            # 'create':
            # 'destroy':
            # 'wait-until':

            # Utility commands. (No corresponding command in ovs-vsctl)
            'set-qos': (self._pre_cmd_set_qos, self._cmd_set_qos),
            'set-queue': (self._pre_cmd_set_queue, self._cmd_set_queue),
            'del-qos': (self._pre_get_info, self._cmd_del_qos),
            # for quantum_adapter
            'list-ifaces-verbose': (self._pre_cmd_list_ifaces_verbose,
                                    self._cmd_list_ifaces_verbose),
        }

        for command in commands:
            funcs = all_commands[command.command]
            command._prerequisite, command._run = funcs
        self._do_main(commands)
565281
def get_command_str(args):
    
    single_quote = "'"
    double_quote = '"'
    for i, value in enumerate(args):
        if " " in value and double_quote not in value:
            args[i] = '"%s"' % value
        elif " " in value and single_quote not in value:
            args[i] = "'%s'" % value
    return " ".join(args)
958131
def get_command_and_args(self):
        
        """

        # First protect
        p_call = self.call.replace(r'\!', '___PROTECT_EXCLAMATION___')
        tab = p_call.split('!')
        return tab[0].strip(), [s.replace('___PROTECT_EXCLAMATION___', '!') for s in tab[1:]]
1197244
def run_local(self, commands):
        
        process = subprocess.Popen(
            commands.get('cli_command'),
            shell=self.shell,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )

        out, err = process.communicate()

        # display app output
        self.run_display_app_output(out)
        self.run_display_app_errors(err)

        # Exit Code
        return self.run_exit_code(process.returncode)
1308452
def run_command(cmd):
    '''
    '''
    output = Popen(cmd,stderr=STDOUT,stdout=PIPE)
    t = output.communicate()[0],output.returncode
    output = {'message':t[0],
              'return_code':t[1]}

    return output
390316
def cmdline(executable):
    

    args = [executable.executable]
    indexed_args = []

    for parameter in executable:

        optional = (parameter.type == 'boolean') or parameter.default
        has_value = parameter.type != 'boolean'


        if parameter.longflag:  # use longflag where possible
            flag = "--%s" % parameter.longflag
        elif parameter.flag:
            flag = "-%s VALUE" % parameter.flag
        elif parameter.index:
            flag = parameter.name
            optional = False


        if has_value:
            flag += " VALUE"

        if optional:
            flag = "[" + flag + "]"

        if parameter.index:
            indexed_args.insert(int(parameter.index), flag)
        else:
            args.append(flag)

    return args + indexed_args
591907
def runCommandReturnOutput(cmd):
    
    splits = shlex.split(cmd)
    proc = subprocess.Popen(
        splits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate()
    if proc.returncode != 0:
        raise subprocess.CalledProcessError(stdout, stderr)
    return stdout, stderr
975124
def argument_run(self, sp_r):
		
		arg_run = []

		for line in sp_r:
			logging.debug("argument run: handling: " + str(line))
			if(line[1] == "data"):
				arg_run.append( (line[0], line[1], line[2], line[2].get_words(line[3])))
				continue
			if(line[1] == "command"):
				self.checkargs(line[0], line[2], line[3])
				arg_run.append( (line[0], line[1], line[2], [a for a in self.convert_args(line[2], line[3])]))
		return arg_run
1233510
def get_command(arguments):
    
    cmds = list(filter(lambda k: not (k.startswith('-') or
                                 k.startswith('<')) and arguments[k],
                  arguments.keys()))
    if len(cmds) != 1:
        raise Exception('invalid command line!')
    return cmds[0]
934054
def run (cmd, verbosity=0, **kwargs):
    """"""
    # Note that shell_quote_nt() result is not suitable for copy-paste
    # (especially on Unix systems), but it looks nicer than shell_quote().
    if verbosity >= 0:
        log_info("running %s" % " ".join(map(shell_quote_nt, cmd)))
    if kwargs:
        if verbosity >= 0:
            log_info("    with %s" % ", ".join("%s=%s" % (k, shell_quote(str(v)))\
                                           for k, v in kwargs.items()))
        if kwargs.get("shell"):
            # for shell calls the command must be a string
            cmd = " ".join(cmd)
    if verbosity < 1:
        # hide command output on stdout
        with open(os.devnull, 'wb') as devnull:
            kwargs['stdout'] = devnull
            res = subprocess.call(cmd, **kwargs)
    else:
        res = subprocess.call(cmd, **kwargs)
    return res
504813
def cmdargv(self):
        '''
        
        '''

        argv = []
        while self.more():

            # cmdargv *requires* whitespace
            if not self.ignore(whitespace):
                break

            # if we hit a | or a } we're done
            if self.nextstr('|'):
                break

            if self.nextstr('}'):
                break

            if not self.nextstr('{'):
                valu = self.cmdvalu()
                argv.append(valu)
                continue

            start = self.offs
            self.subquery()

            text = self.text[start:self.offs]

            argv.append(text)

        return s_ast.Const(tuple(argv))
270669
def cmd_help(*args):
    
    if len(args) == 0:
        print("Possible commands are:")
        print("")
        for cmd_name in sorted(COMMANDS.keys()):
            cmd_func = COMMANDS[cmd_name]
            print("{}:".format(cmd_name))
            print("=" * (len(cmd_name) + 1))
            print("    {}".format(cmd_func.__doc__.strip()))
            print("")
    else:
        cmd_name = args[0]
        cmd_func = COMMANDS[cmd_name]
        print("{}:".format(cmd_name))
        print("=" * (len(cmd_name) + 1))
        print("    {}".format(cmd_func.__doc__.strip()))
1174125
def cmd(self, *args, **kwargs):
        ''''''
        serial = self.device_serial()
        if serial:
            if " " in serial:  # TODO how to include special chars on command line
                serial = "'%s'" % serial
            return self.raw_cmd(*["-s", serial] + list(args))
        else:
            return self.raw_cmd(*args)
576095
def _get_cmd(cmd):
    
    check_cmd = "RunTHetA.py"
    try:
        local_cmd = subprocess.check_output(["which", check_cmd]).strip()
    except subprocess.CalledProcessError:
        return None
    return [sys.executable, "%s/%s" % (os.path.dirname(os.path.realpath(local_cmd)), cmd)]
631981
def cmdline(self, **kwargs):
        

        args = [self.executable]
        indexed_args = []

        for key, value in kwargs.iteritems():
            parameter = self[key]
            if value != parameter.default:
                no_value = parameter.type == 'boolean'

                if parameter.longflag:  # use longflag where possible
                    args.append("--%s" % parameter.longflag)
                    if no_value:
                        args.append(str(value))
                elif parameter.flag:
                    args.append("-%s" % parameter.flag)
                    if no_value:
                        args.append(str(value))
                elif parameter.index:
                    indexed_args.insert(int(parameter.index), str(value))

        return args + indexed_args
222720
def run_command(self, cmd, argv):
        
        try:
            Command = self.get_command_class(cmd)
        except CommandError, e:
            self.stderr.write(str(e) + '\n')
            self.show_help()
            sys.exit(-1)
        command = Command(stdout=self.stdout, stderr=self.stderr)
        command.run_from_argv(argv)