VCS/ProjectHelper.py

changeset 3013
fe886b7f8f40
parent 2409
df3820f08247
child 3020
542e97d4ecb3
child 3057
10516539f238
equal deleted inserted replaced
3012:d177226027e2 3013:fe886b7f8f40
66 self.vcsNewAct.setStatusTip(self.trUtf8( 66 self.vcsNewAct.setStatusTip(self.trUtf8(
67 'Create a new project from the VCS repository' 67 'Create a new project from the VCS repository'
68 )) 68 ))
69 self.vcsNewAct.setWhatsThis(self.trUtf8( 69 self.vcsNewAct.setWhatsThis(self.trUtf8(
70 """<b>New from repository</b>""" 70 """<b>New from repository</b>"""
71 """<p>This creates a new local project from the VCS repository.</p>""" 71 """<p>This creates a new local project from the VCS"""
72 """ repository.</p>"""
72 )) 73 ))
73 self.vcsNewAct.triggered[()].connect(self._vcsCheckout) 74 self.vcsNewAct.triggered[()].connect(self._vcsCheckout)
74 self.actions.append(self.vcsNewAct) 75 self.actions.append(self.vcsNewAct)
75 76
76 self.vcsExportAct = E5Action(self.trUtf8('Export from repository'), 77 self.vcsExportAct = E5Action(
77 self.trUtf8('&Export from repository...'), 0, 0, self, 'vcs_export') 78 self.trUtf8('Export from repository'),
79 self.trUtf8('&Export from repository...'),
80 0, 0, self, 'vcs_export')
78 self.vcsExportAct.setStatusTip(self.trUtf8( 81 self.vcsExportAct.setStatusTip(self.trUtf8(
79 'Export a project from the repository' 82 'Export a project from the repository'
80 )) 83 ))
81 self.vcsExportAct.setWhatsThis(self.trUtf8( 84 self.vcsExportAct.setWhatsThis(self.trUtf8(
82 """<b>Export from repository</b>""" 85 """<b>Export from repository</b>"""
90 self.vcsAddAct.setStatusTip(self.trUtf8( 93 self.vcsAddAct.setStatusTip(self.trUtf8(
91 'Add the local project to the VCS repository' 94 'Add the local project to the VCS repository'
92 )) 95 ))
93 self.vcsAddAct.setWhatsThis(self.trUtf8( 96 self.vcsAddAct.setWhatsThis(self.trUtf8(
94 """<b>Add to repository</b>""" 97 """<b>Add to repository</b>"""
95 """<p>This adds (imports) the local project to the VCS repository.</p>""" 98 """<p>This adds (imports) the local project to the VCS"""
99 """ repository.</p>"""
96 )) 100 ))
97 self.vcsAddAct.triggered[()].connect(self._vcsImport) 101 self.vcsAddAct.triggered[()].connect(self._vcsImport)
98 self.actions.append(self.vcsAddAct) 102 self.actions.append(self.vcsAddAct)
99 103
100 def initMenu(self, menu): 104 def initMenu(self, menu):
162 self.project.pdata["VCS"] = [vcsSystem] 166 self.project.pdata["VCS"] = [vcsSystem]
163 self.project.vcs = self.project.initVCS(vcsSystem) 167 self.project.vcs = self.project.initVCS(vcsSystem)
164 # edit VCS command options 168 # edit VCS command options
165 vcores = E5MessageBox.yesNo(self.parent(), 169 vcores = E5MessageBox.yesNo(self.parent(),
166 self.trUtf8("New Project"), 170 self.trUtf8("New Project"),
167 self.trUtf8("""Would you like to edit the VCS command options?""")) 171 self.trUtf8(
172 """Would you like to edit the VCS command options?"""))
168 if vcores: 173 if vcores:
169 from .CommandOptionsDialog import vcsCommandOptionsDialog 174 from .CommandOptionsDialog import vcsCommandOptionsDialog
170 codlg = vcsCommandOptionsDialog(self.project.vcs) 175 codlg = vcsCommandOptionsDialog(self.project.vcs)
171 if codlg.exec_() == QDialog.Accepted: 176 if codlg.exec_() == QDialog.Accepted:
172 self.project.vcs.vcsSetOptions(codlg.getOptions()) 177 self.project.vcs.vcsSetOptions(codlg.getOptions())
176 try: 181 try:
177 os.makedirs(projectdir) 182 os.makedirs(projectdir)
178 except EnvironmentError: 183 except EnvironmentError:
179 E5MessageBox.critical(self.parent(), 184 E5MessageBox.critical(self.parent(),
180 self.trUtf8("Create project directory"), 185 self.trUtf8("Create project directory"),
181 self.trUtf8("<p>The project directory <b>{0}</b> could not" 186 self.trUtf8(
187 "<p>The project directory <b>{0}</b> could not"
182 " be created.</p>").format(projectdir)) 188 " be created.</p>").format(projectdir))
183 self.project.pdata["VCS"] = ['None'] 189 self.project.pdata["VCS"] = ['None']
184 self.project.vcs = self.project.initVCS() 190 self.project.vcs = self.project.initVCS()
185 return 191 return
186 192
187 # create the project from the VCS 193 # create the project from the VCS
188 self.project.vcs.vcsSetDataFromDict(vcsDataDict) 194 self.project.vcs.vcsSetDataFromDict(vcsDataDict)
189 if export: 195 if export:
190 ok = self.project.vcs.vcsExport(vcsDataDict, projectdir) 196 ok = self.project.vcs.vcsExport(vcsDataDict, projectdir)
191 else: 197 else:
192 ok = self.project.vcs.vcsCheckout(vcsDataDict, projectdir, False) 198 ok = self.project.vcs.vcsCheckout(vcsDataDict, projectdir,
199 False)
193 if ok: 200 if ok:
194 projectdir = os.path.normpath(projectdir) 201 projectdir = os.path.normpath(projectdir)
195 filters = ["*.e4p"] 202 filters = ["*.e4p"]
196 d = QDir(projectdir) 203 d = QDir(projectdir)
197 plist = d.entryInfoList(filters) 204 plist = d.entryInfoList(filters)
198 if len(plist): 205 if len(plist):
199 if len(plist) == 1: 206 if len(plist) == 1:
200 self.project.openProject(plist[0].absoluteFilePath()) 207 self.project.openProject(
208 plist[0].absoluteFilePath())
201 self.project.newProject.emit() 209 self.project.newProject.emit()
202 else: 210 else:
203 pfilenamelist = d.entryList(filters) 211 pfilenamelist = d.entryList(filters)
204 pfilename, ok = QInputDialog.getItem( 212 pfilename, ok = QInputDialog.getItem(
205 None, 213 None,
216 self.project.setDirty(True) 224 self.project.setDirty(True)
217 self.project.saveProject() 225 self.project.saveProject()
218 else: 226 else:
219 res = E5MessageBox.yesNo(self.parent(), 227 res = E5MessageBox.yesNo(self.parent(),
220 self.trUtf8("New project from repository"), 228 self.trUtf8("New project from repository"),
221 self.trUtf8("The project retrieved from the repository" 229 self.trUtf8(
230 "The project retrieved from the repository"
222 " does not contain an eric project file" 231 " does not contain an eric project file"
223 " (*.e4p). Create it?"), 232 " (*.e4p). Create it?"),
224 yesDefault=True) 233 yesDefault=True)
225 if res: 234 if res:
226 self.project.ppath = projectdir 235 self.project.ppath = projectdir
227 self.project.opened = True 236 self.project.opened = True
228 237
229 from Project.PropertiesDialog import PropertiesDialog 238 from Project.PropertiesDialog import \
239 PropertiesDialog
230 dlg = PropertiesDialog(self.project, False) 240 dlg = PropertiesDialog(self.project, False)
231 if dlg.exec_() == QDialog.Accepted: 241 if dlg.exec_() == QDialog.Accepted:
232 dlg.storeData() 242 dlg.storeData()
233 self.project.initFileTypes() 243 self.project.initFileTypes()
234 self.project.setDirty(True) 244 self.project.setDirty(True)
235 try: 245 try:
236 ms = os.path.join(self.project.ppath, 246 ms = os.path.join(
237 self.project.pdata["MAINSCRIPT"][0]) 247 self.project.ppath,
248 self.project.pdata["MAINSCRIPT"][0])
238 if os.path.exists(ms): 249 if os.path.exists(ms):
239 self.project.appendFile(ms) 250 self.project.appendFile(ms)
240 except IndexError: 251 except IndexError:
241 ms = "" 252 ms = ""
242 self.project.newProjectAddFiles(ms) 253 self.project.newProjectAddFiles(ms)
243 self.project.saveProject() 254 self.project.saveProject()
244 self.project.openProject(self.project.pfile) 255 self.project.openProject(self.project.pfile)
245 if not export: 256 if not export:
246 res = E5MessageBox.yesNo(self.parent(), 257 res = E5MessageBox.yesNo(
247 self.trUtf8("New project from repository"), 258 self.parent(),
248 self.trUtf8("Shall the project file be added to" 259 self.trUtf8(
249 " the repository?"), 260 "New project from repository"),
261 self.trUtf8(
262 "Shall the project file be added"
263 " to the repository?"),
250 yesDefault=True) 264 yesDefault=True)
251 if res: 265 if res:
252 self.project.vcs.vcsAdd(self.project.pfile) 266 self.project.vcs.vcsAdd(
267 self.project.pfile)
253 else: 268 else:
254 E5MessageBox.critical(self.parent(), 269 E5MessageBox.critical(
270 self.parent(),
255 self.trUtf8("New project from repository"), 271 self.trUtf8("New project from repository"),
256 self.trUtf8("""The project could not be retrieved from""" 272 self.trUtf8(
273 """The project could not be retrieved from"""
257 """ the repository.""")) 274 """ the repository."""))
258 self.project.pdata["VCS"] = ['None'] 275 self.project.pdata["VCS"] = ['None']
259 self.project.vcs = self.project.initVCS() 276 self.project.vcs = self.project.initVCS()
260 else: 277 else:
261 self.project.pdata["VCS"] = ['None'] 278 self.project.pdata["VCS"] = ['None']
271 """ 288 """
272 Protected slot used to import the local project into the repository. 289 Protected slot used to import the local project into the repository.
273 290
274 <b>NOTE</b>: 291 <b>NOTE</b>:
275 This does not necessarily make the local project a vcs controlled 292 This does not necessarily make the local project a vcs controlled
276 project. You may have to checkout the project from the repository in 293 project. You may have to checkout the project from the repository
277 order to accomplish that. 294 in order to accomplish that.
278 """ 295 """
279 def revertChanges(): 296 def revertChanges():
280 """ 297 """
281 Local function to revert the changes made to the project object. 298 Local function to revert the changes made to the project object.
282 """ 299 """
318 break 335 break
319 336
320 self.project.pdata["VCS"] = [vcsSystem] 337 self.project.pdata["VCS"] = [vcsSystem]
321 self.project.vcs = self.project.initVCS(vcsSystem) 338 self.project.vcs = self.project.initVCS(vcsSystem)
322 if self.project.vcs is not None: 339 if self.project.vcs is not None:
323 vcsdlg = self.project.vcs.vcsOptionsDialog(self.project, self.project.name, 1) 340 vcsdlg = self.project.vcs.vcsOptionsDialog(self.project,
341 self.project.name, 1)
324 if vcsdlg.exec_() == QDialog.Accepted: 342 if vcsdlg.exec_() == QDialog.Accepted:
325 vcsDataDict = vcsdlg.getData() 343 vcsDataDict = vcsdlg.getData()
326 # edit VCS command options 344 # edit VCS command options
327 vcores = E5MessageBox.yesNo(self.parent(), 345 vcores = E5MessageBox.yesNo(self.parent(),
328 self.trUtf8("Import Project"), 346 self.trUtf8("Import Project"),
329 self.trUtf8("""Would you like to edit the VCS command options?""")) 347 self.trUtf8(
348 """Would you like to edit the VCS command options?"""))
330 if vcores: 349 if vcores:
331 from .CommandOptionsDialog import vcsCommandOptionsDialog 350 from .CommandOptionsDialog import vcsCommandOptionsDialog
332 codlg = vcsCommandOptionsDialog(self.project.vcs) 351 codlg = vcsCommandOptionsDialog(self.project.vcs)
333 if codlg.exec_() == QDialog.Accepted: 352 if codlg.exec_() == QDialog.Accepted:
334 self.project.vcs.vcsSetOptions(codlg.getOptions()) 353 self.project.vcs.vcsSetOptions(codlg.getOptions())
335 self.project.setDirty(True) 354 self.project.setDirty(True)
336 self.project.vcs.vcsSetDataFromDict(vcsDataDict) 355 self.project.vcs.vcsSetDataFromDict(vcsDataDict)
337 self.project.saveProject() 356 self.project.saveProject()
338 isVcsControlled = \ 357 isVcsControlled = self.project.vcs.vcsImport(
339 self.project.vcs.vcsImport(vcsDataDict, self.project.ppath)[0] 358 vcsDataDict, self.project.ppath)[0]
340 if isVcsControlled: 359 if isVcsControlled:
341 # reopen the project 360 # reopen the project
342 self.project.openProject(self.project.pfile) 361 self.project.openProject(self.project.pfile)
343 else: 362 else:
344 # revert the changes to the local project 363 # revert the changes to the local project
361 if res: 380 if res:
362 self.project.reopenProject() 381 self.project.reopenProject()
363 382
364 def _vcsCommit(self): 383 def _vcsCommit(self):
365 """ 384 """
366 Protected slot used to commit changes to the local project to the repository. 385 Protected slot used to commit changes to the local project to the
386 repository.
367 """ 387 """
368 if Preferences.getVCS("AutoSaveProject"): 388 if Preferences.getVCS("AutoSaveProject"):
369 self.project.saveProject() 389 self.project.saveProject()
370 if Preferences.getVCS("AutoSaveFiles"): 390 if Preferences.getVCS("AutoSaveFiles"):
371 self.project.saveAllScripts() 391 self.project.saveAllScripts()
407 """ 427 """
408 self.vcs.vcsLog(self.project.ppath) 428 self.vcs.vcsLog(self.project.ppath)
409 429
410 def _vcsDiff(self): 430 def _vcsDiff(self):
411 """ 431 """
412 Protected slot used to show the difference of the local project to the repository. 432 Protected slot used to show the difference of the local project to
433 the repository.
413 """ 434 """
414 self.vcs.vcsDiff(self.project.ppath) 435 self.vcs.vcsDiff(self.project.ppath)
415 436
416 def _vcsStatus(self): 437 def _vcsStatus(self):
417 """ 438 """
444 if res: 465 if res:
445 self.project.reopenProject() 466 self.project.reopenProject()
446 467
447 def _vcsMerge(self): 468 def _vcsMerge(self):
448 """ 469 """
449 Protected slot used to merge changes of a tag/revision into the local project. 470 Protected slot used to merge changes of a tag/revision into the local
471 project.
450 """ 472 """
451 self.vcs.vcsMerge(self.project.ppath) 473 self.vcs.vcsMerge(self.project.ppath)
452 474
453 def _vcsCleanup(self): 475 def _vcsCleanup(self):
454 """ 476 """

eric ide

mercurial