예제 #1
0
파일: manager.py 프로젝트: D3f0/prymatex
    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
예제 #2
0
파일: scripts.py 프로젝트: D3f0/prymatex
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
예제 #3
0
파일: server.py 프로젝트: prymatex/prymatex
 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)
예제 #4
0
파일: staticfile.py 프로젝트: D3f0/prymatex
 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
예제 #5
0
파일: staticfile.py 프로젝트: D3f0/prymatex
 def setFileContent(self, content):
     if os.path.exists(self.path):
         with open(self.path, 'w') as f:
             f.write(encoding.to_fs(content))
예제 #6
0
def ensureCygwinEnvironment(environment):
    return dict(map(lambda item: (encoding.to_fs(item[0]), ensureCygwinPath(encoding.to_fs(item[1]))), environment.items()))
예제 #7
0
def ensureWindowsEnvironment(environment):
    return dict(map(lambda item: (encoding.to_fs(item[0]), encoding.to_fs(item[1])), environment.items()))
예제 #8
0
파일: support.py 프로젝트: D3f0/prymatex
 def _started():
     if context.inputValue is not None:
         context.process.write(encoding.to_fs(context.inputValue))
     context.process.closeWriteChannel()