Exemple #1
0
    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)

        outputValue, errorValue =  context.process.communicate(
            context.inputValue and 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
Exemple #2
0
 def _finished(exitCode, exitStatus):
     self.processTableModel.removeProcess(context.process)
     errorValue = qbytearray_to_text(
         context.process.readAllStandardError())
     context.errorValue = encoding.from_fs(errorValue)
     outputValue = qbytearray_to_text(
         context.process.readAllStandardOutput())
     context.outputValue = encoding.from_fs(outputValue)
     context.outputType = exitCode
     context.callback(context)
Exemple #3
0
 def socketReadyRead(self, connection):
     payload = encoding.from_fs(connection.readAll().data())
     for data in filter(lambda d: d, payload.split("\n\n")):
         message = json.loads(data)
         sid = message['sid']
         if sid in self.sessions:
             self.sessions[sid].message(message)
Exemple #4
0
    def _paint_screen(self, painter):
        # Speed hacks: local name lookups are faster
        vars().update(QColor=QtGui.QColor, QBrush=QtGui.QBrush, QPen=QtGui.QPen, QRect=QtCore.QRect)
        
        char_width = self._char_width
        char_height = self._char_height
        painter_drawText = painter.drawText
        painter_fillRect = painter.fillRect
        painter_setPen = painter.setPen
        painter_setFont = painter.setFont
        align = QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft
        # set defaults
        brush = QtGui.QBrush(self.scheme.background())
        painter_fillRect(self.rect(), brush)
        pen = QtGui.QPen(self.scheme.foreground())
        painter_setPen(pen)
        y = 0
        text = []
        # Calculate viewscreen
        viewscreen = (self._screen_history + self._screen)[self._history_index:self._history_index + len(self._screen)]
        for row, line in enumerate(viewscreen):
            col = 0
            text_line = ""
            for item in line:
                if isinstance(item, tuple):
                    foreground_color_idx, background_color_idx, flags = item
                    foregroundColor, backgroundColor, font = self.mapToStyle(
                        foreground_color_idx, 
                        background_color_idx, 
                        flags)
                    pen = QtGui.QPen(foregroundColor)
                    brush = QtGui.QBrush(backgroundColor)
                    painter_setFont(font)
                    painter_setPen(pen)
                else:
                    item = encoding.from_fs(item)
                    x = col * char_width
                    length = len(item)
                    rect = QtCore.QRect(x, y, x + char_width * length, y + char_height)
                    painter_fillRect(rect, brush)
                    painter_drawText(rect, align, item)
                    col += length
                    text_line += item
            # Clear last column            
            rect = QtCore.QRect(col * char_width, y, self.width(), y + char_height)
            brush = QtGui.QBrush(self.backgroundColor())
            painter_fillRect(rect, brush)
            
            y += char_height
            text.append(text_line)

        # Store text
        self._text = text
        
        # Clear last lines
        rect = QtCore.QRect(0, y, self.width(), self.height())
        brush = QtGui.QBrush(self.backgroundColor())
        painter_fillRect(rect, brush)
Exemple #5
0
 def backend_start_readyReadStandardOutput():
     connection = encoding.from_fs(self.process.readAllStandardOutput()).splitlines()[1]
     connection = json.loads(connection)
     self.setAddress(connection['address'])
     self.process.readyReadStandardError.disconnect(backend_start_readyReadStandardError)
     self.process.readyReadStandardOutput.disconnect(backend_start_readyReadStandardOutput)
     self.process.readyReadStandardError.connect(self.backend_readyReadStandardError)
     self.process.readyReadStandardOutput.connect(self.backend_readyReadStandardOutput)
     self.process.finished.connect(self.backend_finished)
     self.process.error.connect(self.backend_error)
     super(LocalBackend, self).start()
Exemple #6
0
 def backend_start_readyReadStandardOutput(self):
     connectionString = encoding.from_fs(self.process.readAllStandardOutput()).splitlines()[-1]
     data = ast.literal_eval(connectionString)
     self.startMultiplexer(data["multiplexer"])
     self.startNotifier(data["notifier"])
     self.process.readyReadStandardError.disconnect(self.backend_start_readyReadStandardError)
     self.process.readyReadStandardOutput.disconnect(self.backend_start_readyReadStandardOutput)
     self.process.readyReadStandardError.connect(self.backend_readyReadStandardError)
     self.process.readyReadStandardOutput.connect(self.backend_readyReadStandardOutput)
     self.process.finished.connect(self.backend_finished)
     self.process.error.connect(self.backend_error)
     self._set_state(self.Running)
     self.started.emit()
Exemple #7
0
 def socketReadyRead(self, connection):
     command = json.loads(encoding.from_fs(connection.readAll().data()))
     name = command.get("name")
     args = command.get("args", [])
     kwargs = command.get("kwargs", {})
     
     args.insert(0, connection)
     #TODO: Filtro todo lo que sea None asumo que las signaturas de los metodos ponene los valores por defecto
     # esto tendria que ser controlado de una mejor forma
     kwargs = dict([key_value for key_value in iter(kwargs.items()) if key_value[1] != None])
     
     self.logger().debug("Dialog Recv --> Method: %s, Arguments: %s" % (name, kwargs))
     method = getattr(self, name)
     try:
         method(*args, **kwargs)
     except Exception as reason:
         self.sendResult(connection, {"error": {"code": -1, "message": six.text_type(reason)}})
         raise reason
Exemple #8
0
 def getFileContent(self):
     content = ""
     if os.path.exists(self.path):
         with open(self.path, 'r') as f:
             content = encoding.from_fs(f.read())
     return content
Exemple #9
0
 def backend_readyReadStandardOutput(self):
     print(encoding.from_fs(self.process.readAllStandardOutput()))
Exemple #10
0
 def backend_start_readyReadStandardError(self):
     print(encoding.from_fs(self.process.readAllStandardError()))
     self.process.readyReadStandardError.disconnect(self.backend_start_readyReadStandardError)
     self.process.readyReadStandardOutput.disconnect(self.backend_start_readyReadStandardOutput)
     self.error.emit(self.ReadError)
     self.finished.emit(-1)