|
| 1 | +from qgis.core import QgsProcessingParameterFile, QgsProcessingParameterString |
| 2 | +from kart.gui import icons |
| 3 | + |
| 4 | +from .base import KartAlgorithm |
| 5 | + |
| 6 | + |
| 7 | +class RepoCreateBranch(KartAlgorithm): |
| 8 | + REPO_PATH = "REPO_PATH" |
| 9 | + REPO_BRANCH_NAME = "REPO_BRANCH_NAME" |
| 10 | + |
| 11 | + def displayName(self): |
| 12 | + return self.tr("Create Branch") |
| 13 | + |
| 14 | + def shortHelpString(self): |
| 15 | + return self.tr("Create a new branch") |
| 16 | + |
| 17 | + def icon(self): |
| 18 | + return icons.createBranchIcon |
| 19 | + |
| 20 | + def initAlgorithm(self, config=None): |
| 21 | + |
| 22 | + self.addParameter( |
| 23 | + QgsProcessingParameterFile( |
| 24 | + self.REPO_PATH, |
| 25 | + self.tr("Repo Path"), |
| 26 | + behavior=QgsProcessingParameterFile.Folder, |
| 27 | + ) |
| 28 | + ) |
| 29 | + |
| 30 | + self.addParameter( |
| 31 | + QgsProcessingParameterString( |
| 32 | + self.REPO_BRANCH_NAME, |
| 33 | + self.tr("Branch Name"), |
| 34 | + ) |
| 35 | + ) |
| 36 | + |
| 37 | + def processAlgorithm(self, parameters, context, feedback): |
| 38 | + from kart.kartapi import Repository |
| 39 | + |
| 40 | + repo_path = self.parameterAsFile(parameters, self.REPO_PATH, context) |
| 41 | + branch_name = self.parameterAsString(parameters, self.REPO_BRANCH_NAME, context) |
| 42 | + |
| 43 | + repo = Repository(repo_path) |
| 44 | + repo.createBranch(branch_name) |
| 45 | + |
| 46 | + return { |
| 47 | + self.REPO_PATH: repo_path, |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | +class RepoSwitchBranch(KartAlgorithm): |
| 52 | + REPO_PATH = "REPO_PATH" |
| 53 | + REPO_BRANCH_NAME = "REPO_BRANCH_NAME" |
| 54 | + |
| 55 | + def displayName(self): |
| 56 | + return self.tr("Switch to Branch") |
| 57 | + |
| 58 | + def shortHelpString(self): |
| 59 | + return self.tr("Switches to a named branch") |
| 60 | + |
| 61 | + def icon(self): |
| 62 | + return icons.checkoutIcon |
| 63 | + |
| 64 | + def initAlgorithm(self, config=None): |
| 65 | + |
| 66 | + self.addParameter( |
| 67 | + QgsProcessingParameterFile( |
| 68 | + self.REPO_PATH, |
| 69 | + self.tr("Repo Path"), |
| 70 | + behavior=QgsProcessingParameterFile.Folder, |
| 71 | + ) |
| 72 | + ) |
| 73 | + |
| 74 | + self.addParameter( |
| 75 | + QgsProcessingParameterString( |
| 76 | + self.REPO_BRANCH_NAME, |
| 77 | + self.tr("Branch Name"), |
| 78 | + ) |
| 79 | + ) |
| 80 | + |
| 81 | + def processAlgorithm(self, parameters, context, feedback): |
| 82 | + from kart.kartapi import Repository |
| 83 | + |
| 84 | + repo_path = self.parameterAsFile(parameters, self.REPO_PATH, context) |
| 85 | + branch_name = self.parameterAsString(parameters, self.REPO_BRANCH_NAME, context) |
| 86 | + |
| 87 | + repo = Repository(repo_path) |
| 88 | + repo.checkoutBranch(branch_name) |
| 89 | + |
| 90 | + return { |
| 91 | + self.REPO_PATH: repo_path, |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | +class RepoDeleteBranch(KartAlgorithm): |
| 96 | + REPO_PATH = "REPO_PATH" |
| 97 | + REPO_BRANCH_NAME = "REPO_BRANCH_NAME" |
| 98 | + |
| 99 | + def displayName(self): |
| 100 | + return self.tr("Delete Branch") |
| 101 | + |
| 102 | + def shortHelpString(self): |
| 103 | + return self.tr("Delete a branch") |
| 104 | + |
| 105 | + def icon(self): |
| 106 | + return icons.deleteIcon |
| 107 | + |
| 108 | + def initAlgorithm(self, config=None): |
| 109 | + |
| 110 | + self.addParameter( |
| 111 | + QgsProcessingParameterFile( |
| 112 | + self.REPO_PATH, |
| 113 | + self.tr("Repo Path"), |
| 114 | + behavior=QgsProcessingParameterFile.Folder, |
| 115 | + ) |
| 116 | + ) |
| 117 | + |
| 118 | + self.addParameter( |
| 119 | + QgsProcessingParameterString( |
| 120 | + self.REPO_BRANCH_NAME, |
| 121 | + self.tr("Branch Name"), |
| 122 | + ) |
| 123 | + ) |
| 124 | + |
| 125 | + def processAlgorithm(self, parameters, context, feedback): |
| 126 | + from kart.kartapi import Repository |
| 127 | + |
| 128 | + repo_path = self.parameterAsFile(parameters, self.REPO_PATH, context) |
| 129 | + branch_name = self.parameterAsString(parameters, self.REPO_BRANCH_NAME, context) |
| 130 | + |
| 131 | + repo = Repository(repo_path) |
| 132 | + repo.deleteBranch(branch_name) |
| 133 | + |
| 134 | + return { |
| 135 | + self.REPO_PATH: repo_path, |
| 136 | + } |
0 commit comments