def runSystemCommand(self, **attrs): """Synchronous run system command""" context = RunningContext(**attrs) origWD = os.getcwd() # remember our original working directory if context.workingDirectory is not None: os.chdir(context.workingDirectory) context.process = subprocess.Popen(context.scriptFilePath, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env = context.scriptFileEnvironment) print(encoding.to_fs(context.inputValue)) outputValue, errorValue = context.process.communicate( encoding.to_fs(context.inputValue)) context.outputValue = encoding.from_fs(outputValue) context.errorValue = encoding.from_fs(errorValue) context.outputType = context.process.returncode if context.workingDirectory is not None: os.chdir(origWD) if context.callback is not None: context.callback(context) return context
def makeExecutableTempFile(content, directory, prefix="script"): # TODO: Mejorara la generacion de temp, se borra no se borra que onda #tempFile = tempfile.NamedTemporaryFile(prefix='pmx', dir = directory) descriptor, name = tempfile.mkstemp(prefix=prefix, dir = directory) tempFile = os.fdopen(descriptor, 'w+') tempFile.write(encoding.to_fs(content)) tempFile.close() os.chmod(name, stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE) return name
def sendResult(self, connection, value=None): if value is None: value = "" if isinstance(value, int): value = "%d" % value if isinstance(value, dict): value = plist.writePlistToString(value) #Si tengo error retorno en lugar de result un error con { "code": <numero>, "message": "Cadena de error"} result = encoding.to_fs(value) self.logger().debug("Dialog Send --> Result %s: %s" % (type(result), result)) connection.write(result)
def save(self, basePath = None): path = os.path.join(basePath, self.name) if basePath is not None else self.path with open(path, 'w') as f: f.write(encoding.to_fs(self.content)) self.path = path
def setFileContent(self, content): if os.path.exists(self.path): with open(self.path, 'w') as f: f.write(encoding.to_fs(content))
def ensureCygwinEnvironment(environment): return dict(map(lambda item: (encoding.to_fs(item[0]), ensureCygwinPath(encoding.to_fs(item[1]))), environment.items()))
def ensureWindowsEnvironment(environment): return dict(map(lambda item: (encoding.to_fs(item[0]), encoding.to_fs(item[1])), environment.items()))
def _started(): if context.inputValue is not None: context.process.write(encoding.to_fs(context.inputValue)) context.process.closeWriteChannel()