Configure unconfigured system on project creation
offlate/manager.py
| 166 | 166 | pass | |
| 167 | 167 | self.projects = [x for x in self.projects if x['name'] != name] | |
| 168 | 168 | return self.createProject(name, lang, system, info, callback) | |
| 169 | + | ||
| 170 | + | def isConfigured(self, system): | |
| 171 | + | if system == TRANSLATION_PROJECT: | |
| 172 | + | if not "TP" in self.settings.conf: | |
| 173 | + | self.settings.conf["TP"] = {} | |
| 174 | + | settings = self.settings.conf["TP"] | |
| 175 | + | for s in self.settings.conf["Generic"].keys(): | |
| 176 | + | settings[s] = self.settings.conf["Generic"][s] | |
| 177 | + | return TPProject.isConfigured(settings) | |
| 178 | + | elif system == TRANSIFEX: | |
| 179 | + | if not "Transifex" in self.settings.conf: | |
| 180 | + | self.settings.conf["Transifex"] = {} | |
| 181 | + | settings = self.settings.conf["Transifex"] | |
| 182 | + | for s in self.settings.conf["Generic"].keys(): | |
| 183 | + | settings[s] = self.settings.conf["Generic"][s] | |
| 184 | + | return TransifexProject.isConfigured(settings) | |
| 185 | + | elif system == GITLAB: | |
| 186 | + | if not "Gitlab" in self.settings.conf: | |
| 187 | + | self.settings.conf["Gitlab"] = {} | |
| 188 | + | settings = self.settings.conf["Gitlab"] | |
| 189 | + | for s in self.settings.conf["Generic"].keys(): | |
| 190 | + | settings[s] = self.settings.conf["Generic"][s] | |
| 191 | + | return GitlabProject.isConfigured(settings) | |
| 192 | + | else: | |
| 193 | + | return False |
offlate/systems/git.py
| 143 | 143 | print(resource['format']) | |
| 144 | 144 | content[resource['filename']] = resource['format'].content() | |
| 145 | 145 | return content | |
| 146 | + | ||
| 147 | + | @staticmethod | |
| 148 | + | def isConfigured(conf): | |
| 149 | + | return 'fullname' in conf and conf['fullname'] != '' and \ | |
| 150 | + | conf['fullname'] != None |
offlate/systems/gitlab.py
| 80 | 80 | project.mergerequests.create({'source_branch': 'translation', | |
| 81 | 81 | 'target_branch': self.branch, 'target_project_id': originproject.id, | |
| 82 | 82 | 'title': 'Update \'' + self.lang + '\' translation'}) | |
| 83 | + | ||
| 84 | + | @staticmethod | |
| 85 | + | def isConfigured(conf): | |
| 86 | + | res = GitProject.isConfigured(conf) | |
| 87 | + | res = res and 'servers' in conf and conf['servers'] != '' and \ | |
| 88 | + | conf['servers'] != None | |
| 89 | + | return res |
offlate/systems/tp.py
| 139 | 139 | 'fullname': self.conf['fullname'], | |
| 140 | 140 | 'lang': self.lang}) | |
| 141 | 141 | return {'default': self.po.content()} | |
| 142 | + | ||
| 143 | + | @staticmethod | |
| 144 | + | def isConfigured(conf): | |
| 145 | + | res = 'email' in conf and conf['email'] != '' and conf['email'] != None | |
| 146 | + | res = res and 'fullname' in conf and conf['fullname'] != '' and \ | |
| 147 | + | conf['fullname'] != None | |
| 148 | + | res = res and 'server' in conf and conf['server'] != '' and \ | |
| 149 | + | conf['server'] != None | |
| 150 | + | res = res and 'user' in conf and conf['user'] != '' and \ | |
| 151 | + | conf['user'] != None | |
| 152 | + | return res |
offlate/systems/transifex.py
| 132 | 132 | self.slugs.append(myslug) | |
| 133 | 133 | content[slug['slug']] = myslug.content() | |
| 134 | 134 | return content | |
| 135 | + | ||
| 136 | + | @staticmethod | |
| 137 | + | def isConfigured(conf): | |
| 138 | + | return 'token' in conf and conf['token'] != '' and conf['token'] != None |
offlate/ui/manager.py
| 156 | 156 | w.exec_() | |
| 157 | 157 | if not w.wantNew(): | |
| 158 | 158 | return | |
| 159 | + | res = self.manager.isConfigured(w.getProjectSystem()) | |
| 160 | + | if not res: | |
| 161 | + | res = self.configureSystem(w.getProjectSystem()) | |
| 162 | + | if not res: | |
| 163 | + | return | |
| 159 | 164 | worker = NewRunnable(self, w.getProjectName(), w.getProjectLang(), | |
| 160 | 165 | w.getProjectSystem(), w.getProjectInfo()) | |
| 161 | 166 | worker.signals.finished.connect(self.openProject) | |
… | |||
| 170 | 175 | w.exec_() | |
| 171 | 176 | if not w.wantNew(): | |
| 172 | 177 | return | |
| 178 | + | res = self.manager.isConfigured(w.getProjectSystem()) | |
| 179 | + | if not res: | |
| 180 | + | res = self.configureSystem(w.getProjectSystem()) | |
| 181 | + | if not res: | |
| 182 | + | return | |
| 173 | 183 | worker = NewRunnable(self, w.getProjectName(), w.getProjectLang(), | |
| 174 | 184 | w.getProjectSystem(), w.getProjectInfo()) | |
| 175 | 185 | worker.signals.finished.connect(self.openProject) | |
… | |||
| 178 | 188 | worker.signals.restart_required.connect(self.restartNew) | |
| 179 | 189 | self.threadpool.start(worker) | |
| 180 | 190 | ||
| 191 | + | def configureSystem(self, system): | |
| 192 | + | w = SettingsWindow(self.manager.getConf(), system) | |
| 193 | + | w.exec_() | |
| 194 | + | if w.done: | |
| 195 | + | self.manager.updateSettings(w.data) | |
| 196 | + | return True | |
| 197 | + | return False | |
| 198 | + | ||
| 181 | 199 | def reportError(self, name, msg): | |
| 182 | 200 | dialog = QMessageBox() | |
| 183 | 201 | dialog.setText(msg) | |
offlate/ui/settings.py
| 21 | 21 | from .gitlabedit import GitlabEdit | |
| 22 | 22 | ||
| 23 | 23 | class SettingsWindow(QDialog): | |
| 24 | - | def __init__(self, preferences, parent = None): | |
| 24 | + | def __init__(self, preferences, system = -1, parent = None): | |
| 25 | 25 | super().__init__(parent) | |
| 26 | 26 | self.data = preferences | |
| 27 | 27 | self.done = False | |
| 28 | + | self.system = system | |
| 28 | 29 | self.initUI() | |
| 29 | 30 | ||
| 30 | 31 | def initUI(self): | |
… | |||
| 48 | 49 | cancel.clicked.connect(self.close) | |
| 49 | 50 | ok.clicked.connect(self.ok) | |
| 50 | 51 | ||
| 52 | + | tab.setCurrentIndex(self.system + 1) | |
| 53 | + | ||
| 51 | 54 | def addTransifexTab(self, tab): | |
| 52 | 55 | formBox = QGroupBox(self.tr("Transifex")) | |
| 53 | 56 | formLayout = QFormLayout() | |