mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-16 00:05:45 -04:00
support grass algorithms in profile folder
This commit is contained in:
parent
9eb449edcc
commit
f08e5e9469
@ -25,6 +25,7 @@ import re
|
||||
import uuid
|
||||
import math
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
|
||||
from qgis.PyQt.QtCore import QCoreApplication, QUrl
|
||||
|
||||
@ -139,11 +140,16 @@ class Grass7Algorithm(QgsProcessingAlgorithm):
|
||||
|
||||
# Use the ext mechanism
|
||||
name = self.name().replace('.', '_')
|
||||
self.module = None
|
||||
try:
|
||||
self.module = importlib.import_module(
|
||||
'grassprovider.ext.{}'.format(name))
|
||||
except ImportError:
|
||||
self.module = None
|
||||
extpath = Path(self.descriptionFile).parents[1].joinpath('ext', name + '.py')
|
||||
# this check makes it a bit faster
|
||||
if extpath.exists():
|
||||
spec = importlib.util.spec_from_file_location('grassprovider.ext.' + name, extpath)
|
||||
self.module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(self.module)
|
||||
except:
|
||||
pass
|
||||
|
||||
def createInstance(self):
|
||||
return self.__class__(self.descriptionFile)
|
||||
|
@ -31,11 +31,12 @@ from qgis.core import (Qgis,
|
||||
from processing.core.ProcessingConfig import (ProcessingConfig, Setting)
|
||||
from grassprovider.Grass7Utils import Grass7Utils
|
||||
from grassprovider.Grass7Algorithm import Grass7Algorithm
|
||||
from processing.tools.system import isWindows, isMac
|
||||
from processing.tools.system import isWindows, isMac, mkdir
|
||||
|
||||
|
||||
class Grass7AlgorithmProvider(QgsProcessingProvider):
|
||||
descriptionFolder = Grass7Utils.grassDescriptionPath()
|
||||
descriptionFolders = Grass7Utils.grassDescriptionFolders()
|
||||
mkdir(descriptionFolders[0])
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@ -85,18 +86,19 @@ class Grass7AlgorithmProvider(QgsProcessingProvider):
|
||||
|
||||
def createAlgsList(self):
|
||||
algs = []
|
||||
folder = self.descriptionFolder
|
||||
for descriptionFile in os.listdir(folder):
|
||||
if descriptionFile.endswith('txt'):
|
||||
try:
|
||||
alg = Grass7Algorithm(os.path.join(folder, descriptionFile))
|
||||
if alg.name().strip() != '':
|
||||
algs.append(alg)
|
||||
else:
|
||||
QgsMessageLog.logMessage(self.tr('Could not open GRASS GIS 7 algorithm: {0}').format(descriptionFile), self.tr('Processing'), Qgis.Critical)
|
||||
except Exception as e:
|
||||
QgsMessageLog.logMessage(
|
||||
self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(descriptionFile, str(e)), self.tr('Processing'), Qgis.Critical)
|
||||
folders = self.descriptionFolders
|
||||
for folder in folders:
|
||||
for descriptionFile in os.listdir(folder):
|
||||
if descriptionFile.endswith('txt'):
|
||||
try:
|
||||
alg = Grass7Algorithm(os.path.join(folder, descriptionFile))
|
||||
if alg.name().strip() != '':
|
||||
algs.append(alg)
|
||||
else:
|
||||
QgsMessageLog.logMessage(self.tr('Could not open GRASS GIS 7 algorithm: {0}').format(descriptionFile), self.tr('Processing'), Qgis.Critical)
|
||||
except Exception as e:
|
||||
QgsMessageLog.logMessage(
|
||||
self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(descriptionFile, str(e)), self.tr('Processing'), Qgis.Critical)
|
||||
return algs
|
||||
|
||||
def loadAlgorithms(self):
|
||||
|
@ -254,8 +254,8 @@ class Grass7Utils:
|
||||
return folder or ''
|
||||
|
||||
@staticmethod
|
||||
def grassDescriptionPath():
|
||||
return os.path.join(os.path.dirname(__file__), 'description')
|
||||
def grassDescriptionFolders():
|
||||
return [ os.path.join(userFolder(), 'grassaddons', 'description'), os.path.join(os.path.dirname(__file__), 'description')]
|
||||
|
||||
@staticmethod
|
||||
def getWindowsCodePage():
|
||||
|
Loading…
x
Reference in New Issue
Block a user