97 self.actions.append(self.migrateAvailabilityAct) |
97 self.actions.append(self.migrateAvailabilityAct) |
98 |
98 |
99 ######################################################### |
99 ######################################################### |
100 ## action to initialize the database migration system |
100 ## action to initialize the database migration system |
101 ######################################################### |
101 ######################################################### |
|
102 |
|
103 self.migrateInitAct = E5Action( |
|
104 self.tr('Initialize Migrations'), |
|
105 self.tr('&Initialize Migrations'), |
|
106 0, 0, |
|
107 self, 'flask_init_migrations') |
|
108 self.migrateInitAct.setStatusTip(self.tr( |
|
109 'Initialize support for database migrations')) |
|
110 self.migrateInitAct.setWhatsThis(self.tr( |
|
111 """<b>Initialize Migrations</b>""" |
|
112 """<p>Initializes the support for database migrations to be""" |
|
113 """ stored in the configured migrations directory.</p>""" |
|
114 )) |
|
115 self.migrateInitAct.triggered.connect( |
|
116 self.__initMigrations) |
|
117 self.actions.append(self.migrateInitAct) |
102 # TODO: add action for flask db init |
118 # TODO: add action for flask db init |
103 |
119 |
104 ######################################################### |
120 ######################################################### |
105 ## action to create a new database migration |
121 ## action to create a new database migration |
106 ######################################################### |
122 ######################################################### |
121 """ |
137 """ |
122 menu = QMenu(self.tr("Database")) |
138 menu = QMenu(self.tr("Database")) |
123 menu.setTearOffEnabled(True) |
139 menu.setTearOffEnabled(True) |
124 |
140 |
125 menu.addAction(self.migrateConfigAct) |
141 menu.addAction(self.migrateConfigAct) |
|
142 menu.addSeparator() |
|
143 menu.addAction(self.migrateInitAct) |
126 menu.addSeparator() |
144 menu.addSeparator() |
127 menu.addAction(self.migrateAvailabilityAct) |
145 menu.addAction(self.migrateAvailabilityAct) |
128 menu.addAction(self.migrateInstallAct) |
146 menu.addAction(self.migrateInstallAct) |
129 |
147 |
130 return menu |
148 return menu |
136 available = self.__flaskMigrateAvailable() |
154 available = self.__flaskMigrateAvailable() |
137 self.__project.setCapability("migrate", available) |
155 self.__project.setCapability("migrate", available) |
138 |
156 |
139 self.migrateConfigAct.setEnabled(available) |
157 self.migrateConfigAct.setEnabled(available) |
140 self.migrateInstallAct.setEnabled(not available) |
158 self.migrateInstallAct.setEnabled(not available) |
|
159 |
|
160 self.migrateInitAct.setEnabled(available) |
141 |
161 |
142 def __flaskMigrateAvailable(self): |
162 def __flaskMigrateAvailable(self): |
143 """ |
163 """ |
144 Private method to check, if the 'flask-babel' package is available. |
164 Private method to check, if the 'flask-babel' package is available. |
145 |
165 |
157 if finished and proc.exitCode() == 0: |
177 if finished and proc.exitCode() == 0: |
158 return True |
178 return True |
159 |
179 |
160 return False |
180 return False |
161 |
181 |
|
182 def __migrationsDirectory(self): |
|
183 """ |
|
184 Private method to calculate the path of the configured migrations |
|
185 directory. |
|
186 |
|
187 @return path of the migrations directory |
|
188 @rtype str |
|
189 """ |
|
190 migrations = "" |
|
191 |
|
192 self.__ensureMigrateConfigured() |
|
193 |
|
194 migrations = self.__project.getData("migrate", |
|
195 "migrationsDirectory") |
|
196 if migrations: |
|
197 workdir = self.__project.getApplication()[0] |
|
198 migrations = os.path.relpath( |
|
199 self.__e5project.getAbsoluteUniversalPath(migrations), |
|
200 workdir |
|
201 ) |
|
202 |
|
203 return migrations |
|
204 |
162 ######################################################## |
205 ######################################################## |
163 ## Menu related slots below |
206 ## Menu related slots below |
164 ######################################################## |
207 ######################################################## |
165 |
208 |
166 @pyqtSlot() |
209 @pyqtSlot() |
233 |
273 |
234 ######################################################### |
274 ######################################################### |
235 ## slot to initialize the database migration system |
275 ## slot to initialize the database migration system |
236 ######################################################### |
276 ######################################################### |
237 |
277 |
|
278 @pyqtSlot() |
|
279 def __initMigrations(self): |
|
280 """ |
|
281 Private slot to initialize the database migration system. |
|
282 """ |
|
283 self.__ensureMigrateConfigured() |
|
284 migrations = self.__migrationsDirectory() |
|
285 |
|
286 args = ["init"] |
|
287 if migrations: |
|
288 args += ["--directory", migrations] |
|
289 |
|
290 multidb = E5MessageBox.yesNo( |
|
291 None, |
|
292 self.tr("Multiple Databases"), |
|
293 self.tr("""Shall the support for multiple databases be""" |
|
294 """ activated?""")) |
|
295 if multidb: |
|
296 args.append("--multidb") |
|
297 |
|
298 dlg = FlaskCommandDialog( |
|
299 self.__project, title=self.tr("Initialize Migrations")) |
|
300 if dlg.startCommand("db", args): |
|
301 dlg.exec() |
|
302 |
238 ######################################################### |
303 ######################################################### |
239 ## slot to create a new database migration |
304 ## slot to create a new database migration |
240 ######################################################### |
305 ######################################################### |
241 |
306 |
242 ######################################################### |
307 ######################################################### |