Project/Project.py

changeset 3038
7fe9a53280bd
parent 3034
7ce719013078
child 3060
5883ce99ee12
child 3126
df109651b577
equal deleted inserted replaced
3037:a417a0670a36 3038:7fe9a53280bd
181 "Mixed": Preferences.getPython("Python3Extensions") + ['.rb'], 181 "Mixed": Preferences.getPython("Python3Extensions") + ['.rb'],
182 } 182 }
183 183
184 self.dbgFilters = { 184 self.dbgFilters = {
185 "Python2": self.trUtf8( 185 "Python2": self.trUtf8(
186 "Python2 Files (*.py2);;" 186 "Python2 Files (*.py2);;"
187 "Python2 GUI Files (*.pyw2);;"), 187 "Python2 GUI Files (*.pyw2);;"),
188 "Python3": self.trUtf8( 188 "Python3": self.trUtf8(
189 "Python3 Files (*.py *.py3);;" 189 "Python3 Files (*.py *.py3);;"
190 "Python3 GUI Files (*.pyw *.pyw3);;"), 190 "Python3 GUI Files (*.pyw *.pyw3);;"),
191 "Ruby": self.trUtf8("Ruby Files (*.rb);;"), 191 "Ruby": self.trUtf8("Ruby Files (*.rb);;"),
192 } 192 }
193 193
194 self.vcsMenu = None 194 self.vcsMenu = None
195 195
314 self.ui, 314 self.ui,
315 self.trUtf8("Registering Project Type"), 315 self.trUtf8("Registering Project Type"),
316 self.trUtf8( 316 self.trUtf8(
317 """<p>The Programming Language <b>{0}</b> is not""" 317 """<p>The Programming Language <b>{0}</b> is not"""
318 """ supported.</p>""") 318 """ supported.</p>""")
319 .format(progLanguage) 319 .format(progLanguage)
320 ) 320 )
321 return 321 return
322 322
323 if type_ in self.__projectProgLanguages[progLanguage]: 323 if type_ in self.__projectProgLanguages[progLanguage]:
324 E5MessageBox.critical( 324 E5MessageBox.critical(
326 self.trUtf8("Registering Project Type"), 326 self.trUtf8("Registering Project Type"),
327 self.trUtf8( 327 self.trUtf8(
328 """<p>The Project type <b>{0}</b> is already""" 328 """<p>The Project type <b>{0}</b> is already"""
329 """ registered with Programming Language""" 329 """ registered with Programming Language"""
330 """ <b>{1}</b>.</p>""") 330 """ <b>{1}</b>.</p>""")
331 .format(type_, progLanguage) 331 .format(type_, progLanguage)
332 ) 332 )
333 return 333 return
334 334
335 if type_ in self.__projectTypes: 335 if type_ in self.__projectTypes:
336 E5MessageBox.critical( 336 E5MessageBox.critical(
670 E5MessageBox.critical( 670 E5MessageBox.critical(
671 self.ui, 671 self.ui,
672 self.trUtf8("Read project file"), 672 self.trUtf8("Read project file"),
673 self.trUtf8( 673 self.trUtf8(
674 "<p>The project file <b>{0}</b> could not be read.</p>") 674 "<p>The project file <b>{0}</b> could not be read.</p>")
675 .format(fn)) 675 .format(fn))
676 return False 676 return False
677 677
678 self.pfile = os.path.abspath(fn) 678 self.pfile = os.path.abspath(fn)
679 self.ppath = os.path.abspath(os.path.dirname(fn)) 679 self.ppath = os.path.abspath(os.path.dirname(fn))
680 680
706 self.__checkFilesExist("RESOURCES") 706 self.__checkFilesExist("RESOURCES")
707 self.__checkFilesExist("OTHERS") 707 self.__checkFilesExist("OTHERS")
708 708
709 # get the names of subdirectories the files are stored in 709 # get the names of subdirectories the files are stored in
710 for fn in self.pdata["SOURCES"] + \ 710 for fn in self.pdata["SOURCES"] + \
711 self.pdata["FORMS"] + \ 711 self.pdata["FORMS"] + \
712 self.pdata["INTERFACES"] + \ 712 self.pdata["INTERFACES"] + \
713 self.pdata["RESOURCES"] + \ 713 self.pdata["RESOURCES"] + \
714 self.pdata["TRANSLATIONS"]: 714 self.pdata["TRANSLATIONS"]:
715 dn = os.path.dirname(fn) 715 dn = os.path.dirname(fn)
716 if dn not in self.subdirs: 716 if dn not in self.subdirs:
717 self.subdirs.append(dn) 717 self.subdirs.append(dn)
718 718
719 # get the names of other subdirectories 719 # get the names of other subdirectories
972 E5MessageBox.critical( 972 E5MessageBox.critical(
973 self.ui, 973 self.ui,
974 self.trUtf8("Read tasks"), 974 self.trUtf8("Read tasks"),
975 self.trUtf8( 975 self.trUtf8(
976 "<p>The tasks file <b>{0}</b> could not be read.</p>") 976 "<p>The tasks file <b>{0}</b> could not be read.</p>")
977 .format(fn)) 977 .format(fn))
978 978
979 def writeTasks(self): 979 def writeTasks(self):
980 """ 980 """
981 Public method to write the tasks data to an XML file (.e4t). 981 Public method to write the tasks data to an XML file (.e4t).
982 """ 982 """
992 E5MessageBox.critical( 992 E5MessageBox.critical(
993 self.ui, 993 self.ui,
994 self.trUtf8("Save tasks"), 994 self.trUtf8("Save tasks"),
995 self.trUtf8( 995 self.trUtf8(
996 "<p>The tasks file <b>{0}</b> could not be written.</p>") 996 "<p>The tasks file <b>{0}</b> could not be written.</p>")
997 .format(fn)) 997 .format(fn))
998 return 998 return
999 999
1000 from E5XML.TasksWriter import TasksWriter 1000 from E5XML.TasksWriter import TasksWriter
1001 TasksWriter( 1001 TasksWriter(
1002 f, True, os.path.splitext(os.path.basename(fn))[0]).writeXML() 1002 f, True, os.path.splitext(os.path.basename(fn))[0]).writeXML()
1108 self.ui, 1108 self.ui,
1109 self.trUtf8("Delete debugger properties"), 1109 self.trUtf8("Delete debugger properties"),
1110 self.trUtf8( 1110 self.trUtf8(
1111 "<p>The project debugger properties file" 1111 "<p>The project debugger properties file"
1112 " <b>{0}</b> could not be deleted.</p>") 1112 " <b>{0}</b> could not be deleted.</p>")
1113 .format(fn)) 1113 .format(fn))
1114 1114
1115 def __initDebugProperties(self): 1115 def __initDebugProperties(self):
1116 """ 1116 """
1117 Private method to initialize the debug properties. 1117 Private method to initialize the debug properties.
1118 """ 1118 """
1242 def checkLanguageFiles(self): 1242 def checkLanguageFiles(self):
1243 """ 1243 """
1244 Public slot to check the language files after a release process. 1244 Public slot to check the language files after a release process.
1245 """ 1245 """
1246 tbPath = self.pdata["TRANSLATIONSBINPATH"] and \ 1246 tbPath = self.pdata["TRANSLATIONSBINPATH"] and \
1247 self.pdata["TRANSLATIONSBINPATH"][0] or "" 1247 self.pdata["TRANSLATIONSBINPATH"][0] or ""
1248 for langFile in self.pdata["TRANSLATIONS"][:]: 1248 for langFile in self.pdata["TRANSLATIONS"][:]:
1249 qmFile = self.__binaryTranslationFile(langFile) 1249 qmFile = self.__binaryTranslationFile(langFile)
1250 if qmFile: 1250 if qmFile:
1251 if qmFile not in self.pdata["TRANSLATIONS"] and \ 1251 if qmFile not in self.pdata["TRANSLATIONS"] and \
1252 os.path.exists(os.path.join(self.ppath, qmFile)): 1252 os.path.exists(os.path.join(self.ppath, qmFile)):
1445 self.ui, 1445 self.ui,
1446 self.trUtf8("Add file"), 1446 self.trUtf8("Add file"),
1447 self.trUtf8( 1447 self.trUtf8(
1448 "<p>The file <b>{0}</b> already" 1448 "<p>The file <b>{0}</b> already"
1449 " exists.</p><p>Overwrite it?</p>") 1449 " exists.</p><p>Overwrite it?</p>")
1450 .format(targetfile), 1450 .format(targetfile),
1451 icon=E5MessageBox.Warning) 1451 icon=E5MessageBox.Warning)
1452 if not res: 1452 if not res:
1453 return # don't overwrite 1453 return # don't overwrite
1454 1454
1455 shutil.copy(fn, target) 1455 shutil.copy(fn, target)
1459 self.trUtf8("Add file"), 1459 self.trUtf8("Add file"),
1460 self.trUtf8( 1460 self.trUtf8(
1461 "<p>The selected file <b>{0}</b> could" 1461 "<p>The selected file <b>{0}</b> could"
1462 " not be added to <b>{1}</b>.</p>" 1462 " not be added to <b>{1}</b>.</p>"
1463 "<p>Reason: {2}</p>") 1463 "<p>Reason: {2}</p>")
1464 .format(fn, target, str(why))) 1464 .format(fn, target, str(why)))
1465 continue 1465 continue
1466 1466
1467 self.appendFile(targetfile, isSource or filter == 'source') 1467 self.appendFile(targetfile, isSource or filter == 'source')
1468 else: 1468 else:
1469 E5MessageBox.critical( 1469 E5MessageBox.critical(
1514 self.ui, 1514 self.ui,
1515 self.trUtf8("Add directory"), 1515 self.trUtf8("Add directory"),
1516 self.trUtf8( 1516 self.trUtf8(
1517 "<p>The target directory <b>{0}</b> could not be" 1517 "<p>The target directory <b>{0}</b> could not be"
1518 " created.</p><p>Reason: {1}</p>") 1518 " created.</p><p>Reason: {1}</p>")
1519 .format(target, str(why))) 1519 .format(target, str(why)))
1520 return 1520 return
1521 1521
1522 for file in files: 1522 for file in files:
1523 for pattern in ignorePatterns: 1523 for pattern in ignorePatterns:
1524 if fnmatch.fnmatch(file, pattern): 1524 if fnmatch.fnmatch(file, pattern):
1532 self.ui, 1532 self.ui,
1533 self.trUtf8("Add directory"), 1533 self.trUtf8("Add directory"),
1534 self.trUtf8( 1534 self.trUtf8(
1535 "<p>The file <b>{0}</b> already exists.</p>" 1535 "<p>The file <b>{0}</b> already exists.</p>"
1536 "<p>Overwrite it?</p>") 1536 "<p>Overwrite it?</p>")
1537 .format(targetfile), 1537 .format(targetfile),
1538 icon=E5MessageBox.Warning) 1538 icon=E5MessageBox.Warning)
1539 if not res: 1539 if not res:
1540 continue # don't overwrite, carry on 1540 continue # don't overwrite, carry on
1541 # with next file 1541 # with next file
1542 1542
2045 self.ui, 2045 self.ui,
2046 self.trUtf8("Create project directory"), 2046 self.trUtf8("Create project directory"),
2047 self.trUtf8( 2047 self.trUtf8(
2048 "<p>The project directory <b>{0}</b> could not" 2048 "<p>The project directory <b>{0}</b> could not"
2049 " be created.</p>") 2049 " be created.</p>")
2050 .format(self.ppath)) 2050 .format(self.ppath))
2051 self.vcs = self.initVCS() 2051 self.vcs = self.initVCS()
2052 return 2052 return
2053 # create an empty __init__.py file to make it a Python package 2053 # create an empty __init__.py file to make it a Python package
2054 # (only for Python and Python3) 2054 # (only for Python and Python3)
2055 if self.pdata["PROGLANGUAGE"][0] in \ 2055 if self.pdata["PROGLANGUAGE"][0] in \
2103 self.ui, 2103 self.ui,
2104 self.trUtf8("Create main script"), 2104 self.trUtf8("Create main script"),
2105 self.trUtf8( 2105 self.trUtf8(
2106 "<p>The mainscript <b>{0}</b> could not" 2106 "<p>The mainscript <b>{0}</b> could not"
2107 " be created.<br/>Reason: {1}</p>") 2107 " be created.<br/>Reason: {1}</p>")
2108 .format(self.ppath, str(err))) 2108 .format(self.ppath, str(err)))
2109 self.appendFile(ms) 2109 self.appendFile(ms)
2110 except IndexError: 2110 except IndexError:
2111 ms = "" 2111 ms = ""
2112 2112
2113 # add existing files to the project 2113 # add existing files to the project
2288 tslist.extend(Utilities.direntries(tpd, True, pattern)) 2288 tslist.extend(Utilities.direntries(tpd, True, pattern))
2289 if tslist: 2289 if tslist:
2290 if '_' in os.path.basename(tslist[0]): 2290 if '_' in os.path.basename(tslist[0]):
2291 # the first entry determines the mainscript name 2291 # the first entry determines the mainscript name
2292 mainscriptname = os.path.splitext(mainscript)[0] or \ 2292 mainscriptname = os.path.splitext(mainscript)[0] or \
2293 os.path.basename(tslist[0]).split('_')[0] 2293 os.path.basename(tslist[0]).split('_')[0]
2294 self.pdata["TRANSLATIONPATTERN"] = \ 2294 self.pdata["TRANSLATIONPATTERN"] = \
2295 [os.path.join(os.path.dirname(tslist[0]), 2295 [os.path.join(os.path.dirname(tslist[0]),
2296 "{0}_%language%{1}".format( 2296 "{0}_%language%{1}".format(
2297 os.path.basename(tslist[0]).split('_')[0], 2297 os.path.basename(tslist[0]).split('_')[0],
2298 os.path.splitext(tslist[0])[1]))] 2298 os.path.splitext(tslist[0])[1]))]
2299 else: 2299 else:
2300 pattern, ok = QInputDialog.getText( 2300 pattern, ok = QInputDialog.getText(
2301 None, 2301 None,
2302 self.trUtf8("Translation Pattern"), 2302 self.trUtf8("Translation Pattern"),
2303 self.trUtf8( 2303 self.trUtf8(
2401 if (self.pdata["VCS"] and 2401 if (self.pdata["VCS"] and
2402 self.pdata["VCS"][0] != vcsSystem) or \ 2402 self.pdata["VCS"][0] != vcsSystem) or \
2403 (self.pudata["VCSOVERRIDE"] and 2403 (self.pudata["VCSOVERRIDE"] and
2404 self.pudata["VCSOVERRIDE"][0] != vcsSystemOverride) or \ 2404 self.pudata["VCSOVERRIDE"][0] != vcsSystemOverride) or \
2405 (vcsSystemOverride is not None and 2405 (vcsSystemOverride is not None and
2406 len(self.pudata["VCSOVERRIDE"]) == 0): 2406 len(self.pudata["VCSOVERRIDE"]) == 0):
2407 # stop the VCS monitor thread and shutdown VCS 2407 # stop the VCS monitor thread and shutdown VCS
2408 if self.vcs is not None: 2408 if self.vcs is not None:
2409 self.vcs.stopStatusMonitor() 2409 self.vcs.stopStatusMonitor()
2410 self.vcs.vcsShutdown() 2410 self.vcs.vcsShutdown()
2411 self.vcs.deleteLater() 2411 self.vcs.deleteLater()
2490 if fn is None: 2490 if fn is None:
2491 fn = E5FileDialog.getOpenFileName( 2491 fn = E5FileDialog.getOpenFileName(
2492 self.parent(), 2492 self.parent(),
2493 self.trUtf8("Open project"), 2493 self.trUtf8("Open project"),
2494 Preferences.getMultiProject("Workspace") or 2494 Preferences.getMultiProject("Workspace") or
2495 Utilities.getHomeDir(), 2495 Utilities.getHomeDir(),
2496 self.trUtf8("Project Files (*.e4p)")) 2496 self.trUtf8("Project Files (*.e4p)"))
2497 2497
2498 QApplication.processEvents() 2498 QApplication.processEvents()
2499 2499
2500 if fn: 2500 if fn:
2561 vcsSystem = vcsData[0][0] 2561 vcsSystem = vcsData[0][0]
2562 self.pdata["VCS"] = [vcsSystem] 2562 self.pdata["VCS"] = [vcsSystem]
2563 self.vcs = self.initVCS() 2563 self.vcs = self.initVCS()
2564 self.setDirty(True) 2564 self.setDirty(True)
2565 if self.vcs is not None and \ 2565 if self.vcs is not None and \
2566 (self.vcs.vcsRegisteredState(self.ppath) != 2566 (self.vcs.vcsRegisteredState(self.ppath) !=
2567 self.vcs.canBeCommitted): 2567 self.vcs.canBeCommitted):
2568 self.pdata["VCS"] = ['None'] 2568 self.pdata["VCS"] = ['None']
2569 self.vcs = self.initVCS() 2569 self.vcs = self.initVCS()
2570 self.closeAct.setEnabled(True) 2570 self.closeAct.setEnabled(True)
2571 self.saveasAct.setEnabled(True) 2571 self.saveasAct.setEnabled(True)
2667 defaultFilter = self.trUtf8("Project Files (*.e4p)") 2667 defaultFilter = self.trUtf8("Project Files (*.e4p)")
2668 if self.ppath: 2668 if self.ppath:
2669 defaultPath = self.ppath 2669 defaultPath = self.ppath
2670 else: 2670 else:
2671 defaultPath = Preferences.getMultiProject("Workspace") or \ 2671 defaultPath = Preferences.getMultiProject("Workspace") or \
2672 Utilities.getHomeDir() 2672 Utilities.getHomeDir()
2673 fn, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 2673 fn, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
2674 self.parent(), 2674 self.parent(),
2675 self.trUtf8("Save project as"), 2675 self.trUtf8("Save project as"),
2676 defaultPath, 2676 defaultPath,
2677 self.trUtf8("Project Files (*.e4p)"), 2677 self.trUtf8("Project Files (*.e4p)"),
4137 self.ui, 4137 self.ui,
4138 self.trUtf8("Version Control System"), 4138 self.trUtf8("Version Control System"),
4139 self.trUtf8( 4139 self.trUtf8(
4140 "<p>The selected VCS <b>{0}</b> could not be" 4140 "<p>The selected VCS <b>{0}</b> could not be"
4141 " found. <br/>Reverting override.</p><p>{1}</p>") 4141 " found. <br/>Reverting override.</p><p>{1}</p>")
4142 .format(vcsSystem, msg)) 4142 .format(vcsSystem, msg))
4143 self.pudata["VCSOVERRIDE"] = [] 4143 self.pudata["VCSOVERRIDE"] = []
4144 return self.initVCS(nooverride=True) 4144 return self.initVCS(nooverride=True)
4145 4145
4146 QApplication.restoreOverrideCursor() 4146 QApplication.restoreOverrideCursor()
4147 E5MessageBox.critical( 4147 E5MessageBox.critical(
4631 self.trUtf8("Create Plugin Archive"), 4631 self.trUtf8("Create Plugin Archive"),
4632 self.trUtf8( 4632 self.trUtf8(
4633 """<p>The file <b>{0}</b> could not be stored """ 4633 """<p>The file <b>{0}</b> could not be stored """
4634 """in the archive. Ignoring it.</p>""" 4634 """in the archive. Ignoring it.</p>"""
4635 """<p>Reason: {1}</p>""") 4635 """<p>Reason: {1}</p>""")
4636 .format(os.path.join(self.ppath, name), str(why))) 4636 .format(os.path.join(self.ppath, name), str(why)))
4637 archiveFile.writestr("VERSION", version.encode("utf-8")) 4637 archiveFile.writestr("VERSION", version.encode("utf-8"))
4638 archiveFile.close() 4638 archiveFile.close()
4639 4639
4640 if not archive in self.pdata["OTHERS"]: 4640 if not archive in self.pdata["OTHERS"]:
4641 self.appendFile(archive) 4641 self.appendFile(archive)
4645 UI.PixmapCache.getPixmap("pluginArchive48.png"), 4645 UI.PixmapCache.getPixmap("pluginArchive48.png"),
4646 self.trUtf8("Create Plugin Archive"), 4646 self.trUtf8("Create Plugin Archive"),
4647 self.trUtf8( 4647 self.trUtf8(
4648 """<p>The eric5 plugin archive file <b>{0}</b> was """ 4648 """<p>The eric5 plugin archive file <b>{0}</b> was """
4649 """created successfully.</p>""") 4649 """created successfully.</p>""")
4650 .format(os.path.basename(archive))) 4650 .format(os.path.basename(archive)))
4651 else: 4651 else:
4652 E5MessageBox.information( 4652 E5MessageBox.information(
4653 self.ui, 4653 self.ui,
4654 self.trUtf8("Create Plugin Archive"), 4654 self.trUtf8("Create Plugin Archive"),
4655 self.trUtf8( 4655 self.trUtf8(
4698 self.ui, 4698 self.ui,
4699 self.trUtf8("Create Plugin Archive"), 4699 self.trUtf8("Create Plugin Archive"),
4700 self.trUtf8("""<p>The plugin file <b>{0}</b> could """ 4700 self.trUtf8("""<p>The plugin file <b>{0}</b> could """
4701 """not be read.</p>""" 4701 """not be read.</p>"""
4702 """<p>Reason: {1}</p>""") 4702 """<p>Reason: {1}</p>""")
4703 .format(filename, str(why))) 4703 .format(filename, str(why)))
4704 return b"", "" 4704 return b"", ""
4705 4705
4706 lineno = 0 4706 lineno = 0
4707 while lineno < len(sourcelines): 4707 while lineno < len(sourcelines):
4708 if sourcelines[lineno].startswith("version = "): 4708 if sourcelines[lineno].startswith("version = "):
4710 datestr = time.strftime("%Y%m%d") 4710 datestr = time.strftime("%Y%m%d")
4711 lineend = sourcelines[lineno]\ 4711 lineend = sourcelines[lineno]\
4712 .replace(sourcelines[lineno].rstrip(), "") 4712 .replace(sourcelines[lineno].rstrip(), "")
4713 sversion = "{0}-snapshot-{1}".format( 4713 sversion = "{0}-snapshot-{1}".format(
4714 sourcelines[lineno].replace("version = ", "") 4714 sourcelines[lineno].replace("version = ", "")
4715 .strip()[1:-1], 4715 .strip()[1:-1],
4716 datestr) 4716 datestr)
4717 sourcelines[lineno] = '{0} + "-snapshot-{1}"{2}'.format( 4717 sourcelines[lineno] = '{0} + "-snapshot-{1}"{2}'.format(
4718 sourcelines[lineno].rstrip(), datestr, lineend) 4718 sourcelines[lineno].rstrip(), datestr, lineend)
4719 break 4719 break
4720 4720
4739 self.ui, 4739 self.ui,
4740 self.trUtf8("Create Plugin Archive"), 4740 self.trUtf8("Create Plugin Archive"),
4741 self.trUtf8( 4741 self.trUtf8(
4742 """<p>The plugin file <b>{0}</b> could """ 4742 """<p>The plugin file <b>{0}</b> could """
4743 """not be read.</p> <p>Reason: {1}</p>""") 4743 """not be read.</p> <p>Reason: {1}</p>""")
4744 .format(filename, str(why))) 4744 .format(filename, str(why)))
4745 return "" 4745 return ""
4746 4746
4747 for sourceline in sourcelines: 4747 for sourceline in sourcelines:
4748 if sourceline.startswith("version = "): 4748 if sourceline.startswith("version = "):
4749 version = sourceline.replace("version = ", "").strip()\ 4749 version = sourceline.replace("version = ", "").strip()\
4750 .replace('"', "").replace("'", "") 4750 .replace('"', "").replace("'", "")
4751 break 4751 break
4752 4752
4753 return version 4753 return version

eric ide

mercurial