VCS/ProjectHelper.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3349
2a034a7f1f54
child 3656
441956d8fce5
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
11 11
12 import os 12 import os
13 import shutil 13 import shutil
14 import copy 14 import copy
15 15
16 from PyQt4.QtCore import QDir, QFileInfo, QObject 16 from PyQt4.QtCore import pyqtSlot, QDir, QFileInfo, QObject
17 from PyQt4.QtGui import QDialog, QInputDialog 17 from PyQt4.QtGui import QDialog, QInputDialog
18 18
19 from E5Gui.E5Action import E5Action 19 from E5Gui.E5Action import E5Action
20 from E5Gui import E5MessageBox 20 from E5Gui import E5MessageBox
21 from E5Gui.E5Application import e5App 21 from E5Gui.E5Application import e5App
62 def initActions(self): 62 def initActions(self):
63 """ 63 """
64 Public method to generate the action objects. 64 Public method to generate the action objects.
65 """ 65 """
66 self.vcsNewAct = E5Action( 66 self.vcsNewAct = E5Action(
67 self.trUtf8('New from repository'), 67 self.tr('New from repository'),
68 self.trUtf8('&New from repository...'), 68 self.tr('&New from repository...'),
69 0, 0, self, 'vcs_new') 69 0, 0, self, 'vcs_new')
70 self.vcsNewAct.setStatusTip(self.trUtf8( 70 self.vcsNewAct.setStatusTip(self.tr(
71 'Create a new project from the VCS repository' 71 'Create a new project from the VCS repository'
72 )) 72 ))
73 self.vcsNewAct.setWhatsThis(self.trUtf8( 73 self.vcsNewAct.setWhatsThis(self.tr(
74 """<b>New from repository</b>""" 74 """<b>New from repository</b>"""
75 """<p>This creates a new local project from the VCS""" 75 """<p>This creates a new local project from the VCS"""
76 """ repository.</p>""" 76 """ repository.</p>"""
77 )) 77 ))
78 self.vcsNewAct.triggered[()].connect(self._vcsCheckout) 78 self.vcsNewAct.triggered.connect(self._vcsCheckout)
79 self.actions.append(self.vcsNewAct) 79 self.actions.append(self.vcsNewAct)
80 80
81 self.vcsExportAct = E5Action( 81 self.vcsExportAct = E5Action(
82 self.trUtf8('Export from repository'), 82 self.tr('Export from repository'),
83 self.trUtf8('&Export from repository...'), 83 self.tr('&Export from repository...'),
84 0, 0, self, 'vcs_export') 84 0, 0, self, 'vcs_export')
85 self.vcsExportAct.setStatusTip(self.trUtf8( 85 self.vcsExportAct.setStatusTip(self.tr(
86 'Export a project from the repository' 86 'Export a project from the repository'
87 )) 87 ))
88 self.vcsExportAct.setWhatsThis(self.trUtf8( 88 self.vcsExportAct.setWhatsThis(self.tr(
89 """<b>Export from repository</b>""" 89 """<b>Export from repository</b>"""
90 """<p>This exports a project from the repository.</p>""" 90 """<p>This exports a project from the repository.</p>"""
91 )) 91 ))
92 self.vcsExportAct.triggered[()].connect(self._vcsExport) 92 self.vcsExportAct.triggered.connect(self._vcsExport)
93 self.actions.append(self.vcsExportAct) 93 self.actions.append(self.vcsExportAct)
94 94
95 self.vcsAddAct = E5Action( 95 self.vcsAddAct = E5Action(
96 self.trUtf8('Add to repository'), 96 self.tr('Add to repository'),
97 self.trUtf8('&Add to repository...'), 97 self.tr('&Add to repository...'),
98 0, 0, self, 'vcs_add') 98 0, 0, self, 'vcs_add')
99 self.vcsAddAct.setStatusTip(self.trUtf8( 99 self.vcsAddAct.setStatusTip(self.tr(
100 'Add the local project to the VCS repository' 100 'Add the local project to the VCS repository'
101 )) 101 ))
102 self.vcsAddAct.setWhatsThis(self.trUtf8( 102 self.vcsAddAct.setWhatsThis(self.tr(
103 """<b>Add to repository</b>""" 103 """<b>Add to repository</b>"""
104 """<p>This adds (imports) the local project to the VCS""" 104 """<p>This adds (imports) the local project to the VCS"""
105 """ repository.</p>""" 105 """ repository.</p>"""
106 )) 106 ))
107 self.vcsAddAct.triggered[()].connect(self._vcsImport) 107 self.vcsAddAct.triggered.connect(self._vcsImport)
108 self.actions.append(self.vcsAddAct) 108 self.actions.append(self.vcsAddAct)
109 109
110 def initMenu(self, menu): 110 def initMenu(self, menu):
111 """ 111 """
112 Public method to generate the VCS menu. 112 Public method to generate the VCS menu.
125 """ 125 """
126 Public slot called before the vcs menu is shown. 126 Public slot called before the vcs menu is shown.
127 """ 127 """
128 if self.vcsAddAct: 128 if self.vcsAddAct:
129 self.vcsAddAct.setEnabled(self.project.isOpen()) 129 self.vcsAddAct.setEnabled(self.project.isOpen())
130 130
131 @pyqtSlot()
131 def _vcsCheckout(self, export=False): 132 def _vcsCheckout(self, export=False):
132 """ 133 """
133 Protected slot used to create a local project from the repository. 134 Protected slot used to create a local project from the repository.
134 135
135 @param export flag indicating whether an export or a checkout 136 @param export flag indicating whether an export or a checkout
148 keys = sorted(vcsSystemsDict.keys()) 149 keys = sorted(vcsSystemsDict.keys())
149 for key in keys: 150 for key in keys:
150 vcsSystemsDisplay.append(vcsSystemsDict[key]) 151 vcsSystemsDisplay.append(vcsSystemsDict[key])
151 vcsSelected, ok = QInputDialog.getItem( 152 vcsSelected, ok = QInputDialog.getItem(
152 None, 153 None,
153 self.trUtf8("New Project"), 154 self.tr("New Project"),
154 self.trUtf8("Select version control system for the project"), 155 self.tr("Select version control system for the project"),
155 vcsSystemsDisplay, 156 vcsSystemsDisplay,
156 0, False) 157 0, False)
157 if not ok: 158 if not ok:
158 return 159 return
159 for vcsSystem, vcsSystemDisplay in list(vcsSystemsDict.items()): 160 for vcsSystem, vcsSystemDisplay in list(vcsSystemsDict.items()):
170 if vcsdlg.exec_() == QDialog.Accepted: 171 if vcsdlg.exec_() == QDialog.Accepted:
171 projectdir, vcsDataDict = vcsdlg.getData() 172 projectdir, vcsDataDict = vcsdlg.getData()
172 self.project.pdata["VCS"] = [vcsSystem] 173 self.project.pdata["VCS"] = [vcsSystem]
173 self.project.vcs = self.project.initVCS(vcsSystem) 174 self.project.vcs = self.project.initVCS(vcsSystem)
174 # edit VCS command options 175 # edit VCS command options
175 vcores = E5MessageBox.yesNo( 176 if self.project.vcs.vcsSupportCommandOptions():
176 self.parent(), 177 vcores = E5MessageBox.yesNo(
177 self.trUtf8("New Project"), 178 self.parent(),
178 self.trUtf8( 179 self.tr("New Project"),
179 """Would you like to edit the VCS command options?""")) 180 self.tr(
181 """Would you like to edit the VCS command"""
182 """ options?"""))
183 else:
184 vcores = False
180 if vcores: 185 if vcores:
181 from .CommandOptionsDialog import VcsCommandOptionsDialog 186 from .CommandOptionsDialog import VcsCommandOptionsDialog
182 codlg = VcsCommandOptionsDialog(self.project.vcs) 187 codlg = VcsCommandOptionsDialog(self.project.vcs)
183 if codlg.exec_() == QDialog.Accepted: 188 if codlg.exec_() == QDialog.Accepted:
184 self.project.vcs.vcsSetOptions(codlg.getOptions()) 189 self.project.vcs.vcsSetOptions(codlg.getOptions())
188 try: 193 try:
189 os.makedirs(projectdir) 194 os.makedirs(projectdir)
190 except EnvironmentError: 195 except EnvironmentError:
191 E5MessageBox.critical( 196 E5MessageBox.critical(
192 self.parent(), 197 self.parent(),
193 self.trUtf8("Create project directory"), 198 self.tr("Create project directory"),
194 self.trUtf8( 199 self.tr(
195 "<p>The project directory <b>{0}</b> could not" 200 "<p>The project directory <b>{0}</b> could not"
196 " be created.</p>").format(projectdir)) 201 " be created.</p>").format(projectdir))
197 self.project.pdata["VCS"] = ['None'] 202 self.project.pdata["VCS"] = ['None']
198 self.project.vcs = self.project.initVCS() 203 self.project.vcs = self.project.initVCS()
199 return 204 return
217 self.project.newProject.emit() 222 self.project.newProject.emit()
218 else: 223 else:
219 pfilenamelist = d.entryList(filters) 224 pfilenamelist = d.entryList(filters)
220 pfilename, ok = QInputDialog.getItem( 225 pfilename, ok = QInputDialog.getItem(
221 None, 226 None,
222 self.trUtf8("New project from repository"), 227 self.tr("New project from repository"),
223 self.trUtf8("Select a project file to open."), 228 self.tr("Select a project file to open."),
224 pfilenamelist, 0, False) 229 pfilenamelist, 0, False)
225 if ok: 230 if ok:
226 self.project.openProject( 231 self.project.openProject(
227 QFileInfo(d, pfilename).absoluteFilePath()) 232 QFileInfo(d, pfilename).absoluteFilePath())
228 self.project.newProject.emit() 233 self.project.newProject.emit()
232 self.project.setDirty(True) 237 self.project.setDirty(True)
233 self.project.saveProject() 238 self.project.saveProject()
234 else: 239 else:
235 res = E5MessageBox.yesNo( 240 res = E5MessageBox.yesNo(
236 self.parent(), 241 self.parent(),
237 self.trUtf8("New project from repository"), 242 self.tr("New project from repository"),
238 self.trUtf8( 243 self.tr(
239 "The project retrieved from the repository" 244 "The project retrieved from the repository"
240 " does not contain an eric project file" 245 " does not contain an eric project file"
241 " (*.e4p). Create it?"), 246 " (*.e4p). Create it?"),
242 yesDefault=True) 247 yesDefault=True)
243 if res: 248 if res:
264 self.project.saveProject() 269 self.project.saveProject()
265 self.project.openProject(self.project.pfile) 270 self.project.openProject(self.project.pfile)
266 if not export: 271 if not export:
267 res = E5MessageBox.yesNo( 272 res = E5MessageBox.yesNo(
268 self.parent(), 273 self.parent(),
269 self.trUtf8( 274 self.tr(
270 "New project from repository"), 275 "New project from repository"),
271 self.trUtf8( 276 self.tr(
272 "Shall the project file be added" 277 "Shall the project file be added"
273 " to the repository?"), 278 " to the repository?"),
274 yesDefault=True) 279 yesDefault=True)
275 if res: 280 if res:
276 self.project.vcs.vcsAdd( 281 self.project.vcs.vcsAdd(
277 self.project.pfile) 282 self.project.pfile)
278 else: 283 else:
279 E5MessageBox.critical( 284 E5MessageBox.critical(
280 self.parent(), 285 self.parent(),
281 self.trUtf8("New project from repository"), 286 self.tr("New project from repository"),
282 self.trUtf8( 287 self.tr(
283 """The project could not be retrieved from""" 288 """The project could not be retrieved from"""
284 """ the repository.""")) 289 """ the repository."""))
285 self.project.pdata["VCS"] = ['None'] 290 self.project.pdata["VCS"] = ['None']
286 self.project.vcs = self.project.initVCS() 291 self.project.vcs = self.project.initVCS()
287 else: 292 else:
332 keys = sorted(list(vcsSystemsDict.keys())) 337 keys = sorted(list(vcsSystemsDict.keys()))
333 for key in keys: 338 for key in keys:
334 vcsSystemsDisplay.append(vcsSystemsDict[key]) 339 vcsSystemsDisplay.append(vcsSystemsDict[key])
335 vcsSelected, ok = QInputDialog.getItem( 340 vcsSelected, ok = QInputDialog.getItem(
336 None, 341 None,
337 self.trUtf8("Import Project"), 342 self.tr("Import Project"),
338 self.trUtf8("Select version control system for the project"), 343 self.tr("Select version control system for the project"),
339 vcsSystemsDisplay, 344 vcsSystemsDisplay,
340 0, False) 345 0, False)
341 if not ok: 346 if not ok:
342 return 347 return
343 for vcsSystem, vcsSystemDisplay in list(vcsSystemsDict.items()): 348 for vcsSystem, vcsSystemDisplay in list(vcsSystemsDict.items()):
350 vcsdlg = self.project.vcs.vcsOptionsDialog(self.project, 355 vcsdlg = self.project.vcs.vcsOptionsDialog(self.project,
351 self.project.name, 1) 356 self.project.name, 1)
352 if vcsdlg.exec_() == QDialog.Accepted: 357 if vcsdlg.exec_() == QDialog.Accepted:
353 vcsDataDict = vcsdlg.getData() 358 vcsDataDict = vcsdlg.getData()
354 # edit VCS command options 359 # edit VCS command options
355 vcores = E5MessageBox.yesNo( 360 if self.project.vcs.vcsSupportCommandOptions():
356 self.parent(), 361 vcores = E5MessageBox.yesNo(
357 self.trUtf8("Import Project"), 362 self.parent(),
358 self.trUtf8( 363 self.tr("Import Project"),
359 """Would you like to edit the VCS command options?""")) 364 self.tr(
365 """Would you like to edit the VCS command"""
366 """ options?"""))
367 else:
368 vcores = False
360 if vcores: 369 if vcores:
361 from .CommandOptionsDialog import VcsCommandOptionsDialog 370 from .CommandOptionsDialog import VcsCommandOptionsDialog
362 codlg = VcsCommandOptionsDialog(self.project.vcs) 371 codlg = VcsCommandOptionsDialog(self.project.vcs)
363 if codlg.exec_() == QDialog.Accepted: 372 if codlg.exec_() == QDialog.Accepted:
364 self.project.vcs.vcsSetOptions(codlg.getOptions()) 373 self.project.vcs.vcsSetOptions(codlg.getOptions())
384 """ 393 """
385 shouldReopen = self.vcs.vcsUpdate(self.project.ppath) 394 shouldReopen = self.vcs.vcsUpdate(self.project.ppath)
386 if shouldReopen: 395 if shouldReopen:
387 res = E5MessageBox.yesNo( 396 res = E5MessageBox.yesNo(
388 self.parent(), 397 self.parent(),
389 self.trUtf8("Update"), 398 self.tr("Update"),
390 self.trUtf8("""The project should be reread. Do this now?"""), 399 self.tr("""The project should be reread. Do this now?"""),
391 yesDefault=True) 400 yesDefault=True)
392 if res: 401 if res:
393 self.project.reopenProject() 402 self.project.reopenProject()
394 403
395 def _vcsCommit(self): 404 def _vcsCommit(self):
410 Depending on the parameters set in the vcs object the project 419 Depending on the parameters set in the vcs object the project
411 may be removed from the local disk as well. 420 may be removed from the local disk as well.
412 """ 421 """
413 res = E5MessageBox.yesNo( 422 res = E5MessageBox.yesNo(
414 self.parent(), 423 self.parent(),
415 self.trUtf8("Remove project from repository"), 424 self.tr("Remove project from repository"),
416 self.trUtf8( 425 self.tr(
417 "Dou you really want to remove this project from" 426 "Dou you really want to remove this project from"
418 " the repository (and disk)?")) 427 " the repository (and disk)?"))
419 if res: 428 if res:
420 self.vcs.vcsRemove(self.project.ppath, True) 429 self.vcs.vcsRemove(self.project.ppath, True)
421 self._vcsCommit() 430 self._vcsCommit()
427 436
428 def _vcsCommandOptions(self): 437 def _vcsCommandOptions(self):
429 """ 438 """
430 Protected slot to edit the VCS command options. 439 Protected slot to edit the VCS command options.
431 """ 440 """
432 from .CommandOptionsDialog import VcsCommandOptionsDialog 441 if self.vcs.vcsSupportCommandOptions():
433 codlg = VcsCommandOptionsDialog(self.vcs) 442 from .CommandOptionsDialog import VcsCommandOptionsDialog
434 if codlg.exec_() == QDialog.Accepted: 443 codlg = VcsCommandOptionsDialog(self.vcs)
435 self.vcs.vcsSetOptions(codlg.getOptions()) 444 if codlg.exec_() == QDialog.Accepted:
436 self.project.setDirty(True) 445 self.vcs.vcsSetOptions(codlg.getOptions())
446 self.project.setDirty(True)
437 447
438 def _vcsLog(self): 448 def _vcsLog(self):
439 """ 449 """
440 Protected slot used to show the log of the local project. 450 Protected slot used to show the log of the local project.
441 """ 451 """
442 self.vcs.vcsLog(self.project.ppath) 452 self.vcs.vcsLog(self.project.ppath)
453
454 def _vcsLogBrowser(self):
455 """
456 Protected slot used to show the log of the local project with a
457 log browser dialog.
458 """
459 self.vcs.vcsLogBrowser(self.project.ppath)
443 460
444 def _vcsDiff(self): 461 def _vcsDiff(self):
445 """ 462 """
446 Protected slot used to show the difference of the local project to 463 Protected slot used to show the difference of the local project to
447 the repository. 464 the repository.
472 """ 489 """
473 shouldReopen = self.vcs.vcsSwitch(self.project.ppath) 490 shouldReopen = self.vcs.vcsSwitch(self.project.ppath)
474 if shouldReopen: 491 if shouldReopen:
475 res = E5MessageBox.yesNo( 492 res = E5MessageBox.yesNo(
476 self.parent(), 493 self.parent(),
477 self.trUtf8("Switch"), 494 self.tr("Switch"),
478 self.trUtf8("""The project should be reread. Do this now?"""), 495 self.tr("""The project should be reread. Do this now?"""),
479 yesDefault=True) 496 yesDefault=True)
480 if res: 497 if res:
481 self.project.reopenProject() 498 self.project.reopenProject()
482 499
483 def _vcsMerge(self): 500 def _vcsMerge(self):

eric ide

mercurial