def run_command(self, cmd, conn=None, check_exit_code=True): def _exec_local_command(): if 'ioscli' in cmd: host = CONF.host # self._host @synchronized(host, 'pvm-odm-lock', False) def _run_local_odm_commands(host): cmdin, cmdout, cmderr = None, None, None for odm_retries in range(2): cmdout, cmderr = processutils.execute('su', '-', 'padmin', '-c', *cmd, check_exit_code=check_exit_code) # cmdout, cmderr = processutils.execute('su', '-', 'padmin', check_exit_code=check_exit_code, process_input = cmd) if cmderr: if (any('0514-516' in err for err in cmderr) or any('Please retry the command later' in err for err in cmderr)): if(odm_retries < 2): time.sleep(30) continue return cmdout, cmderr return cmdout, cmderr cmdout, cmderr = _run_local_odm_commands(host) else: cmdout, cmderr = processutils.execute('su', '-', 'padmin' , '-c', *cmd, check_exit_code=check_exit_code) # cmdout, cmderr = processutils.execute('su', '-', 'padmin', check_exit_code=check_exit_code, process_input = cmd) if cmdout is not None: cmdout = cmdout.split('\n') cmdout.pop() if len(cmdout) > 0: return_code = cmdout.pop() if return_code and int(return_code) == 0: return cmdout raise_exception = check_exit_code if raise_exception: ex_args = {'command': ' '.join(cmd), 'error': cmderr, 'stdout': cmdout, 'exit_code': int(return_code)} raise exception.IBMPowerVMCommandFailed(**ex_args) LOG.debug(_("Command: %(cmd)s") % {'cmd': ' '.join(cmd)}) LOG.debug(_("Exit Code: %(exit_code)s") % {'exit_code': int(return_code)}) LOG.debug(_("Stdout: %(out)r") % {'out': cmdout}) LOG.debug(_("Stderr: %(err)r") % {'err': cmderr}) return None # try: # for num_retries in range(2): # if num_retries > 0: # LOG.debug("vios local command retried %(num_retries)s with command " # "%(command)s" % locals()) # if ';echo $?' not in cmd: # cmd += ";echo $?" cmd = cmd.split() cmd.append(';echo') cmd.append('$?') return _exec_local_command()
def parseCommand(self): if not self.getCommand(): return None cmd = [] for e in self.cmd.split(): if e == '2>' or e == '>' or '/dev/null' in e: break cmd.append(e) return ' '.join(cmd)
def parse_command_line(self, st): """returns command the flags set under a command and the arguments""" cmd = [] flags = set() for ic in st.strip().split(): if ic[0] == "-": flags.add( ic.strip("-") ) else: cmd.append( ic ) return flags, cmd
def parse_command_line(self, st): """returns command, the flags set under a command and the arguments""" st = st.strip().split() cmd = [] flags = {} for ic in st: if ic[:2] == "--": st = ic[2:] if "=" in st: k, v = st.split("=") flags[k] = v else: flags[st] = None else: cmd.append(ic) return flags, cmd
def say(self, phrase): self._logger.debug("Saying '%s' with '%s'", phrase, self.SLUG) with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f: fname = f.name cmd = ['pico2wave', '--wave', fname] if self.language not in self.languages: raise ValueError("Language '%s' not supported by '%s'", self.language, self.SLUG) cmd.extend(['-l', self.language]) cmd.append(phrase) self._logger.debug('Executing %s', ' '.join([pipes.quote(arg) for arg in cmd])) with tempfile.TemporaryFile() as f: subprocess.call(cmd, stdout=f, stderr=f) f.seek(0) output = f.read() if output: self._logger.debug("Output was: '%s'", output) self.play(fname) os.remove(fname)
def say(self, phrase): self._logger.debug("Saying '%s' with '%s'", phrase, self.SLUG) cmd = ['flite'] if self.voice: cmd.extend(['-voice', self.voice]) cmd.extend(['-t', phrase]) with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f: fname = f.name cmd.append(fname) with tempfile.SpooledTemporaryFile() as out_f: self._logger.debug('Executing %s', ' '.join([pipes.quote(arg) for arg in cmd])) subprocess.call(cmd, stdout=out_f, stderr=out_f) out_f.seek(0) output = out_f.read().strip() if output: self._logger.debug("Output was: '%s'", output) self.play(fname) os.remove(fname)
def analyzeWebsiteReport(ws_report, log): def countResultFiles(dir): fname = dir + "/processed_urls.csv" try: with open(fname) as f: return len(f.readlines()) return 0 except: error("Error opening: " + fname) return 0 start = time.time() cmd = [] cmd.append(settings.APP_DIR + 'fae2/fae-util/run') cmd.append('-c') cmd.append(ws_report.data_property_file) if len(ws_report.data_authorization_file): cmd.append('-a') cmd.append(ws_report.data_authorization_file) proc = subprocess.call(cmd, stdout=log) page_count = countResultFiles(ws_report.data_directory + '/data') ave_time = "{:10.4f}".format(time.time() - start) + " seconds (0 pages)" if page_count > 0: if page_count == 1: ave_time = "{:10.4f}".format(time.time() - start) + " seconds/page (1 page)" else: ave_time = "{:10.4f}".format( (time.time() - start) / page_count) + " seconds/page (" + str(page_count) + " pages)" info(" Pages analyzed: " + str(page_count)) info('Average processing time per page: ' + ave_time)
def analyzeWebsiteReport(ws_report, log): def countResultFiles(dir): fname = dir + "/processed_urls.csv" try: with open(fname) as f: return len(f.readlines()) return 0 except: error("Error opening: " + fname) return 0 start = time.time() cmd = [] cmd.append(settings.APP_DIR + 'fae2/fae-util/run') cmd.append('-c') cmd.append(ws_report.data_property_file) if len(ws_report.data_authorization_file): cmd.append('-a') cmd.append(ws_report.data_authorization_file) proc = subprocess.call(cmd, stdout=log) page_count = countResultFiles(ws_report.data_directory + '/data') ave_time = "{:10.4f}".format(time.time()-start) + " seconds (0 pages)" if page_count > 0: if page_count == 1: ave_time = "{:10.4f}".format(time.time()-start) + " seconds/page (1 page)" else: ave_time = "{:10.4f}".format((time.time()-start)/page_count) + " seconds/page (" + str(page_count) + " pages)" info(" Pages analyzed: " + str(page_count)) info('Average processing time per page: ' + ave_time)
# # It is enriched by setting JAVA_OPTS for scala d = dict(os.environ) # Add java options (in the command line for java executables and # in JAVA_OPTS env. variable for scala) if args.language == 's' or args.language == 'scala': s = " ".join(map(str, javaOptions)) if verbose: print "Options to pass to the java executable", s d['JAVA_OPTS'] = s else: for opt in javaOptions: if verbose: print "Adding", opt, "java option" cmd.append(opt) # Is the environment ok? # Fail fast! if not CommonDefs.checkEnvironment(): print "Some setting missing in IAS environment." print "Set the environment with ias-bash_profile before running IAS applications" print sys.exit(-1) # Create tmp and logs folders if not exists already FileSupport.createLogsFolder() FileSupport.createTmpFolder() # Add the properties #
# Add the properties # # Default and user defined properties are in a dictionary: # this way it is easy for the user to overrride default properties. props={} setProps(props) if len(props)>0: stingOfPros = formatProps(props) # Sort to enhance readability stingOfPros.sort() cmd.extend(formatProps(props)) #add the classpath cmd.append("-cp") cmd.append(CommonDefs.buildClasspath()) # Add the class cmd.append(args.className) # Finally the command line parameters if len(args.params)>0: cmd.extend(args.params) print print "Going to run:" print cmd print call(cmd)
def run_command(self, name, args): cmd = [os.path.join(self.commands_dir, name)] cmd.append(args) self.cmd.output = subprocess.Popen( cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE).communicate(input=self.cmd.output)[0]