Configure unconfigured system on project creation

Julien LepillerSat Aug 31 11:36:42+0200 2019

2c83329

Configure unconfigured system on project creation

offlate/manager.py

166166
            pass
167167
        self.projects = [x for x in self.projects if x['name'] != name]
168168
        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

143143
            print(resource['format'])
144144
            content[resource['filename']] = resource['format'].content()
145145
        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

8080
        project.mergerequests.create({'source_branch': 'translation',
8181
            'target_branch': self.branch, 'target_project_id': originproject.id,
8282
            '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

139139
                 'fullname': self.conf['fullname'],
140140
                 'lang': self.lang})
141141
        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

132132
            self.slugs.append(myslug)
133133
            content[slug['slug']] = myslug.content()
134134
        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

156156
        w.exec_()
157157
        if not w.wantNew():
158158
            return
159+
        res = self.manager.isConfigured(w.getProjectSystem())
160+
        if not res:
161+
            res = self.configureSystem(w.getProjectSystem())
162+
        if not res:
163+
            return
159164
        worker = NewRunnable(self, w.getProjectName(), w.getProjectLang(),
160165
                w.getProjectSystem(), w.getProjectInfo())
161166
        worker.signals.finished.connect(self.openProject)

170175
        w.exec_()
171176
        if not w.wantNew():
172177
            return
178+
        res = self.manager.isConfigured(w.getProjectSystem())
179+
        if not res:
180+
            res = self.configureSystem(w.getProjectSystem())
181+
        if not res:
182+
            return
173183
        worker = NewRunnable(self, w.getProjectName(), w.getProjectLang(),
174184
                w.getProjectSystem(), w.getProjectInfo())
175185
        worker.signals.finished.connect(self.openProject)

178188
        worker.signals.restart_required.connect(self.restartNew)
179189
        self.threadpool.start(worker)
180190
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+
181199
    def reportError(self, name, msg):
182200
        dialog = QMessageBox()
183201
        dialog.setText(msg)

offlate/ui/settings.py

2121
from .gitlabedit import GitlabEdit
2222
2323
class SettingsWindow(QDialog):
24-
    def __init__(self, preferences, parent = None):
24+
    def __init__(self, preferences, system = -1, parent = None):
2525
        super().__init__(parent)
2626
        self.data = preferences
2727
        self.done = False
28+
        self.system = system
2829
        self.initUI()
2930
3031
    def initUI(self):

4849
        cancel.clicked.connect(self.close)
4950
        ok.clicked.connect(self.ok)
5051
52+
        tab.setCurrentIndex(self.system + 1)
53+
5154
    def addTransifexTab(self, tab):
5255
        formBox = QGroupBox(self.tr("Transifex"))
5356
        formLayout = QFormLayout()