forked from koordinates/kart-qgis-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial processing support for the Kart plugin
- Loading branch information
1 parent
b0fa22c
commit b469738
Showing
10 changed files
with
596 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from qgis.core import QgsProcessingProvider | ||
|
||
from kart.gui import icons | ||
|
||
from .branches import RepoCreateBranch, RepoDeleteBranch, RepoSwitchBranch | ||
from .data import RepoImportData | ||
from .remotes import RepoPullFromRemote, RepoPushToRemote | ||
from .repos import RepoClone, RepoInit | ||
from .tags import RepoCreateTag | ||
|
||
|
||
class KartProvider(QgsProcessingProvider): | ||
def loadAlgorithms(self, *args, **kwargs): | ||
|
||
self.addAlgorithm(RepoInit()) | ||
self.addAlgorithm(RepoClone()) | ||
self.addAlgorithm(RepoCreateTag()) | ||
self.addAlgorithm(RepoSwitchBranch()) | ||
self.addAlgorithm(RepoCreateBranch()) | ||
self.addAlgorithm(RepoDeleteBranch()) | ||
self.addAlgorithm(RepoImportData()) | ||
self.addAlgorithm(RepoPullFromRemote()) | ||
self.addAlgorithm(RepoPushToRemote()) | ||
|
||
def id(self, *args, **kwargs): | ||
return "Kart" | ||
|
||
def name(self, *args, **kwargs): | ||
return self.tr("Kart") | ||
|
||
def icon(self): | ||
return icons.kartIcon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from qgis.PyQt.QtCore import QCoreApplication | ||
from qgis.core import QgsProcessingAlgorithm | ||
|
||
|
||
class KartAlgorithm(QgsProcessingAlgorithm): | ||
def createInstance(self): | ||
return type(self)() | ||
|
||
def name(self): | ||
return f"kart_{self.__class__.__name__.lower()}" | ||
|
||
def tr(self, string): | ||
return QCoreApplication.translate("Processing", string) | ||
|
||
def initAlgorithm(self, config=None): | ||
return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
from qgis.core import QgsProcessingParameterFile, QgsProcessingParameterString | ||
from kart.gui import icons | ||
|
||
from .base import KartAlgorithm | ||
|
||
|
||
class RepoCreateBranch(KartAlgorithm): | ||
REPO_PATH = "REPO_PATH" | ||
REPO_BRANCH_NAME = "REPO_BRANCH_NAME" | ||
|
||
def displayName(self): | ||
return self.tr("Create Branch") | ||
|
||
def shortHelpString(self): | ||
return self.tr("Create a new branch") | ||
|
||
def icon(self): | ||
return icons.createBranchIcon | ||
|
||
def initAlgorithm(self, config=None): | ||
|
||
self.addParameter( | ||
QgsProcessingParameterFile( | ||
self.REPO_PATH, | ||
self.tr("Repo Path"), | ||
behavior=QgsProcessingParameterFile.Folder, | ||
) | ||
) | ||
|
||
self.addParameter( | ||
QgsProcessingParameterString( | ||
self.REPO_BRANCH_NAME, | ||
self.tr("Branch Name"), | ||
) | ||
) | ||
|
||
def processAlgorithm(self, parameters, context, feedback): | ||
from kart.kartapi import Repository | ||
|
||
repo_path = self.parameterAsFile(parameters, self.REPO_PATH, context) | ||
branch_name = self.parameterAsString(parameters, self.REPO_REFISH, context) | ||
|
||
repo = Repository(repo_path) | ||
repo.createBranch(branch_name) | ||
|
||
return { | ||
self.REPO_PATH: repo_path, | ||
} | ||
|
||
|
||
class RepoSwitchBranch(KartAlgorithm): | ||
REPO_PATH = "REPO_PATH" | ||
REPO_BRANCH_NAME = "REPO_BRANCH_NAME" | ||
|
||
def displayName(self): | ||
return self.tr("Switch to Branch") | ||
|
||
def shortHelpString(self): | ||
return self.tr("Switches to a named branch") | ||
|
||
def icon(self): | ||
return icons.checkoutIcon | ||
|
||
def initAlgorithm(self, config=None): | ||
|
||
self.addParameter( | ||
QgsProcessingParameterFile( | ||
self.REPO_PATH, | ||
self.tr("Repo Path"), | ||
behavior=QgsProcessingParameterFile.Folder, | ||
) | ||
) | ||
|
||
self.addParameter( | ||
QgsProcessingParameterString( | ||
self.REPO_BRANCH_NAME, | ||
self.tr("Branch Name"), | ||
) | ||
) | ||
|
||
def processAlgorithm(self, parameters, context, feedback): | ||
from kart.kartapi import Repository | ||
|
||
repo_path = self.parameterAsFile(parameters, self.REPO_PATH, context) | ||
branch_name = self.parameterAsString(parameters, self.REPO_BRANCH_NAME, context) | ||
|
||
repo = Repository(repo_path) | ||
repo.checkoutBranch(branch_name) | ||
|
||
return { | ||
self.REPO_PATH: repo_path, | ||
} | ||
|
||
|
||
class RepoDeleteBranch(KartAlgorithm): | ||
REPO_PATH = "REPO_PATH" | ||
REPO_BRANCH_NAME = "REPO_BRANCH_NAME" | ||
|
||
def displayName(self): | ||
return self.tr("Delete Branch") | ||
|
||
def shortHelpString(self): | ||
return self.tr("Delete a branch") | ||
|
||
def icon(self): | ||
return icons.deleteIcon | ||
|
||
def initAlgorithm(self, config=None): | ||
|
||
self.addParameter( | ||
QgsProcessingParameterFile( | ||
self.REPO_PATH, | ||
self.tr("Repo Path"), | ||
behavior=QgsProcessingParameterFile.Folder, | ||
) | ||
) | ||
|
||
self.addParameter( | ||
QgsProcessingParameterString( | ||
self.REPO_BRANCH_NAME, | ||
self.tr("Branch Name"), | ||
) | ||
) | ||
|
||
def processAlgorithm(self, parameters, context, feedback): | ||
from kart.kartapi import Repository | ||
|
||
repo_path = self.parameterAsFile(parameters, self.REPO_PATH, context) | ||
branch_name = self.parameterAsString(parameters, self.REPO_BRANCH_NAME, context) | ||
|
||
repo = Repository(repo_path) | ||
repo.deleteBranch(branch_name) | ||
|
||
return { | ||
self.REPO_PATH: repo_path, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from qgis.core import ( | ||
QgsProcessingParameterFile, | ||
QgsProcessingParameterString, | ||
QgsProcessingOutputFolder, | ||
) | ||
from kart.gui import icons | ||
|
||
from .base import KartAlgorithm | ||
|
||
|
||
class RepoImportData(KartAlgorithm): | ||
REPO_PATH = "REPO_PATH" | ||
REPO_DATA_PATH = "REPO_DATA_PATH" | ||
REPO_DATASET_NAME = "REPO_DATASET_NAME" | ||
|
||
def displayName(self): | ||
return self.tr("Import Data") | ||
|
||
def shortHelpString(self): | ||
return self.tr("Import data into a repository") | ||
|
||
def icon(self): | ||
return icons.importIcon | ||
|
||
def initAlgorithm(self, config=None): | ||
|
||
self.addParameter( | ||
QgsProcessingParameterFile( | ||
self.REPO_PATH, | ||
self.tr("Repo Path"), | ||
behavior=QgsProcessingParameterFile.Folder, | ||
) | ||
) | ||
|
||
self.addParameter( | ||
QgsProcessingParameterFile( | ||
self.REPO_DATA_PATH, | ||
self.tr("Data Path"), | ||
behavior=QgsProcessingParameterFile.File, | ||
) | ||
) | ||
|
||
self.addParameter( | ||
QgsProcessingParameterString( | ||
self.REPO_DATASET_NAME, | ||
self.tr("Dataset Name"), | ||
optional=True, | ||
) | ||
) | ||
|
||
self.addOutput( | ||
QgsProcessingOutputFolder( | ||
self.REPO_PATH, | ||
self.tr("Repo Path"), | ||
) | ||
) | ||
|
||
def processAlgorithm(self, parameters, context, feedback): | ||
from kart.kartapi import Repository | ||
|
||
repo_path = self.parameterAsFile(parameters, self.REPO_PATH, context) | ||
data_path = self.parameterAsFile(parameters, self.REPO_DATA_PATH, context) | ||
dataset_name = self.parameterAsString( | ||
parameters, self.REPO_DATASET_NAME, context | ||
) | ||
|
||
repo = Repository(repo_path) | ||
repo.importIntoRepo(data_path, dataset_name) | ||
|
||
return { | ||
self.REPO_PATH: repo_path, | ||
self.REPO_DATASET_NAME: dataset_name, | ||
} |
Oops, something went wrong.