Ejemplo n.º 1
0
 def __init__(self):
     self.process = QProcess()
     self.process.error[QProcess.ProcessError].connect(
         self.error_management)
     self.env = QProcessEnvironment().systemEnvironment()
     self.set_otb_process_env_default()
     self.command = ""
Ejemplo n.º 2
0
    def __init__(self):
        super(EjecutarWidget, self).__init__()
        layoutV = QVBoxLayout(self)
        layoutV.setContentsMargins(0, 0, 0, 0)
        layoutV.setSpacing(0)
        self.output = output_compiler.SalidaCompilador(self)
        layoutV.addWidget(self.output)
        self.setLayout(layoutV)

        # Flag
        self._compilation_failed = False

        # Procesos
        self.build_process = QProcess(self)
        if not sys.platform.startswith('linux'):
            self._envgcc = QProcessEnvironment.systemEnvironment()
            self._envgcc.insert("PATH", ENV_GCC)
            self.build_process.setProcessEnvironment(self._envgcc)
        self.execution_process = QProcess(self)

        # Conexiones
        self.build_process.readyReadStandardError.connect(
            self.output.stderr_output)
        self.build_process.finished[int, QProcess.ExitStatus].connect(
            self._compilation_finished)
        self.build_process.error[QProcess.ProcessError].connect(
            self._compilation_error)
        self.execution_process.finished[int, QProcess.ExitStatus].connect(
            self._execution_finished)
Ejemplo n.º 3
0
def get_env_variable(variable):
    from PyQt4.QtCore import QProcessEnvironment
    env = QProcessEnvironment.systemEnvironment()
    if env.contains(variable):
        return str(env.value(variable))
    else:
        return None
Ejemplo n.º 4
0
    def __init__(self, name, project, **kwargs):
        super(BatchFileSync, self).__init__(name, project)
        self.cmd = kwargs['cmd']
        if self.project:
            self.rootfolder = os.path.abspath(self.project.folder)
        else:
            self.rootfolder = kwargs['rootfolder']

        self.project = project
        self.closeproject = kwargs.get("close_project", False)
        self.process = QProcess()
        self.parser = kwargs.get("parser", None)
        self.parsermodule = None
        variables = kwargs.get("variables", {})
        env = QProcessEnvironment.systemEnvironment()
        for varname, value in variables.iteritems():
            env.insert(varname, str(value))
        self.process.setProcessEnvironment(env)
        self.process.setWorkingDirectory(os.path.dirname(os.path.realpath(self.cmd)))
        self.process.finished.connect(self.complete)
        self.process.started.connect(self.syncStarted)
        self.process.readyReadStandardError.connect(self.error)
        self.process.readyReadStandardOutput.connect(self.readOutput)
        self._output = ""
        self.haserror = False
Ejemplo n.º 5
0
    def __init__(self, name, project, **kwargs):
        super(BatchFileSync, self).__init__(name, project)
        self.cmd = kwargs['cmd']
        if self.project:
            self.rootfolder = os.path.abspath(self.project.folder)
        else:
            self.rootfolder = kwargs['rootfolder']

        self.project = project
        self.closeproject = kwargs.get("close_project", False)
        self.process = QProcess()
        self.parser = kwargs.get("parser", None)
        self.parsermodule = None
        variables = kwargs.get("variables", {})
        env = QProcessEnvironment.systemEnvironment()
        for varname, value in variables.iteritems():
            env.insert(varname, str(value))
        self.process.setProcessEnvironment(env)
        self.process.setWorkingDirectory(
            os.path.dirname(os.path.realpath(self.cmd)))
        self.process.finished.connect(self.complete)
        self.process.started.connect(self.syncStarted)
        self.process.readyReadStandardError.connect(self.error)
        self.process.readyReadStandardOutput.connect(self.readOutput)
        self._output = ""
        self.haserror = False
Ejemplo n.º 6
0
    def __init__(self):
        super(EjecutarWidget, self).__init__()
        layoutV = QVBoxLayout(self)
        layoutV.setContentsMargins(0, 0, 0, 0)
        layoutV.setSpacing(0)
        self.output = output_compiler.SalidaCompilador(self)
        layoutV.addWidget(self.output)
        self.setLayout(layoutV)

        # Flag
        self._compilation_failed = False

        # Procesos
        self.build_process = QProcess(self)
        if not sys.platform.startswith('linux'):
            self._envgcc = QProcessEnvironment.systemEnvironment()
            self._envgcc.insert("PATH", ENV_GCC)
            self.build_process.setProcessEnvironment(self._envgcc)
        self.execution_process = QProcess(self)

        # Conexiones
        self.build_process.readyReadStandardError.connect(
            self.output.stderr_output)
        self.build_process.finished[int, QProcess.ExitStatus].connect(
            self._compilation_finished)
        self.build_process.error[QProcess.ProcessError].connect(
            self._compilation_error)
        self.execution_process.finished[int, QProcess.ExitStatus].connect(
            self._execution_finished)
Ejemplo n.º 7
0
def get_env_variable(variable):
    from PyQt4.QtCore import QProcessEnvironment
    env = QProcessEnvironment.systemEnvironment()
    if env.contains(variable):
        return str(env.value(variable))
    else:
        return None
Ejemplo n.º 8
0
def set_process_env(process):
    dirname = os.path.dirname(os.path.abspath(__file__))
    env = QProcessEnvironment.systemEnvironment()

    env.insert("ITK_AUTOLOAD_PATH", os.path.join(dirname, "win32", "plugin"))  # Add an environment variable
    env.insert("PATH", os.path.join(dirname, "win32", "bin") + ";" + env.value("Path"))
    process.setProcessEnvironment(env)
Ejemplo n.º 9
0
def set_process_env(process):
    dirname = os.path.dirname(os.path.abspath(__file__))
    env = QProcessEnvironment.systemEnvironment()

    env.insert("ITK_AUTOLOAD_PATH",
               os.path.join(dirname, "win32",
                            "plugin"))  # Add an environment variable
    env.insert("PATH",
               os.path.join(dirname, "win32", "bin") + ";" + env.value("Path"))
    process.setProcessEnvironment(env)
Ejemplo n.º 10
0
    def __main_execution(self):
        """Execute the project."""
        self.output.setCurrentCharFormat(self.output.plain_format)
        message = ''
        if self.__preScriptExecuted:
            self.__preScriptExecuted = False
            message = self.tr(
                "Pre Execution Script Successfully executed.\n\n")
        self.output.setPlainText(message + 'Running: %s (%s)\n\n' %
                                 (self.fileName, time.ctime()))
        self.output.moveCursor(QTextCursor.Down)
        self.output.moveCursor(QTextCursor.Down)
        self.output.moveCursor(QTextCursor.Down)

        if not self.pythonExec:
            self.pythonExec = settings.PYTHON_EXEC
        #change the working directory to the fileName dir
        file_directory = file_manager.get_folder(self.fileName)
        self._proc.setWorkingDirectory(file_directory)
        #force python to unbuffer stdin and stdout
        options = ['-u'] + settings.EXECUTION_OPTIONS.split()
        self.currentProcess = self._proc

        env = QProcessEnvironment()
        system_environemnt = self._proc.systemEnvironment()
        for e in system_environemnt:
            key, value = e.split('=', 1)
            env.insert(key, value)
        if self.PYTHONPATH:
            envpaths = [path for path in self.PYTHONPATH.splitlines()]
            for path in envpaths:
                env.insert('PYTHONPATH', path)
        env.insert('PYTHONIOENCODING', 'utf-8')
        env.insert('PYTHONPATH', ':'.join(sys.path))
        self._proc.setProcessEnvironment(env)

        self._proc.start(self.pythonExec, options + [self.fileName] +
                         [p.strip()
                          for p in self.programParams.split(',') if p])
Ejemplo n.º 11
0
    def __main_execution(self):
        """Execute the project."""
        self.output.setCurrentCharFormat(self.output.plain_format)
        message = ''
        if self.__preScriptExecuted:
            self.__preScriptExecuted = False
            message = self.tr(
                "Pre Execution Script Successfully executed.\n\n")
        self.output.setPlainText(message + 'Running: %s (%s)\n\n' %
            (self.fileName, unicode(time.ctime())))
        self.output.moveCursor(QTextCursor.Down)
        self.output.moveCursor(QTextCursor.Down)
        self.output.moveCursor(QTextCursor.Down)

        #runner.run_code_from_file(fileName)
        if not self.pythonPath:
            self.pythonPath = settings.PYTHON_PATH
        #change the working directory to the fileName dir
        file_directory = file_manager.get_folder(self.fileName)
        self._proc.setWorkingDirectory(file_directory)
        #force python to unbuffer stdin and stdout
        options = ['-u'] + settings.EXECUTION_OPTIONS.split()
        self.currentProcess = self._proc

        if self.PYTHONPATH:
            envpaths = [path for path in self.PYTHONPATH.splitlines()]
            env = QProcessEnvironment()
            system_environemnt = self._proc.systemEnvironment()
            for e in system_environemnt:
                key, value = unicode(e).split('=', 1)
                env.insert(key, value)
            for path in envpaths:
                env.insert('PYTHONPATH', path)
            self._proc.setProcessEnvironment(env)

        self._proc.start(self.pythonPath, options + [self.fileName] +
            [p.strip() for p in self.programParams.split(',') if p])
Ejemplo n.º 12
0
 def __init__(self, name, **kwargs):
     super(BatchFileSync, self).__init__(name)
     self.cmd = kwargs['cmd']
     self.process = QProcess()
     variables = kwargs.get("variables", {})
     env = QProcessEnvironment.systemEnvironment()
     for varname, value in variables.iteritems():
         env.insert(varname, value)
     self.process.setProcessEnvironment(env)
     self.process.setWorkingDirectory(os.path.dirname(os.path.realpath(self.cmd)))
     self.process.finished.connect(self.complete)
     self.process.started.connect(self.syncStarted)
     self.process.readyReadStandardError.connect(self.error)
     self.process.readyReadStandardOutput.connect(self.readOutput)
     self._output = ""
     self.haserror = False
Ejemplo n.º 13
0
 def _update_process_environment(self):
     """(internal) initializes the environment for the process."""
     se = QProcessEnvironment.systemEnvironment()
     for k, v in self.environment.items():
         se.remove(k) if v is None else se.insert(k, v)
     self._process.setProcessEnvironment(se)
Ejemplo n.º 14
0
 def _updateProcessEnvironment(self):
     """Called internally; initializes the environment for the process."""
     se = QProcessEnvironment.systemEnvironment()
     for k, v in self.environment.items():
         se.remove(k) if v is None else se.insert(k, v)
     self._process.setProcessEnvironment(se)
Ejemplo n.º 15
0
def main(argv):

    path = None
    first_arg = None
    second_arg = None
    config = None
    apath = None
    print("QT VERSION %s" % QT_VERSION_STR )

    try:
        first_arg = argv[1]
        second_arg = argv[2]
    except IndexError:
        pass

    if first_arg is not None:
        if first_arg == "-c":
            config = True 
            if second_arg is not None:
                path = second_arg
        else:
            path = first_arg
        
    try:
        #app = QApplication(argv)
        app = MyApp(argv)

        QCoreApplication.setOrganizationDomain('www.trickplay.com');
        QCoreApplication.setOrganizationName('Trickplay');
        QCoreApplication.setApplicationName('Trickplay Debugger');
        QCoreApplication.setApplicationVersion('0.0.1');
            
        s = QProcessEnvironment.systemEnvironment().toStringList()
        for item in s:
            k , v = str( item ).split( "=" , 1 )
            if k == 'PWD':
                apath = v

        apath = os.path.join(apath, os.path.dirname(str(argv[0])))
        main = MainWindow(app, apath)
        main.config = config

        main.show()
        main.raise_()
        wizard = Wizard()
        app.main = main

        path = wizard.start(path)
        if path:
            settings = QSettings()
            settings.setValue('path', path)

            app.setActiveWindow(main)
            main.start(path, wizard.filesToOpen())
            main.show()

        sys.exit(app.exec_())

    # TODO, better way of doing this for 'clean' exit...
    except KeyboardInterrupt:
		exit("Exited")
Ejemplo n.º 16
0
 def __init__(self):
     self.process = QProcess()
     self.process.error[QProcess.ProcessError].connect(self.error_management)
     self.env = QProcessEnvironment().systemEnvironment()
     self.set_otb_process_env_default()
     self.command = ""
Ejemplo n.º 17
0
class TerreImageProcess():

    def __init__(self):
        self.process = QProcess()
        self.process.error[QProcess.ProcessError].connect(self.error_management)
        self.env = QProcessEnvironment().systemEnvironment()
        self.set_otb_process_env_default()
        self.command = ""

    def run_process(self, command):
        logger.info(u"Running {}".format(command))
        self.process.setProcessEnvironment(self.env)

        # logger.debug("..............{}".format(self.process.processEnvironment().value("OTB_APPLICATION_PATH")))
        # logger.debug("..............{}".format(self.process.processEnvironment().value("PATH")))
        # logger.debug("Environ : PATH {}".format(os.environ["PATH"]))
        # logger.debug("Environ : OTB_APPLICATION_PATH {}".format(os.environ.get("OTB_APPLICATION_PATH", "Empty")))
        self.command = command
        self.process.start(command)
        if self.process.waitForStarted():
            self.process.waitForFinished(-1)
            exit_code = self.process.exitCode()
            if exit_code != 0:
                self.error_management(exit_code)
            result = self.process.readAllStandardOutput()
            # logger.debug(" {} {}".format(type(result), result))
            error = self.process.readAllStandardError().data()
            # logger.debug(repr(error))
            if not error in ["\n", ""]:
                logger.error("error : %s"%(error))
            output = result.data()
            logger.info(output)
            return result
        else:
            code_d_erreur = self.process.error()
            self.error_management(code_d_erreur)
        return None

    def error_management(self, errorCode):
        dic_err = { 0:"QProcess::FailedToStart", 1:"QProcess::Crashed",
            2:"QProcess::TimedOut", 3:"QProcess::WriteError",
            4:"QProcess::ReadError", 5:"QProcess::UnknownError",
            127:"Other, The application may not have been found"}
        try:
            type_qt_error = dic_err[errorCode]
            logger.error(u"Error {} {}".format(errorCode, type_qt_error))
        except KeyError:
            type_qt_error = ""
        error = self.process.readAllStandardError().data()
        logger.error(error)
        logger.error( self.process.readAllStandardOutput())
        try:
            raise terre_image_exceptions.TerreImageRunProcessError(u"Error running : {}\n {}{}".format(self.command,
                                                                                  type_qt_error, error
                                                                                  ))
        except UnicodeError:
            raise terre_image_exceptions.TerreImageRunProcessError(u"Error running : {}\n {}".format(self.command,
                                                                                  type_qt_error))

    def set_env_var(self, varname, varval, append = False, pre = False):

        if append == True:
            if pre == False:
                # insert value at the end of the variable
                self.env.insert(varname, self.env.value(varname) + os.pathsep + varval)
            else:
                # insert value in head
                self.env.insert(varname, varval + os.pathsep + self.env.value(varname))
        else:
            # replace value if existing
            self.env.insert(varname, varval)
        # logger.debug("env {} {}".format(varname, self.env.value(varname)))

    def set_otb_process_env(self):
        dirname = os.path.dirname(os.path.abspath(__file__))
        self.set_env_var("OTB_APPLICATION_PATH", os.path.join(dirname, "win32", "plugin"), pre=True)
        self.set_env_var("PATH", os.path.join(dirname, "win32", "bin"), append = False, pre=True)


    def set_otb_process_env_custom(self, otb_app_path="", path=""):
        """
        Add the given values to OTB_APPLICATION_PATH and PATH environement variables
        Args:
            otb_app_path:
            path:

        Returns:

        """
        self.set_env_var("OTB_APPLICATION_PATH", otb_app_path, pre=True)
        self.set_env_var("PATH", path, append = False, pre=True)


    def set_otb_process_env_default(self):
        """
        Add the values from the config file to OTB_APPLICATION_PATH and PATH environement variables
        Args:
            otb_app_path:
            path:

        Returns:

        """
        self.set_env_var("OTB_APPLICATION_PATH",
                         terre_image_configuration.OTB_APPLICATION_PATH, pre=True)
        self.set_env_var("PATH", terre_image_configuration.PATH, append = True, pre=True)
        if terre_image_configuration.LD_LIBRARY_PATH:
            self.set_env_var("LD_LIBRARY_PATH", terre_image_configuration.LD_LIBRARY_PATH, append = True, pre=True)
Ejemplo n.º 18
0
def main(argv):

    path = None
    first_arg = None
    second_arg = None
    config = None
    apath = None
    print("QT VERSION %s" % QT_VERSION_STR)

    try:
        first_arg = argv[1]
        second_arg = argv[2]
    except IndexError:
        pass

    if first_arg is not None:
        if first_arg == "-c":
            config = True
            if second_arg is not None:
                path = second_arg
        else:
            path = first_arg

    try:
        #app = QApplication(argv)
        app = MyApp(argv)

        QCoreApplication.setOrganizationDomain('www.trickplay.com')
        QCoreApplication.setOrganizationName('Trickplay')
        QCoreApplication.setApplicationName('Trickplay Debugger')
        QCoreApplication.setApplicationVersion('0.0.1')

        s = QProcessEnvironment.systemEnvironment().toStringList()
        for item in s:
            k, v = str(item).split("=", 1)
            if k == 'PWD':
                apath = v

        apath = os.path.join(apath, os.path.dirname(str(argv[0])))
        main = MainWindow(app, apath)
        main.config = config

        main.show()
        main.raise_()
        wizard = Wizard()
        app.main = main

        path = wizard.start(path)
        if path:
            settings = QSettings()
            settings.setValue('path', path)

            app.setActiveWindow(main)
            main.start(path, wizard.filesToOpen())
            main.show()

        sys.exit(app.exec_())

    # TODO, better way of doing this for 'clean' exit...
    except KeyboardInterrupt:
        exit("Exited")
Ejemplo n.º 19
0
class TerreImageProcess():
    def __init__(self):
        self.process = QProcess()
        self.process.error[QProcess.ProcessError].connect(
            self.error_management)
        self.env = QProcessEnvironment().systemEnvironment()
        self.set_otb_process_env_default()
        self.command = ""

    def run_process(self, command):
        logger.info(u"Running {}".format(command))
        self.process.setProcessEnvironment(self.env)

        # logger.debug("..............{}".format(self.process.processEnvironment().value("OTB_APPLICATION_PATH")))
        # logger.debug("..............{}".format(self.process.processEnvironment().value("PATH")))
        # logger.debug("Environ : PATH {}".format(os.environ["PATH"]))
        # logger.debug("Environ : OTB_APPLICATION_PATH {}".format(os.environ.get("OTB_APPLICATION_PATH", "Empty")))
        self.command = command
        self.process.start(command)
        if self.process.waitForStarted():
            self.process.waitForFinished(-1)
            exit_code = self.process.exitCode()
            if exit_code != 0:
                self.error_management(exit_code)
            result = self.process.readAllStandardOutput()
            # logger.debug(" {} {}".format(type(result), result))
            error = self.process.readAllStandardError().data()
            # logger.debug(repr(error))
            if not error in ["\n", ""]:
                logger.error("error : %s" % (error))
            output = result.data()
            logger.info(output)
            return result
        else:
            code_d_erreur = self.process.error()
            self.error_management(code_d_erreur)
        return None

    def error_management(self, errorCode):
        dic_err = {
            0: "QProcess::FailedToStart",
            1: "QProcess::Crashed",
            2: "QProcess::TimedOut",
            3: "QProcess::WriteError",
            4: "QProcess::ReadError",
            5: "QProcess::UnknownError",
            127: "Other, The application may not have been found"
        }
        try:
            type_qt_error = dic_err[errorCode]
            logger.error(u"Error {} {}".format(errorCode, type_qt_error))
        except KeyError:
            type_qt_error = ""
        error = self.process.readAllStandardError().data()
        logger.error(error)
        logger.error(self.process.readAllStandardOutput())
        try:
            raise terre_image_exceptions.TerreImageRunProcessError(
                u"Error running : {}\n {}{}".format(self.command,
                                                    type_qt_error, error))
        except UnicodeError:
            raise terre_image_exceptions.TerreImageRunProcessError(
                u"Error running : {}\n {}".format(self.command, type_qt_error))

    def set_env_var(self, varname, varval, append=False, pre=False):

        if append == True:
            if pre == False:
                # insert value at the end of the variable
                self.env.insert(varname,
                                self.env.value(varname) + os.pathsep + varval)
            else:
                # insert value in head
                self.env.insert(varname,
                                varval + os.pathsep + self.env.value(varname))
        else:
            # replace value if existing
            self.env.insert(varname, varval)
        # logger.debug("env {} {}".format(varname, self.env.value(varname)))

    def set_otb_process_env(self):
        dirname = os.path.dirname(os.path.abspath(__file__))
        self.set_env_var("OTB_APPLICATION_PATH",
                         os.path.join(dirname, "win32", "plugin"),
                         pre=True)
        self.set_env_var("PATH",
                         os.path.join(dirname, "win32", "bin"),
                         append=False,
                         pre=True)

    def set_otb_process_env_custom(self, otb_app_path="", path=""):
        """
        Add the given values to OTB_APPLICATION_PATH and PATH environement variables
        Args:
            otb_app_path:
            path:

        Returns:

        """
        self.set_env_var("OTB_APPLICATION_PATH", otb_app_path, pre=True)
        self.set_env_var("PATH", path, append=False, pre=True)

    def set_otb_process_env_default(self):
        """
        Add the values from the config file to OTB_APPLICATION_PATH and PATH environement variables
        Args:
            otb_app_path:
            path:

        Returns:

        """
        self.set_env_var("OTB_APPLICATION_PATH",
                         terre_image_configuration.OTB_APPLICATION_PATH,
                         pre=True)
        self.set_env_var("PATH",
                         terre_image_configuration.PATH,
                         append=True,
                         pre=True)
        if terre_image_configuration.LD_LIBRARY_PATH:
            self.set_env_var("LD_LIBRARY_PATH",
                             terre_image_configuration.LD_LIBRARY_PATH,
                             append=True,
                             pre=True)