def __readProduct(self): try: io = IO.InputOutput() io.setStream(sys.stdin) text = io.read() for stdin in self.commands['stdin']: self.commands[stdin].append(text) except Exception, e: raise IO.InputOutputError( "Unable to read product from standard input", e)
def promptForOK(command,text): io = IO.InputOutput() msg = "'%s' operation as requested will %s" % (command,text) io.writeln(sys.stdout,msg) msg = "Confirm operation [Y|N]: " io.write(sys.stdout,msg) resp = io.readln(sys.stdin) return 'Y' == resp.upper()
def __correctLegacyCommand(self): try: default = self.commands.pop(CL.DEFAULT_KEY) command = default.pop(0) command = config.flags.get(command)[0] self.commands[command] = default except Exception, e: raise IO.InputOutputError('Unable to correct legacy command line', e)
def __readScript(self): # read the script if self.script == "": io = IO.InputOutput() io.setStream(sys.stdin) text = io.read() else: text = self.script # perform any substitutions if 'substitution' in self.commands: list = self.commands.get('substitution') dict = util.convListToDict(list) self.script = self.__transform(dict, text) else: self.script = text
def __processResponse(self,msg): status = 0 io = IO.InputOutput() # process the return message for prop in msg.getHeader().getProperties(): name = prop.getName() value = prop.getValue() if name == 'STDERR': parts = value.split(':',2) if parts[0] == 'ERROR': status = 1 value = parts[1] io.setStream(sys.stderr) else: io.setStream(sys.stdout) io.writeln(data=value) return status
def __runScript(self): io = IO.InputOutput() # pass the script to EDEX runner = self.commands.get('runner') service = config.endpoint.get(runner) # submit the input to the server and obtain result connection = str( os.getenv("DEFAULT_HOST", "localhost") + ":" + os.getenv("DEFAULT_PORT", "9581")) ch = CH.CommHandler(connection, service) ch.process(self.script) # expect message 200, if not print error message and return error code if not ch.isGoodStatus(): util.reportHTTPResponse(ch.formatResponse()) return 1 if 'fullMessage' in self.commands: # Return the full XML message to the appropriate stream io.setStream(sys.stdout) io.writeln(data=ch.getContents()) retVal = 0 else: # Pull the responses element out of the xml msg = MSG.Message() msg.parse(ch.getContents()) # process the response and send results to the appropriate stream error, hdr, resp = self.__getResponse(msg) if error: io.setStream(sys.stderr) retVal = 1 else: io.setStream(sys.stdout) retVal = 0 io.writeln(data=hdr) io.writeln(data=resp) return retVal
def __readScript(self): if self.script == "": io = IO.InputOutput() io.setStream(sys.stdin) self.script = io.read() return