def run(self, script, option=""): PHANTOMJS_NATIVE_ARGS = [ 'cookies-file', 'config', 'debug', 'disk-cache', 'ignore-ssl-errors', 'load-images', 'load-plugins', 'local-storage-path', 'local-storage-quota', 'local-to-remote-url-access', 'max-disk-cache-size', 'output-encoding', 'proxy', 'proxy-auth', 'proxy-type', 'remote-debugger-port', 'remote-debugger-autorun', 'script-encoding', 'web-security', ] CASPER_ARGS = [] CASPER_PATH = os.path.abspath(os.path.join(which('casperjs'), '..')) PHANTOMJS_ARGS = [] SYS_ARGS = option for arg in SYS_ARGS: found = False for native in PHANTOMJS_NATIVE_ARGS: if arg.startswith('--%s' % native): PHANTOMJS_ARGS.append(arg) found = True if not found: CASPER_ARGS.append(arg) CASPER_COMMAND = os.environ.get('PHANTOMJS_EXECUTABLE', 'phantomjs').split(' ') CASPER_COMMAND.extend(PHANTOMJS_ARGS) CASPER_COMMAND.extend([ os.path.join(CASPER_PATH, 'bin', 'bootstrap.js'), '--casper-path=%s' % CASPER_PATH, '--cli' ]) CASPER_COMMAND.extend(CASPER_ARGS) script_path = os.path.dirname(self.resolve(__file__)) script_cmd = os.path.join(script_path, 'js', script) CASPER_COMMAND.extend([script_cmd]) print CASPER_COMMAND[0] print CASPER_COMMAND process = subprocess.Popen(CASPER_COMMAND, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # wait for the process to terminate self.out, self.err = process.communicate() self.errcode = process.returncode return self.out, self.err, self.errcode
def run(self, script, option=""): PHANTOMJS_NATIVE_ARGS = [ "cookies-file", "config", "debug", "disk-cache", "ignore-ssl-errors", "load-images", "load-plugins", "local-storage-path", "local-storage-quota", "local-to-remote-url-access", "max-disk-cache-size", "output-encoding", "proxy", "proxy-auth", "proxy-type", "remote-debugger-port", "remote-debugger-autorun", "script-encoding", "web-security", ] CASPER_ARGS = [] CASPER_PATH = os.path.abspath(os.path.join(which("casperjs"), "..")) PHANTOMJS_ARGS = [] SYS_ARGS = option for arg in SYS_ARGS: found = False for native in PHANTOMJS_NATIVE_ARGS: if arg.startswith("--%s" % native): PHANTOMJS_ARGS.append(arg) found = True if not found: CASPER_ARGS.append(arg) CASPER_COMMAND = os.environ.get("PHANTOMJS_EXECUTABLE", "phantomjs").split(" ") CASPER_COMMAND.extend(PHANTOMJS_ARGS) CASPER_COMMAND.extend( [os.path.join(CASPER_PATH, "bin", "bootstrap.js"), "--casper-path=%s" % CASPER_PATH, "--cli"] ) CASPER_COMMAND.extend(CASPER_ARGS) script_path = os.path.dirname(self.resolve(__file__)) script_cmd = os.path.join(script_path, "js", script) CASPER_COMMAND.extend([script_cmd]) print CASPER_COMMAND[0] print CASPER_COMMAND process = subprocess.Popen(CASPER_COMMAND, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # wait for the process to terminate self.out, self.err = process.communicate() self.errcode = process.returncode return self.out, self.err, self.errcode
def initialize(self, runInfo, oriInputFiles): """ Method to initialize the run of a new step @ In, runInfo, dict, dictionary of the info in the <RunInfo> XML block @ In, oriInputFiles, list, list of the original input files @ Out, None """ import RAVENparser index = self.__findInputFile(oriInputFiles) parser = RAVENparser.RAVENparser(oriInputFiles[index].getAbsFile()) # get the OutStreams names self.outStreamsNamesAndType, self.outDatabases = parser.returnOutputs() # check if the linked DataObjects are among the Outstreams if self.linkedDataObjectOutStreamsNames: pointSetNumber, historySetNumber = 0, 0 for outstream, dataObj in self.outStreamsNamesAndType.items(): if outstream in self.linkedDataObjectOutStreamsNames: if dataObj[1].strip() == 'PointSet': pointSetNumber += 1 else: historySetNumber += 1 if pointSetNumber > 1 or historySetNumber > 1: raise IOError( self.printTag + ' ERROR: Only one OutStream for PointSet and/or one for HistorySet can be linked as output export!' ) if pointSetNumber == 0 and historySetNumber == 0: raise IOError( self.printTag + ' ERROR: No one of the OutStreams linked to this interface have been found in the SLAVE RAVEN!' + ' Expected: "' + ' '.join(self.linkedDataObjectOutStreamsNames) + '" but found "' + ' '.join(self.outStreamsNamesAndType.keys()) + '"!') else: # self.linkedDatabaseName for dbName, dbXml in self.outDatabases.items(): if dbName == self.linkedDatabaseName: break else: # the one we want wasn't found! raise IOError( f'{self.printTag} ERROR: The Database named "{self.linkedDatabaseName}" listed ' + 'in <outputDatabase> was not found among the written Databases in active Steps in the inner RAVEN! ' + f'Found: {list(self.outDatabases.keys())}') # get variable groups varGroupNames = parser.returnVarGroups() ## store globally self.variableGroups = varGroupNames # get inner working dir self.innerWorkingDir = parser.workingDir # check operating system and define prefix if needed if platform.startswith("win") and utils.which("bash.exe") is not None: self.preCommand = 'bash.exe'
def toggle_mixer(self): """ Toggle mixer application """ mixer = self.get_mixer_name() run = self.config.getboolean(self.config.get_default_section(), "run_in_terminal") and not self.config.getboolean(self.config.get_default_section(), "mixer_internal") log.Notice("Launching mixer %s / %s" % (mixer, run) ) if not mixer: return try: pid = self._mixer_get_pid() if pid: os.kill(pid, SIGTERM) else: if (run): term = utils.find_term() cmd = [term, "-e", mixer] else: cmd = utils.which(mixer) Popen(cmd, shell=False) except Exception, err: log.Warn("Can\'t find mixer: %s" % str(err) )
def test_which(self): self.assertEqual(utils.which('sh'), '/bin/sh')