Exemplo n.º 1
0
 def RLibs():
     folder = ProcessingConfig.getSetting(RUtils.R_LIBS_USER)
     if folder is None:
         folder = str(os.path.join(userFolder(), 'rlibs'))
     try:
         mkdir(folder)
     except:
         folder = str(os.path.join(userFolder(), 'rlibs'))
         mkdir(folder)
     return os.path.abspath(str(folder))
Exemplo n.º 2
0
    def RScriptsFolder():
        folder = ProcessingConfig.getSetting(RUtils.RSCRIPTS_FOLDER)
        if folder is None:
            folder = unicode(os.path.join(userFolder(), 'rscripts'))
        try:
            mkdir(folder)
        except:
            folder = unicode(os.path.join(userFolder(), 'rscripts'))
            mkdir(folder)

        return os.path.abspath(folder)
Exemplo n.º 3
0
 def grassBatchJobFilename():
     '''This is used in Linux. This is the batch job that we assign to
     GRASS_BATCH_JOB and then call GRASS and let it do the work
     '''
     filename = 'grass7_batch_job.sh'
     batchfile = userFolder() + os.sep + filename
     return batchfile
Exemplo n.º 4
0
 def grassScriptFilename():
     '''This is used in windows. We create a script that initializes
     GRASS and then uses grass commands
     '''
     filename = 'grass_script.bat'
     filename = userFolder() + os.sep + filename
     return filename
Exemplo n.º 5
0
 def RLibs():
     folder = ProcessingConfig.getSetting(RUtils.R_LIBS_USER)
     if folder is None:
         folder = unicode(os.path.join(userFolder(), 'rlibs'))
     mkdir(folder)
     
     return os.path.abspath(unicode(folder))
Exemplo n.º 6
0
    def modelsFolder():
        folder = ProcessingConfig.getSetting(ModelerUtils.MODELS_FOLDER)
        if folder is None:
            folder = unicode(os.path.join(userFolder(), 'models'))
        mkdir(folder)

        return os.path.abspath(folder)
Exemplo n.º 7
0
    def prepareGrassExecution(commands):
        env = os.environ.copy()

        if isWindows():
            GrassUtils.createGrassScript(commands)
            command = ["cmd.exe", "/C ", GrassUtils.grassScriptFilename()]
        else:
            gisrc = os.path.join(userFolder(), "processing.gisrc")
            env["GISRC"] = gisrc
            env["GRASS_MESSAGE_FORMAT"] = "gui"
            env["GRASS_BATCH_JOB"] = GrassUtils.grassBatchJobFilename()
            if "GISBASE" in env:
                del env["GISBASE"]
            GrassUtils.createGrassBatchJobFileFromGrassCommands(commands)
            os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
            if isMac():
                command = (
                    os.path.join(GrassUtils.grassPath(), "grass.sh")
                    + " "
                    + os.path.join(GrassUtils.grassMapsetFolder(), "PERMANENT")
                )
            else:
                command = "grass64 " + os.path.join(GrassUtils.grassMapsetFolder(), "PERMANENT")

        return command, env
Exemplo n.º 8
0
 def grassBatchJobFilename():
     '''This is used in Linux. This is the batch job that we assign to
     GRASS_BATCH_JOB and then call GRASS and let it do the work
     '''
     filename = 'grass_batch_job.sh'
     batchfile = os.path.join(userFolder(), filename)
     return batchfile
Exemplo n.º 9
0
 def grassScriptFilename():
     '''This is used in windows. We create a script that initializes
     GRASS and then uses grass commands
     '''
     filename = 'grass_script.bat'
     filename = os.path.join(userFolder(), filename)
     return filename
Exemplo n.º 10
0
    def prepareGrass7Execution(commands):
        env = os.environ.copy()

        if isWindows():
            Grass7Utils.createGrass7Script(commands)
            command = ['cmd.exe', '/C ', Grass7Utils.grassScriptFilename()]
        else:
            gisrc = userFolder() + os.sep + 'processing.gisrc7'
            env['GISRC'] = gisrc
            env['GRASS_MESSAGE_FORMAT'] = 'plain'
            env['GRASS_BATCH_JOB'] = Grass7Utils.grassBatchJobFilename()
            if 'GISBASE' in env:
                del env['GISBASE']
            Grass7Utils.createGrass7BatchJobFileFromGrass7Commands(commands)
            os.chmod(Grass7Utils.grassBatchJobFilename(), stat.S_IEXEC
                     | stat.S_IREAD | stat.S_IWRITE)
            if isMac() and os.path.exists(Grass7Utils.grassPath() + os.sep +
                                          'grass70.sh'):
                command = Grass7Utils.grassPath() + os.sep + 'grass70.sh ' \
                    + Grass7Utils.grassMapsetFolder() + '/PERMANENT'
            else:
                command = 'grass70 ' + Grass7Utils.grassMapsetFolder() \
                    + '/PERMANENT'

        return command, env
Exemplo n.º 11
0
    def scriptsFolder():
        folder = ProcessingConfig.getSetting(ScriptUtils.SCRIPTS_FOLDER)
        if folder is None:
            folder = unicode(os.path.join(userFolder(), 'scripts'))
        mkdir(folder)

        return os.path.abspath(folder)
Exemplo n.º 12
0
    def logFilename():
        logFilename = userFolder() + os.sep + "processing.log"
        if not os.path.isfile(logFilename):
            logfile = codecs.open(logFilename, "w", encoding="utf-8")
            logfile.write("Started logging at " + datetime.datetime.now().strftime(ProcessingLog.DATE_FORMAT) + "\n")
            logfile.close()

        return logFilename
Exemplo n.º 13
0
    def logFilename():
        logFilename = userFolder() + os.sep + 'processing.log'
        if not os.path.isfile(logFilename):
            with codecs.open(logFilename, 'w', encoding='utf-8') as logfile:
                logfile.write('Started logging at ' +
                              datetime.datetime.now().strftime(ProcessingLog.DATE_FORMAT) + '\n')

        return logFilename
Exemplo n.º 14
0
def sagaBatchJobFilename():
    if isWindows():
        filename = 'saga_batch_job.bat'
    else:
        filename = 'saga_batch_job.sh'

    batchfile = userFolder() + os.sep + filename

    return batchfile
def batchJobFilename():
    if isWindows():
        fileName = "circuitscape_batch_job.bat"
    else:
        fileName = "circuitscape_batch_job.sh"

    batchFile = userFolder() + os.sep + fileName

    return batchFile
Exemplo n.º 16
0
def sagaBatchJobFilename():
    if isWindows():
        filename = 'saga_batch_job.bat'
    else:
        filename = 'saga_batch_job.sh'

    batchfile = os.path.join(userFolder(), filename)

    return batchfile
Exemplo n.º 17
0
    def createGrassScript(commands):
        folder = GrassUtils.grassPath()
        shell = GrassUtils.grassWinShell()

        script = GrassUtils.grassScriptFilename()
        gisrc = userFolder() + os.sep + 'processing.gisrc'

        encoding = locale.getpreferredencoding()
        # Temporary gisrc file
        output = codecs.open(gisrc, 'w', encoding=encoding)
        location = 'temp_location'
        gisdbase = GrassUtils.grassDataFolder()

        output.write('GISDBASE: ' + gisdbase + '\n')
        output.write('LOCATION_NAME: ' + location + '\n')
        output.write('MAPSET: PERMANENT \n')
        output.write('GRASS_GUI: text\n')
        output.close()

        output = codecs.open(script, 'w', encoding=encoding)
        output.write('set HOME=' + os.path.expanduser('~') + '\n')
        output.write('set GISRC=' + gisrc + '\n')
        output.write('set GRASS_SH=' + shell + '\\bin\\sh.exe\n')
        output.write('set PATH=' + shell + os.sep + 'bin;' + shell + os.sep
                     + 'lib;' + '%PATH%\n')
        output.write('set WINGISBASE=' + folder + '\n')
        output.write('set GISBASE=' + folder + '\n')
        output.write('set GRASS_PROJSHARE=' + folder + os.sep + 'share'
                     + os.sep + 'proj' + '\n')
        output.write('set GRASS_MESSAGE_FORMAT=gui\n')

        # Replacement code for etc/Init.bat
        output.write('if "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\lib;%PATH%\n')
        output.write('if not "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\lib;%GRASS_ADDON_PATH%;%PATH%\n')
        output.write('\n')
        output.write('set GRASS_VERSION=' + GrassUtils.getGrassVersion() + '\n')
        output.write('if not "%LANG%"=="" goto langset\n')
        output.write('FOR /F "usebackq delims==" %%i IN (`"%WINGISBASE%\\etc\\winlocale"`) DO @set LANG=%%i\n')
        output.write(':langset\n')
        output.write('\n')
        output.write('set PATHEXT=%PATHEXT%;.PY\n')
        output.write('set PYTHONPATH=%PYTHONPATH%;%WINGISBASE%\\etc\\python;%WINGISBASE%\\etc\\wxpython\\n')
        output.write('\n')
        output.write('g.gisenv.exe set="MAPSET=PERMANENT"\n')
        output.write('g.gisenv.exe set="LOCATION=' + location + '"\n')
        output.write('g.gisenv.exe set="LOCATION_NAME=' + location + '"\n')
        output.write('g.gisenv.exe set="GISDBASE=' + gisdbase + '"\n')
        output.write('g.gisenv.exe set="GRASS_GUI=text"\n')
        for command in commands:
            output.write(command + u'\n')
        output.write('\n')
        output.write('exit\n')
        output.close()
Exemplo n.º 18
0
    def createGrassScript(commands):
        folder = GrassUtils.grassPath()
        shell = GrassUtils.grassWinShell()

        script = GrassUtils.grassScriptFilename()
        gisrc = os.path.join(userFolder(), "processing.gisrc")

        encoding = locale.getpreferredencoding()
        # Temporary gisrc file
        with codecs.open(gisrc, "w", encoding=encoding) as output:
            location = "temp_location"
            gisdbase = GrassUtils.grassDataFolder()

            output.write("GISDBASE: " + gisdbase + "\n")
            output.write("LOCATION_NAME: " + location + "\n")
            output.write("MAPSET: PERMANENT \n")
            output.write("GRASS_GUI: text\n")

        with codecs.open(script, "w", encoding=encoding) as output:
            output.write("set HOME=" + os.path.expanduser("~") + "\n")
            output.write("set GISRC=" + gisrc + "\n")
            output.write("set GRASS_SH=" + shell + "\\bin\\sh.exe\n")
            output.write("set PATH=" + os.path.join(shell, "bin") + ";" + os.path.join(shell, "lib") + ";" + "%PATH%\n")
            output.write("set WINGISBASE=" + folder + "\n")
            output.write("set GISBASE=" + folder + "\n")
            output.write("set GRASS_PROJSHARE=" + os.path.join(folder, "share", "proj") + "\n")
            output.write("set GRASS_MESSAGE_FORMAT=gui\n")

            # Replacement code for etc/Init.bat
            output.write('if "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\lib;%PATH%\n')
            output.write(
                'if not "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\lib;%GRASS_ADDON_PATH%;%PATH%\n'
            )
            output.write("\n")
            output.write("set GRASS_VERSION=" + GrassUtils.getGrassVersion() + "\n")
            output.write('if not "%LANG%"=="" goto langset\n')
            output.write('FOR /F "usebackq delims==" %%i IN (`"%WINGISBASE%\\etc\\winlocale"`) DO @set LANG=%%i\n')
            output.write(":langset\n")
            output.write("\n")
            output.write("set PATHEXT=%PATHEXT%;.PY\n")
            output.write("set PYTHONPATH=%PYTHONPATH%;%WINGISBASE%\\etc\\python;%WINGISBASE%\\etc\\wxpython\\n")
            output.write("\n")
            output.write('g.gisenv.exe set="MAPSET=PERMANENT"\n')
            output.write('g.gisenv.exe set="LOCATION=' + location + '"\n')
            output.write('g.gisenv.exe set="LOCATION_NAME=' + location + '"\n')
            output.write('g.gisenv.exe set="GISDBASE=' + gisdbase + '"\n')
            output.write('g.gisenv.exe set="GRASS_GUI=text"\n')
            for command in commands:
                output.write(command + u"\n")
            output.write("\n")
            output.write("exit\n")
Exemplo n.º 19
0
    def createGrass7Script(commands):
        folder = Grass7Utils.grassPath()

        script = Grass7Utils.grassScriptFilename()
        gisrc = os.path.join(userFolder(), "processing.gisrc7")  # FIXME: use temporary file

        # Temporary gisrc file
        with open(gisrc, "w") as output:
            location = "temp_location"
            gisdbase = Grass7Utils.grassDataFolder()

            output.write("GISDBASE: " + gisdbase + "\n")
            output.write("LOCATION_NAME: " + location + "\n")
            output.write("MAPSET: PERMANENT \n")
            output.write("GRASS_GUI: text\n")

        with open(script, "w") as output:
            output.write("set HOME=" + os.path.expanduser("~") + "\n")
            output.write("set GISRC=" + gisrc + "\n")
            output.write("set WINGISBASE=" + folder + "\n")
            output.write("set GISBASE=" + folder + "\n")
            output.write("set GRASS_PROJSHARE=" + os.path.join(folder, "share", "proj") + "\n")
            output.write("set GRASS_MESSAGE_FORMAT=plain\n")

            # Replacement code for etc/Init.bat
            output.write('if "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\lib;%PATH%\n')
            output.write(
                'if not "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\lib;%GRASS_ADDON_PATH%;%PATH%\n'
            )
            output.write("\n")
            output.write("set GRASS_VERSION=" + Grass7Utils.installedVersion() + "\n")
            output.write('if not "%LANG%"=="" goto langset\n')
            output.write('FOR /F "usebackq delims==" %%i IN (`"%WINGISBASE%\\etc\\winlocale"`) DO @set LANG=%%i\n')
            output.write(":langset\n")
            output.write("\n")
            output.write("set PATHEXT=%PATHEXT%;.PY\n")
            output.write("set PYTHONPATH=%PYTHONPATH%;%WINGISBASE%\\etc\\python;%WINGISBASE%\\etc\\wxpython\\n")
            output.write("\n")
            output.write('g.gisenv.exe set="MAPSET=PERMANENT"\n')
            output.write('g.gisenv.exe set="LOCATION=' + location + '"\n')
            output.write('g.gisenv.exe set="LOCATION_NAME=' + location + '"\n')
            output.write('g.gisenv.exe set="GISDBASE=' + gisdbase + '"\n')
            output.write('g.gisenv.exe set="GRASS_GUI=text"\n')
            for command in commands:
                Grass7Utils.writeCommand(output, command)
            output.write("\n")
            output.write("exit\n")
Exemplo n.º 20
0
    def prepareGrassExecution(commands):
        if isWindows():
            GrassUtils.createGrassScript(commands)
            command = ['cmd.exe', '/C ', GrassUtils.grassScriptFilename()]
        else:
            gisrc = userFolder() + os.sep + 'processing.gisrc'
            os.putenv('GISRC', gisrc)
            os.putenv('GRASS_MESSAGE_FORMAT', 'gui')
            os.putenv('GRASS_BATCH_JOB', GrassUtils.grassBatchJobFilename())
            GrassUtils.createGrassBatchJobFileFromGrassCommands(commands)
            os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC
                     | stat.S_IREAD | stat.S_IWRITE)
            if isMac():
                command = GrassUtils.grassPath() + os.sep + 'grass.sh ' \
                    + GrassUtils.grassMapsetFolder() + '/PERMANENT'
            else:
                command = 'grass64 ' + GrassUtils.grassMapsetFolder() \
                    + '/PERMANENT'

        return command
Exemplo n.º 21
0
    def prepareGrassExecution(commands):
        env = os.environ.copy()

        if isWindows():
            GrassUtils.createGrassScript(commands)
            command = ['cmd.exe', '/C ', GrassUtils.grassScriptFilename()]
        else:
            gisrc = os.path.join(userFolder(), 'processing.gisrc')
            env['GISRC'] = gisrc
            env['GRASS_MESSAGE_FORMAT'] = 'gui'
            env['GRASS_BATCH_JOB'] = GrassUtils.grassBatchJobFilename()
            if 'GISBASE' in env:
                del env['GISBASE']
            GrassUtils.createGrassBatchJobFileFromGrassCommands(commands)
            os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC
                     | stat.S_IREAD | stat.S_IWRITE)
            if isMac():
                command = os.path.join(GrassUtils.grassPath(), 'grass.sh') + ' ' \
                    + os.path.join(GrassUtils.grassMapsetFolder(), 'PERMANENT')
            else:
                command = 'grass64 ' + os.path.join(GrassUtils.grassMapsetFolder(), 'PERMANENT')

        return command, env
Exemplo n.º 22
0
 def tempFileListFilepath():
     filename = 'fusion_files_list.txt'
     filepath = os.path.join(userFolder(), filename)
     return filepath
Exemplo n.º 23
0
 def expsFile(self):
     return os.path.join(userFolder(), 'rastercalcexpressions.json')
Exemplo n.º 24
0
 def defaultScriptsFolder():
     folder = str(os.path.join(userFolder(), "scripts"))
     mkdir(folder)
     return os.path.abspath(folder)
Exemplo n.º 25
0
 def configFile():
     return os.path.join(userFolder(), 'processing_qgis_styles.conf')
Exemplo n.º 26
0
 def configFile():
     return os.path.join(userFolder(), 'processing_qgis_styles.conf')
Exemplo n.º 27
0
 def expsFile(self):
     return os.path.join(userFolder(), 'rastercalcexpressions.json')
Exemplo n.º 28
0
 def logFilename():
     batchfile = userFolder() + os.sep + 'processing.log'
     return batchfile
Exemplo n.º 29
0
    def createGrass7Script(commands):
        folder = Grass7Utils.grassPath()
        shell = Grass7Utils.grassWinShell()

        script = Grass7Utils.grassScriptFilename()
        gisrc = userFolder(
        ) + os.sep + 'processing.gisrc7'  # FIXME: use temporary file

        # Temporary gisrc file
        output = open(gisrc, 'w')
        location = 'temp_location'
        gisdbase = Grass7Utils.grassDataFolder()

        output.write('GISDBASE: ' + gisdbase + '\n')
        output.write('LOCATION_NAME: ' + location + '\n')
        output.write('MAPSET: PERMANENT \n')
        output.write('GRASS_GUI: text\n')
        output.close()

        output = open(script, 'w')
        output.write('set HOME=' + os.path.expanduser('~') + '\n')
        output.write('set GISRC=' + gisrc + '\n')
        output.write('set GRASS_SH=' + shell + '\\bin\\sh.exe\n')
        output.write('set PATH=' + shell + os.sep + 'bin;' + shell + os.sep +
                     'lib;' + '%PATH%\n')
        output.write('set WINGISBASE=' + folder + '\n')
        output.write('set GISBASE=' + folder + '\n')
        output.write('set GRASS_PROJSHARE=' + folder + os.sep + 'share' +
                     os.sep + 'proj' + '\n')
        output.write('set GRASS_MESSAGE_FORMAT=gui\n')

        # Replacement code for etc/Init.bat
        output.write(
            'if "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\lib;%PATH%\n'
        )
        output.write(
            'if not "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\lib;%GRASS_ADDON_PATH%;%PATH%\n'
        )
        output.write('\n')
        output.write('set GRASS_VERSION=' + Grass7Utils.getGrassVersion() +
                     '\n')
        output.write('if not "%LANG%"=="" goto langset\n')
        output.write(
            'FOR /F "usebackq delims==" %%i IN (`"%WINGISBASE%\\etc\\winlocale"`) DO @set LANG=%%i\n'
        )
        output.write(':langset\n')
        output.write('\n')
        output.write('set PATHEXT=%PATHEXT%;.PY\n')
        output.write(
            'set PYTHONPATH=%PYTHONPATH%;%WINGISBASE%\\etc\\python;%WINGISBASE%\\etc\\wxpython\\n'
        )
        output.write('\n')
        output.write('g.gisenv.exe set="MAPSET=PERMANENT"\n')
        output.write('g.gisenv.exe set="LOCATION=' + location + '"\n')
        output.write('g.gisenv.exe set="LOCATION_NAME=' + location + '"\n')
        output.write('g.gisenv.exe set="GISDBASE=' + gisdbase + '"\n')
        output.write('g.gisenv.exe set="GRASS_GUI=text"\n')
        for command in commands:
            output.write(command.encode('utf8') + '\n')
        output.write('\n')
        output.write('exit\n')
        output.close()
Exemplo n.º 30
0
class RUtils(object):

    RSCRIPTS_FOLDER = 'R_SCRIPTS_FOLDER'
    R_FOLDER = 'R_FOLDER'
    R_USE64 = 'R_USE64'
    R_LIBS_USER = '******'

    rscriptfilename = os.path.join(userFolder(), 'processing_script.r')

    @staticmethod
    def RFolder():
        folder = ProcessingConfig.getSetting(RUtils.R_FOLDER)
        if folder is None:
            if isWindows():
                if 'ProgramW6432' in list(os.environ.keys()) and os.path.isdir(os.path.join(os.environ['ProgramW6432'], 'R')):
                    testfolder = os.path.join(os.environ['ProgramW6432'], 'R')
                elif 'PROGRAMFILES(x86)' in list(os.environ.keys()) and os.path.isdir(os.path.join(os.environ['PROGRAMFILES(x86)'], 'R')):
                    testfolder = os.path.join(os.environ['PROGRAMFILES(x86)'], 'R')
                elif 'PROGRAMFILES' in list(os.environ.keys()) and os.path.isdir(os.path.join(os.environ['PROGRAMFILES'], 'R')):
                    testfolder = os.path.join(os.environ['PROGRAMFILES'], 'R')
                else:
                    testfolder = 'C:\\R'

                if os.path.isdir(testfolder):
                    subfolders = os.listdir(testfolder)
                    subfolders.sort(reverse=True)
                    for subfolder in subfolders:
                        if subfolder.startswith('R-'):
                            folder = os.path.join(testfolder, subfolder)
                            break
                else:
                    folder = ''
            else:
                folder = ''

        return os.path.abspath(str(folder))

    @staticmethod
    def RLibs():
        folder = ProcessingConfig.getSetting(RUtils.R_LIBS_USER)
        if folder is None:
            folder = str(os.path.join(userFolder(), 'rlibs'))
        try:
            mkdir(folder)
        except:
            folder = str(os.path.join(userFolder(), 'rlibs'))
            mkdir(folder)
        return os.path.abspath(str(folder))

    @staticmethod
    def defaultRScriptsFolder():
        folder = str(os.path.join(userFolder(), 'rscripts'))
        mkdir(folder)
        return os.path.abspath(folder)

    @staticmethod
    def RScriptsFolders():
        folder = ProcessingConfig.getSetting(RUtils.RSCRIPTS_FOLDER)
        if folder is not None:
            return folder.split(';')
        else:
            return [RUtils.defaultRScriptsFolder()]

    @staticmethod
    def createRScriptFromRCommands(commands):
        with open(RUtils.getRScriptFilename(), 'w') as scriptfile:
            for command in commands:
                scriptfile.write(command + '\n')

    @staticmethod
    def getRScriptFilename():
        return RUtils.rscriptfilename

    @staticmethod
    def getConsoleOutputFilename():
        return RUtils.getRScriptFilename() + '.Rout'

    @staticmethod
    def executeRAlgorithm(alg, progress):
        # generate new R script file name in a temp folder
        RUtils.rscriptfilename = getTempFilenameInTempFolder('processing_script.r')
        # run commands
        RUtils.verboseCommands = alg.getVerboseCommands()
        RUtils.createRScriptFromRCommands(alg.getFullSetOfRCommands())
        if isWindows():
            if ProcessingConfig.getSetting(RUtils.R_USE64):
                execDir = 'x64'
            else:
                execDir = 'i386'
            command = [
                os.path.join(RUtils.RFolder(), 'bin', execDir, 'R.exe'),
                'CMD',
                'BATCH',
                '--vanilla',
                RUtils.getRScriptFilename(),
                RUtils.getConsoleOutputFilename()
            ]

        else:
            os.chmod(RUtils.getRScriptFilename(), stat.S_IEXEC | stat.S_IREAD
                     | stat.S_IWRITE)
            command = 'R CMD BATCH --vanilla ' + RUtils.getRScriptFilename() \
                + ' ' + RUtils.getConsoleOutputFilename()

        proc = subprocess.Popen(
            command,
            shell=True,
            stdout=subprocess.PIPE,
            stdin=subprocess.DEVNULL,
            stderr=subprocess.STDOUT,
            universal_newlines=True,
        )
        proc.wait()
        RUtils.createConsoleOutput()
        loglines = []
        loglines.append(RUtils.tr('R execution console output'))
        loglines += RUtils.allConsoleResults
        for line in loglines:
            progress.setConsoleInfo(line)
        ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)

    @staticmethod
    def createConsoleOutput():
        RUtils.consoleResults = []
        RUtils.allConsoleResults = []
        add = False
        if os.path.exists(RUtils.getConsoleOutputFilename()):
            with open(RUtils.getConsoleOutputFilename()) as lines:
                for line in lines:
                    line = line.strip().strip(' ')
                    if line.startswith('>'):
                        line = line[1:].strip(' ')
                        if line in RUtils.verboseCommands:
                            add = True
                        else:
                            add = False
                    elif add:
                        RUtils.consoleResults.append('<p>' + line + '</p>\n')
                    RUtils.allConsoleResults.append(line)

    @staticmethod
    def getConsoleOutput():
        s = '<font face="courier">\n'
        s += RUtils.tr('<h2>R Output</h2>\n')
        for line in RUtils.consoleResults:
            s += line
        s += '</font>\n'

        return s

    @staticmethod
    def checkRIsInstalled(ignoreRegistrySettings=False):
        if isWindows():
            path = RUtils.RFolder()
            if path == '':
                return RUtils.tr('R folder is not configured.\nPlease configure '
                                 'it before running R scripts.')

        R_INSTALLED = 'R_INSTALLED'
        settings = QSettings()
        if not ignoreRegistrySettings:
            if settings.contains(R_INSTALLED):
                return
        if isWindows():
            if ProcessingConfig.getSetting(RUtils.R_USE64):
                execDir = 'x64'
            else:
                execDir = 'i386'
            command = [os.path.join(RUtils.RFolder(), 'bin', execDir, 'R.exe'), '--version']
        else:
            command = ['R --version']
        proc = subprocess.Popen(
            command,
            shell=True,
            stdout=subprocess.PIPE,
            stdin=subprocess.DEVNULL,
            stderr=subprocess.STDOUT,
            universal_newlines=True,
        ).stdout

        for line in iter(proc.readline, ''):
            if 'R version' in line:
                settings.setValue(R_INSTALLED, True)
                return
        html = RUtils.tr(
            '<p>This algorithm requires R to be run. Unfortunately, it '
            'seems that R is not installed in your system, or it is not '
            'correctly configured to be used from QGIS</p>'
            '<p><a href="http://docs.qgis.org/testing/en/docs/user_manual/processing/3rdParty.html">Click here</a> '
            'to know more about how to install and configure R to be used with QGIS</p>')

        return html

    @staticmethod
    def getRequiredPackages(code):
        regex = re.compile('[^#]library\("?(.*?)"?\)')
        return regex.findall(code)

    @staticmethod
    def tr(string, context=''):
        if context == '':
            context = 'RUtils'
        return QCoreApplication.translate(context, string)
Exemplo n.º 31
0
 def defaultScriptsFolder():
     folder = str(os.path.join(userFolder(), 'scripts'))
     mkdir(folder)
     return os.path.abspath(folder)
Exemplo n.º 32
0
 def defaultRScriptsFolder():
     folder = unicode(os.path.join(userFolder(), 'rscripts'))
     mkdir(folder)
     return os.path.abspath(folder)
 def default_models_folder(self):
     """Return the default location of the processing models folder."""
     folder = Path(userFolder(), MODELS_PROCESSING_FOLDER)
     mkdir(str(folder))
     return str(folder)
Exemplo n.º 34
0
def preconfiguredAlgorithmsFolder():
    folder = str(os.path.join(userFolder(), 'preconfigured'))
    mkdir(folder)
    return folder
Exemplo n.º 35
0
 def getRScriptFilename():
     return userFolder() + os.sep + 'processing_script.r'
Exemplo n.º 36
0
def rliPath():
    """Return r.li GRASS7 user dir"""
    if isWindows():
        return path.join(userFolder(), 'GRASS7', 'r.li')
    else:
        return path.join(userFolder(), '.grass7', 'r.li')
Exemplo n.º 37
0
 def tempFileListFilepath():
     filename = 'fusion_files_list.txt'
     filepath = userFolder() + os.sep + filename
     return filepath
Exemplo n.º 38
0
 def commandsFolder(self):
     folder = str(os.path.join(userFolder(), 'commander'))
     mkdir(folder)
     return os.path.abspath(folder)
Exemplo n.º 39
0
 def default_models_folder(self):
     """Return the default location of the processing models folder."""
     folder = str(os.path.join(userFolder(), 'models'))
     mkdir(folder)
     return os.path.abspath(folder)
Exemplo n.º 40
0
 def logFilename():
     batchfile = userFolder() + os.sep + 'processing.log'
     return batchfile
Exemplo n.º 41
0
 def defaultRScriptsFolder():
     folder = unicode(os.path.join(userFolder(), 'rscripts'))
     mkdir(folder)
     return os.path.abspath(folder)
Exemplo n.º 42
0
 def defaultModelsFolder():
     folder = str(os.path.join(userFolder(), 'models'))
     mkdir(folder)
     return os.path.abspath(folder)
Exemplo n.º 43
0
 def defaultModelsFolder():
     folder = str(os.path.join(userFolder(), 'models'))
     mkdir(folder)
     return os.path.abspath(folder)
Exemplo n.º 44
0
 def tempFileListFilepath():
     filename = 'fusion_files_list.txt'
     filepath = userFolder() + os.sep + filename
     return filepath
Exemplo n.º 45
0
 def commandsFolder(self):
     folder = str(os.path.join(userFolder(), 'commander'))
     mkdir(folder)
     return os.path.abspath(folder)
Exemplo n.º 46
0
 def getRScriptFilename():
     return userFolder() + os.sep + 'processing_script.r'