def add(self, items, tmpl_vals=None, allow_spaces=True): """ Add options/arguments to command :param item: option/argument to add to command :param tmpl_vals: template values for item """ if not isinstance(items, (list, tuple)): items = [items] for item in items: if tmpl_vals: item = item % tmpl_vals if not is_string(item): raise ValueError( "Non-string item %s (type %s) being added to command %s" % (item, type(item), self)) if not allow_spaces and ' ' in item: raise ValueError( "Found one or more spaces in item '%s' being added to command %s" % (item, self)) super(CmdList, self).append(item)
def _make_shell_command(self): """Convert cmd into a list of command to be sent to popen, without a shell""" if self.cmd is None: self.log.raiseException("_make_shell_command: no cmd set.") if is_string(self.cmd): self._shellcmd = shlex.split(self.cmd) elif isinstance(self.cmd, (list, tuple,)): self._shellcmd = self.cmd else: self.log.raiseException("Failed to convert cmd %s (type %s) into non shell command" % (self.cmd, type(self.cmd)))
def _make_shell_command(self): """Convert cmd into shell command""" self.log.warning("using potentialy unsafe shell commands, use run.run or run.RunNoShell.run \ instead of run.run_simple or run.Run.run") if self.cmd is None: self.log.raiseException("_make_shell_command: no cmd set.") if is_string(self.cmd): self._shellcmd = self.cmd elif isinstance(self.cmd, (list, tuple,)): self._shellcmd = " ".join([str(arg).replace(' ', '\ ') for arg in self.cmd]) else: self.log.raiseException("Failed to convert cmd %s (type %s) into shell command" % (self.cmd, type(self.cmd)))
def process_answers(answers): """Construct list of newline-terminated answers (as strings).""" if is_string(answers): answers = [answers] elif isinstance(answers, list): # list is manipulated when answering matching question, so take a copy answers = answers[:] else: msg_tmpl = "Invalid type for answer, not a string or list: %s (%s)" self.log.raiseException(msg_tmpl % (type(answers), answers), exception=TypeError) # add optional split at the end if self.add_newline: for i in [idx for idx, a in enumerate(answers) if not a.endswith('\n')]: answers[i] += '\n' return answers
def _make_shell_command(self): """Convert cmd into a list of command to be sent to popen, without a shell""" if self.cmd is None: self.log.raiseException("_make_shell_command: no cmd set.") if is_string(self.cmd): self._shellcmd = shlex.split(self.cmd) elif isinstance(self.cmd, ( list, tuple, )): self._shellcmd = self.cmd else: self.log.raiseException( "Failed to convert cmd %s (type %s) into non shell command" % (self.cmd, type(self.cmd)))
def process_answers(answers): """Construct list of newline-terminated answers (as strings).""" if is_string(answers): answers = [answers] elif isinstance(answers, list): # list is manipulated when answering matching question, so take a copy answers = answers[:] else: msg_tmpl = "Invalid type for answer, not a string or list: %s (%s)" self.log.raiseException(msg_tmpl % (type(answers), answers), exception=TypeError) # add optional split at the end if self.add_newline: for i in [ idx for idx, a in enumerate(answers) if not a.endswith('\n') ]: answers[i] += '\n' return answers
def _make_shell_command(self): """Convert cmd into shell command""" self.log.warning( "using potentialy unsafe shell commands, use run.run or run.RunNoShell.run \ instead of run.run_simple or run.Run.run") if self.cmd is None: self.log.raiseException("_make_shell_command: no cmd set.") if is_string(self.cmd): self._shellcmd = self.cmd elif isinstance(self.cmd, ( list, tuple, )): self._shellcmd = " ".join( [str(arg).replace(' ', '\ ') for arg in self.cmd]) else: self.log.raiseException( "Failed to convert cmd %s (type %s) into shell command" % (self.cmd, type(self.cmd)))
def add(self, items, tmpl_vals=None, allow_spaces=True): """ Add options/arguments to command :param item: option/argument to add to command :param tmpl_vals: template values for item """ if not isinstance(items, (list, tuple)): items = [items] for item in items: if tmpl_vals: item = item % tmpl_vals if not is_string(item): raise ValueError("Non-string item %s (type %s) being added to command %s" % (item, type(item), self)) if not allow_spaces and ' ' in item: raise ValueError("Found one or more spaces in item '%s' being added to command %s" % (item, self)) super(CmdList, self).append(item)