38 """ |
38 """ |
39 super(MigrateProject, self).__init__(parent) |
39 super(MigrateProject, self).__init__(parent) |
40 |
40 |
41 self.__plugin = plugin |
41 self.__plugin = plugin |
42 self.__project = project |
42 self.__project = project |
|
43 |
|
44 self.__e5project = e5App().getObject("Project") |
43 |
45 |
44 def initActions(self): |
46 def initActions(self): |
45 """ |
47 """ |
46 Public method to define the flask-migrate actions. |
48 Public method to define the flask-migrate actions. |
47 """ |
49 """ |
177 if finished and proc.exitCode() == 0: |
179 if finished and proc.exitCode() == 0: |
178 return True |
180 return True |
179 |
181 |
180 return False |
182 return False |
181 |
183 |
182 def __migrationsDirectory(self): |
184 def __migrationsDirectory(self, abspath=False): |
183 """ |
185 """ |
184 Private method to calculate the path of the configured migrations |
186 Private method to calculate the path of the configured migrations |
185 directory. |
187 directory. |
186 |
188 |
|
189 @param abspath flag indicating to return an absolute path |
|
190 @type bool |
187 @return path of the migrations directory |
191 @return path of the migrations directory |
188 @rtype str |
192 @rtype str |
189 """ |
193 """ |
190 migrations = "" |
194 migrations = "" |
191 |
195 |
192 self.__ensureMigrateConfigured() |
196 self.__ensureMigrateConfigured() |
193 |
197 |
194 migrations = self.__project.getData("migrate", |
198 migrations = self.__project.getData("migrate", |
195 "migrationsDirectory") |
199 "migrationsDirectory") |
196 if migrations: |
200 if migrations: |
197 workdir = self.__project.getApplication()[0] |
201 if abspath: |
198 migrations = os.path.relpath( |
202 migrations = self.__e5project.getAbsoluteUniversalPath( |
199 self.__e5project.getAbsoluteUniversalPath(migrations), |
203 migrations) |
200 workdir |
204 else: |
201 ) |
205 workdir = self.__project.getApplication()[0] |
|
206 migrations = os.path.relpath( |
|
207 self.__e5project.getAbsoluteUniversalPath(migrations), |
|
208 workdir |
|
209 ) |
|
210 else: |
|
211 if abspath: |
|
212 migrations = self.__e5project.getAbsoluteUniversalPath( |
|
213 "migrations") |
202 |
214 |
203 return migrations |
215 return migrations |
204 |
216 |
205 ######################################################## |
217 ######################################################## |
206 ## Menu related slots below |
218 ## Menu related slots below |
221 self.__project.setData("migrate", "", config) |
233 self.__project.setData("migrate", "", config) |
222 |
234 |
223 def __ensureMigrateConfigured(self): |
235 def __ensureMigrateConfigured(self): |
224 """ |
236 """ |
225 Private method to ensure, that flask-migrate has been configured. |
237 Private method to ensure, that flask-migrate has been configured. |
226 |
|
227 @return flag indicating successful configuration |
|
228 @rtype bool |
|
229 """ |
238 """ |
230 config = self.__project.getData("migrate", "") |
239 config = self.__project.getData("migrate", "") |
231 if not config: |
240 if not config: |
232 self.__configureMigrate() |
241 self.__configureMigrate() |
233 |
242 |
294 """ activated?""")) |
305 """ activated?""")) |
295 if multidb: |
306 if multidb: |
296 args.append("--multidb") |
307 args.append("--multidb") |
297 |
308 |
298 dlg = FlaskCommandDialog( |
309 dlg = FlaskCommandDialog( |
299 self.__project, title=self.tr("Initialize Migrations")) |
310 self.__project, title=title, |
|
311 msgSuccess=self.tr("\nMigrations initialized successfully.") |
|
312 ) |
300 if dlg.startCommand("db", args): |
313 if dlg.startCommand("db", args): |
301 dlg.exec() |
314 dlg.exec() |
|
315 if dlg.normalExit(): |
|
316 for root, _dirs, files in os.walk( |
|
317 self.__migrationsDirectory(abspath=True) |
|
318 ): |
|
319 for fileName in files: |
|
320 fullName = os.path.join(root, fileName) |
|
321 self.__e5project.appendFile(fullName) |
|
322 |
|
323 browser = (e5App().getObject("ProjectBrowser") |
|
324 .getProjectBrowser("others")) |
|
325 alembic = os.path.join( |
|
326 self.__migrationsDirectory(abspath=True), |
|
327 "alembic.ini" |
|
328 ) |
|
329 browser.sourceFile.emit(alembic) |
302 |
330 |
303 ######################################################### |
331 ######################################################### |
304 ## slot to create a new database migration |
332 ## slot to create a new database migration |
305 ######################################################### |
333 ######################################################### |
306 |
334 |