Project/Project.py

changeset 5099
175b36822cc9
parent 5098
bc74f74a95f5
child 5100
2c193da9b94f
equal deleted inserted replaced
5098:bc74f74a95f5 5099:175b36822cc9
404 self.dbgAutoClearShell = True 404 self.dbgAutoClearShell = True
405 self.dbgTracePython = False 405 self.dbgTracePython = False
406 self.dbgAutoContinue = True 406 self.dbgAutoContinue = True
407 407
408 self.pdata = { 408 self.pdata = {
409 # TODO: change these to use lists only where neccessary 409 "DESCRIPTION": "",
410 "DESCRIPTION": [], 410 "VERSION": "",
411 "VERSION": [],
412 "SOURCES": [], 411 "SOURCES": [],
413 "FORMS": [], 412 "FORMS": [],
414 "RESOURCES": [], 413 "RESOURCES": [],
415 "INTERFACES": [], 414 "INTERFACES": [],
416 "OTHERS": [], 415 "OTHERS": [],
417 "TRANSLATIONS": [], 416 "TRANSLATIONS": [],
418 "TRANSLATIONPATTERN": [],
419 "TRANSLATIONSBINPATH": [],
420 "TRANSLATIONEXCEPTIONS": [], 417 "TRANSLATIONEXCEPTIONS": [],
421 "MAINSCRIPT": [], 418 "TRANSLATIONPATTERN": "",
422 "VCS": [], 419 "TRANSLATIONSBINPATH": "",
423 "VCSOPTIONS": [], 420 "MAINSCRIPT": "",
424 "VCSOTHERDATA": [], 421 "VCS": "None",
422 "VCSOPTIONS": {},
423 "VCSOTHERDATA": {},
424 # TODO: change these to use lists only where neccessary
425 "AUTHOR": [''], 425 "AUTHOR": [''],
426 "EMAIL": [''], 426 "EMAIL": [''],
427 "HASH": [''], 427 "HASH": [''],
428 "PROGLANGUAGE": ["Python3"], 428 "PROGLANGUAGE": ["Python3"],
429 "MIXEDLANGUAGE": [False], 429 "MIXEDLANGUAGE": [False],
437 "PROJECTTYPESPECIFICDATA": {}, 437 "PROJECTTYPESPECIFICDATA": {},
438 "CHECKERSPARMS": {}, 438 "CHECKERSPARMS": {},
439 "PACKAGERSPARMS": {}, 439 "PACKAGERSPARMS": {},
440 "DOCUMENTATIONPARMS": {}, 440 "DOCUMENTATIONPARMS": {},
441 "OTHERTOOLSPARMS": {}, 441 "OTHERTOOLSPARMS": {},
442 "EOL": [-1], 442 "EOL": -1,
443 } 443 }
444 444
445 self.__initDebugProperties() 445 self.__initDebugProperties()
446 446
447 self.pudata = { 447 self.pudata = {
706 706
707 # insert filename into list of recently opened projects 707 # insert filename into list of recently opened projects
708 self.__syncRecent() 708 self.__syncRecent()
709 709
710 if res: 710 if res:
711 if len(self.pdata["TRANSLATIONPATTERN"]) == 1: 711 if self.pdata["TRANSLATIONPATTERN"]:
712 self.translationsRoot = \ 712 self.translationsRoot = \
713 self.pdata["TRANSLATIONPATTERN"][0].split("%language%")[0] 713 self.pdata["TRANSLATIONPATTERN"].split("%language%")[0]
714 elif len(self.pdata["MAINSCRIPT"]) == 1: 714 elif self.pdata["MAINSCRIPT"]:
715 self.translationsRoot = os.path.splitext( 715 self.translationsRoot = os.path.splitext(
716 self.pdata["MAINSCRIPT"][0])[0] 716 self.pdata["MAINSCRIPT"])[0]
717 if os.path.isdir(os.path.join(self.ppath, self.translationsRoot)): 717 if os.path.isdir(os.path.join(self.ppath, self.translationsRoot)):
718 dn = self.translationsRoot 718 dn = self.translationsRoot
719 else: 719 else:
720 dn = os.path.dirname(self.translationsRoot) 720 dn = os.path.dirname(self.translationsRoot)
721 if dn not in self.subdirs: 721 if dn not in self.subdirs:
769 is used instead of the one in the project object. This is the 769 is used instead of the one in the project object. This is the
770 'save as' action. 770 'save as' action.
771 @return flag indicating success 771 @return flag indicating success
772 """ 772 """
773 if self.vcs is not None: 773 if self.vcs is not None:
774 self.pdata["VCSOPTIONS"] = [ 774 self.pdata["VCSOPTIONS"] = \
775 copy.deepcopy(self.vcs.vcsGetOptions())] 775 copy.deepcopy(self.vcs.vcsGetOptions())
776 self.pdata["VCSOTHERDATA"] = [ 776 self.pdata["VCSOTHERDATA"] = \
777 copy.deepcopy(self.vcs.vcsGetOtherData())] 777 copy.deepcopy(self.vcs.vcsGetOtherData())
778 778
779 if not self.pdata["HASH"][0]: 779 if not self.pdata["HASH"][0]:
780 hash = str(QCryptographicHash.hash( 780 hash = str(QCryptographicHash.hash(
781 QByteArray(self.ppath.encode("utf-8")), 781 QByteArray(self.ppath.encode("utf-8")),
782 QCryptographicHash.Sha1).toHex(), 782 QCryptographicHash.Sha1).toHex(),
1237 """ 1237 """
1238 Public method to get the translation pattern. 1238 Public method to get the translation pattern.
1239 1239
1240 @return translation pattern (string) 1240 @return translation pattern (string)
1241 """ 1241 """
1242 if self.pdata["TRANSLATIONPATTERN"]: 1242 return self.pdata["TRANSLATIONPATTERN"]
1243 return self.pdata["TRANSLATIONPATTERN"][0]
1244 else:
1245 return ""
1246 1243
1247 def setTranslationPattern(self, pattern): 1244 def setTranslationPattern(self, pattern):
1248 """ 1245 """
1249 Public method to set the translation pattern. 1246 Public method to set the translation pattern.
1250 1247
1251 @param pattern translation pattern 1248 @param pattern translation pattern
1252 @type str 1249 @type str
1253 """ 1250 """
1254 if pattern: 1251 self.pdata["TRANSLATIONPATTERN"] = pattern
1255 self.pdata["TRANSLATIONPATTERN"] = [pattern]
1256 else:
1257 self.pdata["TRANSLATIONPATTERN"] = []
1258 1252
1259 def addLanguage(self): 1253 def addLanguage(self):
1260 """ 1254 """
1261 Public slot used to add a language to the project. 1255 Public slot used to add a language to the project.
1262 """ 1256 """
1263 if len(self.pdata["TRANSLATIONPATTERN"]) == 0 or \ 1257 if not self.pdata["TRANSLATIONPATTERN"]:
1264 self.pdata["TRANSLATIONPATTERN"][0] == '':
1265 E5MessageBox.critical( 1258 E5MessageBox.critical(
1266 self.ui, 1259 self.ui,
1267 self.tr("Add Language"), 1260 self.tr("Add Language"),
1268 self.tr( 1261 self.tr(
1269 "You have to specify a translation pattern first.")) 1262 "You have to specify a translation pattern first."))
1274 if dlg.exec_() == QDialog.Accepted: 1267 if dlg.exec_() == QDialog.Accepted:
1275 lang = dlg.getSelectedLanguage() 1268 lang = dlg.getSelectedLanguage()
1276 if self.pdata["PROJECTTYPE"][0] in \ 1269 if self.pdata["PROJECTTYPE"][0] in \
1277 ["Qt4", "Qt4C", "PyQt5", "PyQt5C", "E6Plugin", 1270 ["Qt4", "Qt4C", "PyQt5", "PyQt5C", "E6Plugin",
1278 "PySide", "PySideC"]: 1271 "PySide", "PySideC"]:
1279 langFile = self.pdata["TRANSLATIONPATTERN"][0]\ 1272 langFile = self.pdata["TRANSLATIONPATTERN"]\
1280 .replace("%language%", lang) 1273 .replace("%language%", lang)
1281 self.appendFile(langFile) 1274 self.appendFile(langFile)
1282 self.projectLanguageAddedByCode.emit(lang) 1275 self.projectLanguageAddedByCode.emit(lang)
1283 1276
1284 def __binaryTranslationFile(self, langFile): 1277 def __binaryTranslationFile(self, langFile):
1303 1296
1304 def checkLanguageFiles(self): 1297 def checkLanguageFiles(self):
1305 """ 1298 """
1306 Public slot to check the language files after a release process. 1299 Public slot to check the language files after a release process.
1307 """ 1300 """
1308 tbPath = self.pdata["TRANSLATIONSBINPATH"] and \ 1301 tbPath = self.pdata["TRANSLATIONSBINPATH"]
1309 self.pdata["TRANSLATIONSBINPATH"][0] or ""
1310 for langFile in self.pdata["TRANSLATIONS"][:]: 1302 for langFile in self.pdata["TRANSLATIONS"][:]:
1311 qmFile = self.__binaryTranslationFile(langFile) 1303 qmFile = self.__binaryTranslationFile(langFile)
1312 if qmFile: 1304 if qmFile:
1313 if qmFile not in self.pdata["TRANSLATIONS"] and \ 1305 if qmFile not in self.pdata["TRANSLATIONS"] and \
1314 os.path.exists(os.path.join(self.ppath, qmFile)): 1306 os.path.exists(os.path.join(self.ppath, qmFile)):
1333 self.__model.removeItem(langFile) 1325 self.__model.removeItem(langFile)
1334 if qmFile: 1326 if qmFile:
1335 try: 1327 try:
1336 if self.pdata["TRANSLATIONSBINPATH"]: 1328 if self.pdata["TRANSLATIONSBINPATH"]:
1337 qmFile = self.getRelativePath( 1329 qmFile = self.getRelativePath(
1338 os.path.join(self.pdata["TRANSLATIONSBINPATH"][0], 1330 os.path.join(self.pdata["TRANSLATIONSBINPATH"],
1339 os.path.basename(qmFile))) 1331 os.path.basename(qmFile)))
1340 self.pdata["TRANSLATIONS"].remove(qmFile) 1332 self.pdata["TRANSLATIONS"].remove(qmFile)
1341 self.__model.removeItem(qmFile) 1333 self.__model.removeItem(qmFile)
1342 except ValueError: 1334 except ValueError:
1343 pass 1335 pass
1375 # now get rid of the .qm file 1367 # now get rid of the .qm file
1376 if qmFile: 1368 if qmFile:
1377 try: 1369 try:
1378 if self.pdata["TRANSLATIONSBINPATH"]: 1370 if self.pdata["TRANSLATIONSBINPATH"]:
1379 qmFile = self.getRelativePath( 1371 qmFile = self.getRelativePath(
1380 os.path.join(self.pdata["TRANSLATIONSBINPATH"][0], 1372 os.path.join(self.pdata["TRANSLATIONSBINPATH"],
1381 os.path.basename(qmFile))) 1373 os.path.basename(qmFile)))
1382 fn = os.path.join(self.ppath, qmFile) 1374 fn = os.path.join(self.ppath, qmFile)
1383 if os.path.exists(fn): 1375 if os.path.exists(fn):
1384 s2t(fn) 1376 s2t(fn)
1385 except EnvironmentError: 1377 except EnvironmentError:
1765 @param oldfn old filename (string) 1757 @param oldfn old filename (string)
1766 @param newfn new filename of the main script (string) 1758 @param newfn new filename of the main script (string)
1767 """ 1759 """
1768 if self.pdata["MAINSCRIPT"]: 1760 if self.pdata["MAINSCRIPT"]:
1769 ofn = self.getRelativePath(oldfn) 1761 ofn = self.getRelativePath(oldfn)
1770 if ofn != self.pdata["MAINSCRIPT"][0]: 1762 if ofn != self.pdata["MAINSCRIPT"]:
1771 return 1763 return
1772 1764
1773 fn = self.getRelativePath(newfn) 1765 fn = self.getRelativePath(newfn)
1774 self.pdata["MAINSCRIPT"] = [fn] 1766 self.pdata["MAINSCRIPT"] = fn
1775 self.setDirty(True) 1767 self.setDirty(True)
1776 1768
1777 def renameFile(self, oldfn, newfn=None): 1769 def renameFile(self, oldfn, newfn=None):
1778 """ 1770 """
1779 Public slot to rename a file of the project. 1771 Public slot to rename a file of the project.
2116 from .PropertiesDialog import PropertiesDialog 2108 from .PropertiesDialog import PropertiesDialog
2117 dlg = PropertiesDialog(self, True) 2109 dlg = PropertiesDialog(self, True)
2118 if dlg.exec_() == QDialog.Accepted: 2110 if dlg.exec_() == QDialog.Accepted:
2119 self.closeProject() 2111 self.closeProject()
2120 dlg.storeData() 2112 dlg.storeData()
2121 self.pdata["VCS"] = ['None'] 2113 self.pdata["VCS"] = 'None'
2122 self.opened = True 2114 self.opened = True
2123 if not self.pdata["FILETYPES"]: 2115 if not self.pdata["FILETYPES"]:
2124 self.initFileTypes() 2116 self.initFileTypes()
2125 self.setDirty(True) 2117 self.setDirty(True)
2126 self.closeAct.setEnabled(True) 2118 self.closeAct.setEnabled(True)
2140 self.menuApidocAct.setEnabled(True) 2132 self.menuApidocAct.setEnabled(True)
2141 self.menuPackagersAct.setEnabled(True) 2133 self.menuPackagersAct.setEnabled(True)
2142 self.pluginGrp.setEnabled( 2134 self.pluginGrp.setEnabled(
2143 self.pdata["PROJECTTYPE"][0] in ["E6Plugin"]) 2135 self.pdata["PROJECTTYPE"][0] in ["E6Plugin"])
2144 self.addLanguageAct.setEnabled( 2136 self.addLanguageAct.setEnabled(
2145 len(self.pdata["TRANSLATIONPATTERN"]) > 0 and 2137 bool(self.pdata["TRANSLATIONPATTERN"]))
2146 self.pdata["TRANSLATIONPATTERN"][0] != '')
2147 2138
2148 self.projectAboutToBeCreated.emit() 2139 self.projectAboutToBeCreated.emit()
2149 2140
2150 hash = str(QCryptographicHash.hash( 2141 hash = str(QCryptographicHash.hash(
2151 QByteArray(self.ppath.encode("utf-8")), 2142 QByteArray(self.ppath.encode("utf-8")),
2174 fn = os.path.join(self.ppath, "__init__.py") 2165 fn = os.path.join(self.ppath, "__init__.py")
2175 f = open(fn, "w", encoding="utf-8") 2166 f = open(fn, "w", encoding="utf-8")
2176 f.close() 2167 f.close()
2177 self.appendFile(fn, True) 2168 self.appendFile(fn, True)
2178 # create an empty main script file, if a name was given 2169 # create an empty main script file, if a name was given
2179 if len(self.pdata["MAINSCRIPT"]) and \ 2170 if self.pdata["MAINSCRIPT"]:
2180 self.pdata["MAINSCRIPT"][0]: 2171 if not os.path.isabs(self.pdata["MAINSCRIPT"]):
2181 if not os.path.isabs(self.pdata["MAINSCRIPT"][0]):
2182 ms = os.path.join( 2172 ms = os.path.join(
2183 self.ppath, self.pdata["MAINSCRIPT"][0]) 2173 self.ppath, self.pdata["MAINSCRIPT"])
2184 else: 2174 else:
2185 ms = self.pdata["MAINSCRIPT"][0] 2175 ms = self.pdata["MAINSCRIPT"]
2186 f = open(ms, "w") 2176 f = open(ms, "w")
2187 f.close() 2177 f.close()
2188 self.appendFile(ms, True) 2178 self.appendFile(ms, True)
2189 tpd = os.path.join(self.ppath, self.translationsRoot) 2179 tpd = os.path.join(self.ppath, self.translationsRoot)
2190 if not self.translationsRoot.endswith(os.sep): 2180 if not self.translationsRoot.endswith(os.sep):
2191 tpd = os.path.dirname(tpd) 2181 tpd = os.path.dirname(tpd)
2192 if not os.path.isdir(tpd): 2182 if not os.path.isdir(tpd):
2193 os.makedirs(tpd) 2183 os.makedirs(tpd)
2194 if self.pdata["TRANSLATIONSBINPATH"]: 2184 if self.pdata["TRANSLATIONSBINPATH"]:
2195 tpd = os.path.join( 2185 tpd = os.path.join(
2196 self.ppath, self.pdata["TRANSLATIONSBINPATH"][0]) 2186 self.ppath, self.pdata["TRANSLATIONSBINPATH"])
2197 if not os.path.isdir(tpd): 2187 if not os.path.isdir(tpd):
2198 os.makedirs(tpd) 2188 os.makedirs(tpd)
2199 2189
2200 # create management directory if not present 2190 # create management directory if not present
2201 self.createProjectManagementDir() 2191 self.createProjectManagementDir()
2214 " writable.</p>") 2204 " writable.</p>")
2215 .format(self.ppath)) 2205 .format(self.ppath))
2216 return 2206 return
2217 2207
2218 try: 2208 try:
2219 ms = os.path.join(self.ppath, self.pdata["MAINSCRIPT"][0]) 2209 ms = os.path.join(self.ppath, self.pdata["MAINSCRIPT"])
2220 if not os.path.exists(ms): 2210 if not os.path.exists(ms):
2221 try: 2211 try:
2222 f = open(ms, "w") 2212 f = open(ms, "w")
2223 f.close() 2213 f.close()
2224 except EnvironmentError as err: 2214 except EnvironmentError as err:
2277 vcsSystem = "None" 2267 vcsSystem = "None"
2278 else: 2268 else:
2279 vcsSystem = "None" 2269 vcsSystem = "None"
2280 else: 2270 else:
2281 vcsSystem = vcsData[0][1] 2271 vcsSystem = vcsData[0][1]
2282 self.pdata["VCS"] = [vcsSystem] 2272 self.pdata["VCS"] = vcsSystem
2283 self.vcs = self.initVCS() 2273 self.vcs = self.initVCS()
2284 self.setDirty(True) 2274 self.setDirty(True)
2285 if self.vcs is not None: 2275 if self.vcs is not None:
2286 # edit VCS command options 2276 # edit VCS command options
2287 if self.vcs.vcsSupportCommandOptions(): 2277 if self.vcs.vcsSupportCommandOptions():
2310 yesDefault=True) 2300 yesDefault=True)
2311 if apres: 2301 if apres:
2312 self.saveProject() 2302 self.saveProject()
2313 self.vcs.vcsAdd(self.pfile) 2303 self.vcs.vcsAdd(self.pfile)
2314 else: 2304 else:
2315 self.pdata["VCS"] = ['None'] 2305 self.pdata["VCS"] = 'None'
2316 self.saveProject() 2306 self.saveProject()
2317 break 2307 break
2318 2308
2319 # put the project under VCS control 2309 # put the project under VCS control
2320 if self.vcs is None and self.vcsSoftwareAvailable() and \ 2310 if self.vcs is None and self.vcsSoftwareAvailable() and \
2336 for vcsSystem, vcsSystemDisplay in vcsSystemsDict.items(): 2326 for vcsSystem, vcsSystemDisplay in vcsSystemsDict.items():
2337 if vcsSystemDisplay == vcsSelected: 2327 if vcsSystemDisplay == vcsSelected:
2338 break 2328 break
2339 else: 2329 else:
2340 vcsSystem = "None" 2330 vcsSystem = "None"
2341 self.pdata["VCS"] = [vcsSystem] 2331 self.pdata["VCS"] = vcsSystem
2342 else: 2332 else:
2343 self.pdata["VCS"] = ['None'] 2333 self.pdata["VCS"] = 'None'
2344 self.vcs = self.initVCS() 2334 self.vcs = self.initVCS()
2345 if self.vcs is not None: 2335 if self.vcs is not None:
2346 vcsdlg = self.vcs.vcsOptionsDialog(self, self.name) 2336 vcsdlg = self.vcs.vcsOptionsDialog(self, self.name)
2347 if vcsdlg.exec_() == QDialog.Accepted: 2337 if vcsdlg.exec_() == QDialog.Accepted:
2348 vcsDataDict = vcsdlg.getData() 2338 vcsDataDict = vcsdlg.getData()
2349 else: 2339 else:
2350 self.pdata["VCS"] = ['None'] 2340 self.pdata["VCS"] = 'None'
2351 self.vcs = self.initVCS() 2341 self.vcs = self.initVCS()
2352 self.setDirty(True) 2342 self.setDirty(True)
2353 if self.vcs is not None: 2343 if self.vcs is not None:
2354 # edit VCS command options 2344 # edit VCS command options
2355 if self.vcs.vcsSupportCommandOptions(): 2345 if self.vcs.vcsSupportCommandOptions():
2406 tpd = os.path.dirname(tpd) 2396 tpd = os.path.dirname(tpd)
2407 else: 2397 else:
2408 tpd = self.ppath 2398 tpd = self.ppath
2409 tslist = [] 2399 tslist = []
2410 if self.pdata["TRANSLATIONPATTERN"]: 2400 if self.pdata["TRANSLATIONPATTERN"]:
2411 pattern = os.path.basename(self.pdata["TRANSLATIONPATTERN"][0]) 2401 pattern = os.path.basename(self.pdata["TRANSLATIONPATTERN"])
2412 if "%language%" in pattern: 2402 if "%language%" in pattern:
2413 pattern = pattern.replace("%language%", "*") 2403 pattern = pattern.replace("%language%", "*")
2414 else: 2404 else:
2415 tpd = self.pdata["TRANSLATIONPATTERN"][0].split( 2405 tpd = self.pdata["TRANSLATIONPATTERN"].split(
2416 "%language%")[0] 2406 "%language%")[0]
2417 else: 2407 else:
2418 pattern = "*.ts" 2408 pattern = "*.ts"
2419 tslist.extend(Utilities.direntries(tpd, True, pattern)) 2409 tslist.extend(Utilities.direntries(tpd, True, pattern))
2420 pattern = self.__binaryTranslationFile(pattern) 2410 pattern = self.__binaryTranslationFile(pattern)
2424 if '_' in os.path.basename(tslist[0]): 2414 if '_' in os.path.basename(tslist[0]):
2425 # the first entry determines the mainscript name 2415 # the first entry determines the mainscript name
2426 mainscriptname = os.path.splitext(mainscript)[0] or \ 2416 mainscriptname = os.path.splitext(mainscript)[0] or \
2427 os.path.basename(tslist[0]).split('_')[0] 2417 os.path.basename(tslist[0]).split('_')[0]
2428 self.pdata["TRANSLATIONPATTERN"] = \ 2418 self.pdata["TRANSLATIONPATTERN"] = \
2429 [os.path.join(os.path.dirname(tslist[0]), 2419 os.path.join(os.path.dirname(tslist[0]),
2430 "{0}_%language%{1}".format( 2420 "{0}_%language%{1}".format(
2431 os.path.basename(tslist[0]).split('_')[0], 2421 os.path.basename(tslist[0]).split('_')[0],
2432 os.path.splitext(tslist[0])[1]))] 2422 os.path.splitext(tslist[0])[1]))
2433 else: 2423 else:
2434 pattern, ok = QInputDialog.getText( 2424 pattern, ok = QInputDialog.getText(
2435 None, 2425 None,
2436 self.tr("Translation Pattern"), 2426 self.tr("Translation Pattern"),
2437 self.tr( 2427 self.tr(
2438 "Enter the path pattern for translation files " 2428 "Enter the path pattern for translation files "
2439 "(use '%language%' in place of the language code):"), # __IGNORE_WARNING__ 2429 "(use '%language%' in place of the language code):"), # __IGNORE_WARNING__
2440 QLineEdit.Normal, 2430 QLineEdit.Normal,
2441 tslist[0]) 2431 tslist[0])
2442 if pattern: 2432 if pattern:
2443 self.pdata["TRANSLATIONPATTERN"] = [pattern] 2433 self.pdata["TRANSLATIONPATTERN"] = pattern
2444 if self.pdata["TRANSLATIONPATTERN"]: 2434 if self.pdata["TRANSLATIONPATTERN"]:
2445 self.pdata["TRANSLATIONPATTERN"][0] = \ 2435 self.pdata["TRANSLATIONPATTERN"] = \
2446 self.getRelativePath(self.pdata["TRANSLATIONPATTERN"][0]) 2436 self.getRelativePath(self.pdata["TRANSLATIONPATTERN"])
2447 pattern = self.pdata["TRANSLATIONPATTERN"][0]\ 2437 pattern = self.pdata["TRANSLATIONPATTERN"]\
2448 .replace("%language%", "*") 2438 .replace("%language%", "*")
2449 for ts in tslist: 2439 for ts in tslist:
2450 if fnmatch.fnmatch(ts, pattern): 2440 if fnmatch.fnmatch(ts, pattern):
2451 self.pdata["TRANSLATIONS"].append(ts) 2441 self.pdata["TRANSLATIONS"].append(ts)
2452 self.projectLanguageAdded.emit(ts) 2442 self.projectLanguageAdded.emit(ts)
2453 if self.pdata["TRANSLATIONSBINPATH"]: 2443 if self.pdata["TRANSLATIONSBINPATH"]:
2454 tpd = os.path.join(self.ppath, 2444 tpd = os.path.join(self.ppath,
2455 self.pdata["TRANSLATIONSBINPATH"][0]) 2445 self.pdata["TRANSLATIONSBINPATH"])
2456 pattern = os.path.basename( 2446 pattern = os.path.basename(
2457 self.pdata["TRANSLATIONPATTERN"][0])\ 2447 self.pdata["TRANSLATIONPATTERN"])\
2458 .replace("%language%", "*") 2448 .replace("%language%", "*")
2459 pattern = self.__binaryTranslationFile(pattern) 2449 pattern = self.__binaryTranslationFile(pattern)
2460 qmlist = Utilities.direntries(tpd, True, pattern) 2450 qmlist = Utilities.direntries(tpd, True, pattern)
2461 for qm in qmlist: 2451 for qm in qmlist:
2462 self.pdata["TRANSLATIONS"].append(qm) 2452 self.pdata["TRANSLATIONS"].append(qm)
2463 self.projectLanguageAdded.emit(qm) 2453 self.projectLanguageAdded.emit(qm)
2464 if len(self.pdata["MAINSCRIPT"]) == 0 or \ 2454 if not self.pdata["MAINSCRIPT"]:
2465 len(self.pdata["MAINSCRIPT"][0]) == 0:
2466 if self.pdata["PROGLANGUAGE"][0] in \ 2455 if self.pdata["PROGLANGUAGE"][0] in \
2467 ["Python", "Python2", "Python3"]: 2456 ["Python", "Python2", "Python3"]:
2468 self.pdata["MAINSCRIPT"] = [ 2457 self.pdata["MAINSCRIPT"] = '{0}.py'.format(mainscriptname)
2469 '{0}.py'.format(mainscriptname)]
2470 elif self.pdata["PROGLANGUAGE"][0] == "Ruby": 2458 elif self.pdata["PROGLANGUAGE"][0] == "Ruby":
2471 self.pdata["MAINSCRIPT"] = [ 2459 self.pdata["MAINSCRIPT"] = '{0}.rb'.format(mainscriptname)
2472 '{0}.rb'.format(mainscriptname)]
2473 self.setDirty(True) 2460 self.setDirty(True)
2474 QApplication.restoreOverrideCursor() 2461 QApplication.restoreOverrideCursor()
2475 2462
2476 def __showProperties(self): 2463 def __showProperties(self):
2477 """ 2464 """
2482 if dlg.exec_() == QDialog.Accepted: 2469 if dlg.exec_() == QDialog.Accepted:
2483 projectType = self.pdata["PROJECTTYPE"][0] 2470 projectType = self.pdata["PROJECTTYPE"][0]
2484 dlg.storeData() 2471 dlg.storeData()
2485 self.setDirty(True) 2472 self.setDirty(True)
2486 try: 2473 try:
2487 ms = os.path.join(self.ppath, self.pdata["MAINSCRIPT"][0]) 2474 ms = os.path.join(self.ppath, self.pdata["MAINSCRIPT"])
2488 if os.path.exists(ms): 2475 if os.path.exists(ms):
2489 self.appendFile(ms) 2476 self.appendFile(ms)
2490 except IndexError: 2477 except IndexError:
2491 pass 2478 pass
2492 2479
2505 if tp != self.ppath and tp not in self.subdirs: 2492 if tp != self.ppath and tp not in self.subdirs:
2506 self.subdirs.append(tp) 2493 self.subdirs.append(tp)
2507 2494
2508 if self.pdata["TRANSLATIONSBINPATH"]: 2495 if self.pdata["TRANSLATIONSBINPATH"]:
2509 tp = os.path.join( 2496 tp = os.path.join(
2510 self.ppath, self.pdata["TRANSLATIONSBINPATH"][0]) 2497 self.ppath, self.pdata["TRANSLATIONSBINPATH"])
2511 if not os.path.isdir(tp): 2498 if not os.path.isdir(tp):
2512 os.makedirs(tp) 2499 os.makedirs(tp)
2513 if tp != self.ppath and tp not in self.subdirs: 2500 if tp != self.ppath and tp not in self.subdirs:
2514 self.subdirs.append(tp) 2501 self.subdirs.append(tp)
2515 2502
2524 2511
2525 def __showUserProperties(self): 2512 def __showUserProperties(self):
2526 """ 2513 """
2527 Private slot to display the user specific properties dialog. 2514 Private slot to display the user specific properties dialog.
2528 """ 2515 """
2529 vcsSystem = self.pdata["VCS"] and self.pdata["VCS"][0] or None 2516 vcsSystem = self.pdata["VCS"] or None
2530 vcsSystemOverride = self.pudata["VCSOVERRIDE"] or None 2517 vcsSystemOverride = self.pudata["VCSOVERRIDE"] or None
2531 2518
2532 from .UserPropertiesDialog import UserPropertiesDialog 2519 from .UserPropertiesDialog import UserPropertiesDialog
2533 dlg = UserPropertiesDialog(self) 2520 dlg = UserPropertiesDialog(self)
2534 if dlg.exec_() == QDialog.Accepted: 2521 if dlg.exec_() == QDialog.Accepted:
2535 dlg.storeData() 2522 dlg.storeData()
2536 2523
2537 if (self.pdata["VCS"] and 2524 if (self.pdata["VCS"] and
2538 self.pdata["VCS"][0] != vcsSystem) or \ 2525 self.pdata["VCS"] != vcsSystem) or \
2539 (self.pudata["VCSOVERRIDE"] and 2526 (self.pudata["VCSOVERRIDE"] and
2540 self.pudata["VCSOVERRIDE"] != vcsSystemOverride) or \ 2527 self.pudata["VCSOVERRIDE"] != vcsSystemOverride) or \
2541 (vcsSystemOverride is not None and 2528 (vcsSystemOverride is not None and
2542 not self.pudata["VCSOVERRIDE"]): 2529 not self.pudata["VCSOVERRIDE"]):
2543 # stop the VCS monitor thread and shutdown VCS 2530 # stop the VCS monitor thread and shutdown VCS
2704 vcsSystem = "None" 2691 vcsSystem = "None"
2705 else: 2692 else:
2706 vcsSystem = "None" 2693 vcsSystem = "None"
2707 else: 2694 else:
2708 vcsSystem = vcsData[0][0] 2695 vcsSystem = vcsData[0][0]
2709 self.pdata["VCS"] = [vcsSystem] 2696 self.pdata["VCS"] = vcsSystem
2710 self.vcs = self.initVCS() 2697 self.vcs = self.initVCS()
2711 self.setDirty(True) 2698 self.setDirty(True)
2712 if self.vcs is not None and \ 2699 if self.vcs is not None and \
2713 (self.vcs.vcsRegisteredState(self.ppath) != 2700 (self.vcs.vcsRegisteredState(self.ppath) !=
2714 self.vcs.canBeCommitted): 2701 self.vcs.canBeCommitted):
2715 self.pdata["VCS"] = ['None'] 2702 self.pdata["VCS"] = 'None'
2716 self.vcs = self.initVCS() 2703 self.vcs = self.initVCS()
2717 self.closeAct.setEnabled(True) 2704 self.closeAct.setEnabled(True)
2718 self.saveasAct.setEnabled(True) 2705 self.saveasAct.setEnabled(True)
2719 self.actGrp2.setEnabled(True) 2706 self.actGrp2.setEnabled(True)
2720 self.propsAct.setEnabled(True) 2707 self.propsAct.setEnabled(True)
2732 self.menuPackagersAct.setEnabled(True) 2719 self.menuPackagersAct.setEnabled(True)
2733 self.pluginGrp.setEnabled( 2720 self.pluginGrp.setEnabled(
2734 self.pdata["PROJECTTYPE"][0] in [ 2721 self.pdata["PROJECTTYPE"][0] in [
2735 "E6Plugin"]) 2722 "E6Plugin"])
2736 self.addLanguageAct.setEnabled( 2723 self.addLanguageAct.setEnabled(
2737 len(self.pdata["TRANSLATIONPATTERN"]) > 0 and 2724 bool(self.pdata["TRANSLATIONPATTERN"]))
2738 self.pdata["TRANSLATIONPATTERN"][0] != '')
2739 2725
2740 self.__model.projectOpened() 2726 self.__model.projectOpened()
2741 self.projectOpenedHooks.emit() 2727 self.projectOpenedHooks.emit()
2742 self.projectOpened.emit() 2728 self.projectOpened.emit()
2743 2729
2750 self.__readTasks() 2736 self.__readTasks()
2751 self.ui.taskViewer.setProjectOpen(True) 2737 self.ui.taskViewer.setProjectOpen(True)
2752 2738
2753 if restoreSession: 2739 if restoreSession:
2754 # open the main script 2740 # open the main script
2755 if len(self.pdata["MAINSCRIPT"]) == 1: 2741 if self.pdata["MAINSCRIPT"]:
2756 self.sourceFile.emit( 2742 self.sourceFile.emit(
2757 os.path.join( 2743 os.path.join(
2758 self.ppath, self.pdata["MAINSCRIPT"][0])) 2744 self.ppath, self.pdata["MAINSCRIPT"]))
2759 2745
2760 # open a project session file being quiet about errors 2746 # open a project session file being quiet about errors
2761 if reopen: 2747 if reopen:
2762 self.__readSession(quiet=True, indicator="_tmp") 2748 self.__readSession(quiet=True, indicator="_tmp")
2763 elif Preferences.getProject("AutoLoadSession"): 2749 elif Preferences.getProject("AutoLoadSession"):
3049 3035
3050 @param normalized flag indicating a normalized filename is wanted 3036 @param normalized flag indicating a normalized filename is wanted
3051 (boolean) 3037 (boolean)
3052 @return filename of the projects main script (string) 3038 @return filename of the projects main script (string)
3053 """ 3039 """
3054 if len(self.pdata["MAINSCRIPT"]): 3040 if self.pdata["MAINSCRIPT"]:
3055 if normalized: 3041 if normalized:
3056 return os.path.join(self.ppath, self.pdata["MAINSCRIPT"][0]) 3042 return os.path.join(self.ppath, self.pdata["MAINSCRIPT"])
3057 else: 3043 else:
3058 return self.pdata["MAINSCRIPT"][0] 3044 return self.pdata["MAINSCRIPT"]
3059 else: 3045 else:
3060 return None 3046 return None
3061 3047
3062 def getSources(self, normalized=False): 3048 def getSources(self, normalized=False):
3063 """ 3049 """
3312 """ 3298 """
3313 Public method to get the EOL-string to be used by the project. 3299 Public method to get the EOL-string to be used by the project.
3314 3300
3315 @return eol string (string) 3301 @return eol string (string)
3316 """ 3302 """
3317 if self.pdata["EOL"][0] >= 0: 3303 if self.pdata["EOL"] >= 0:
3318 return self.eols[self.pdata["EOL"][0]] 3304 return self.eols[self.pdata["EOL"]]
3319 else: 3305 else:
3320 eolMode = Preferences.getEditor("EOLMode") 3306 eolMode = Preferences.getEditor("EOLMode")
3321 if eolMode == QsciScintilla.EolWindows: 3307 if eolMode == QsciScintilla.EolWindows:
3322 eol = '\r\n' 3308 eol = '\r\n'
3323 elif eolMode == QsciScintilla.EolUnix: 3309 elif eolMode == QsciScintilla.EolUnix:
3332 """ 3318 """
3333 Public method to check, if the project uses the system eol setting. 3319 Public method to check, if the project uses the system eol setting.
3334 3320
3335 @return flag indicating the usage of system eol (boolean) 3321 @return flag indicating the usage of system eol (boolean)
3336 """ 3322 """
3337 return self.pdata["EOL"][0] == 0 3323 return self.pdata["EOL"] == 0
3338 3324
3339 def isProjectFile(self, fn): 3325 def isProjectFile(self, fn):
3340 """ 3326 """
3341 Public method used to check, if the passed in filename belongs to the 3327 Public method used to check, if the passed in filename belongs to the
3342 project. 3328 project.
4143 try: 4129 try:
4144 newSources = os.listdir(curpath) 4130 newSources = os.listdir(curpath)
4145 except OSError: 4131 except OSError:
4146 newSources = [] 4132 newSources = []
4147 if self.pdata["TRANSLATIONPATTERN"]: 4133 if self.pdata["TRANSLATIONPATTERN"]:
4148 pattern = self.pdata["TRANSLATIONPATTERN"][0]\ 4134 pattern = self.pdata["TRANSLATIONPATTERN"]\
4149 .replace("%language%", "*") 4135 .replace("%language%", "*")
4150 else: 4136 else:
4151 pattern = "*.ts" 4137 pattern = "*.ts"
4152 binpattern = self.__binaryTranslationFile(pattern) 4138 binpattern = self.__binaryTranslationFile(pattern)
4153 for ns in newSources: 4139 for ns in newSources:
4318 vcs = None 4304 vcs = None
4319 forProject = True 4305 forProject = True
4320 override = False 4306 override = False
4321 4307
4322 if vcsSystem is None: 4308 if vcsSystem is None:
4323 if len(self.pdata["VCS"]): 4309 if self.pdata["VCS"] and self.pdata["VCS"] != 'None':
4324 if self.pdata["VCS"][0] != 'None': 4310 vcsSystem = self.pdata["VCS"]
4325 vcsSystem = self.pdata["VCS"][0]
4326 else: 4311 else:
4327 forProject = False 4312 forProject = False
4328 4313
4329 if self.pdata["VCS"] and self.pdata["VCS"][0] != 'None': 4314 if self.pdata["VCS"] and self.pdata["VCS"] != 'None':
4330 if self.pudata["VCSOVERRIDE"] and \ 4315 if self.pudata["VCSOVERRIDE"] and \
4331 not nooverride: 4316 not nooverride:
4332 vcsSystem = self.pudata["VCSOVERRIDE"] 4317 vcsSystem = self.pudata["VCSOVERRIDE"]
4333 override = True 4318 override = True
4334 4319
4366 "<p>The selected VCS <b>{0}</b> could not be" 4351 "<p>The selected VCS <b>{0}</b> could not be"
4367 " found.<br/>Disabling version control.</p>" 4352 " found.<br/>Disabling version control.</p>"
4368 "<p>{1}</p>").format(vcsSystem, msg)) 4353 "<p>{1}</p>").format(vcsSystem, msg))
4369 vcs = None 4354 vcs = None
4370 if forProject: 4355 if forProject:
4371 self.pdata["VCS"][0] = 'None' 4356 self.pdata["VCS"] = 'None'
4372 self.setDirty(True) 4357 self.setDirty(True)
4373 else: 4358 else:
4374 vcs.vcsInitConfig(self) 4359 vcs.vcsInitConfig(self)
4375 4360
4376 if vcs and forProject: 4361 if vcs and forProject:
4377 # set the vcs options 4362 # set the vcs options
4378 if vcs.vcsSupportCommandOptions(): 4363 if vcs.vcsSupportCommandOptions():
4379 try: 4364 try:
4380 vcsopt = copy.deepcopy(self.pdata["VCSOPTIONS"][0]) 4365 vcsopt = copy.deepcopy(self.pdata["VCSOPTIONS"])
4381 vcs.vcsSetOptions(vcsopt) 4366 vcs.vcsSetOptions(vcsopt)
4382 except LookupError: 4367 except LookupError:
4383 pass 4368 pass
4384 # set vcs specific data 4369 # set vcs specific data
4385 try: 4370 try:
4386 vcsother = copy.deepcopy(self.pdata["VCSOTHERDATA"][0]) 4371 vcsother = copy.deepcopy(self.pdata["VCSOTHERDATA"])
4387 vcs.vcsSetOtherData(vcsother) 4372 vcs.vcsSetOtherData(vcsother)
4388 except LookupError: 4373 except LookupError:
4389 pass 4374 pass
4390 4375
4391 if vcs is None: 4376 if vcs is None:
4787 self.tr("Create Plugin Archive"), 4772 self.tr("Create Plugin Archive"),
4788 self.tr("""<p>The file <b>PKGLIST</b> does not exist. """ 4773 self.tr("""<p>The file <b>PKGLIST</b> does not exist. """
4789 """Aborting...</p>""")) 4774 """Aborting...</p>"""))
4790 return 4775 return
4791 4776
4792 if len(self.pdata["MAINSCRIPT"]) == 0 or \ 4777 if not self.pdata["MAINSCRIPT"]:
4793 len(self.pdata["MAINSCRIPT"][0]) == 0:
4794 E5MessageBox.critical( 4778 E5MessageBox.critical(
4795 self.ui, 4779 self.ui,
4796 self.tr("Create Plugin Archive"), 4780 self.tr("Create Plugin Archive"),
4797 self.tr( 4781 self.tr(
4798 """The project does not have a main script defined. """ 4782 """The project does not have a main script defined. """
4812 """<p>The file <b>PKGLIST</b> could not be read.</p>""" 4796 """<p>The file <b>PKGLIST</b> could not be read.</p>"""
4813 """<p>Reason: {0}</p>""").format(str(why))) 4797 """<p>Reason: {0}</p>""").format(str(why)))
4814 return 4798 return
4815 4799
4816 archive = os.path.join( 4800 archive = os.path.join(
4817 self.ppath, self.pdata["MAINSCRIPT"][0].replace(".py", ".zip")) 4801 self.ppath, self.pdata["MAINSCRIPT"].replace(".py", ".zip"))
4818 try: 4802 try:
4819 archiveFile = zipfile.ZipFile(archive, "w") 4803 archiveFile = zipfile.ZipFile(archive, "w")
4820 except IOError as why: 4804 except IOError as why:
4821 E5MessageBox.critical( 4805 E5MessageBox.critical(
4822 self.ui, 4806 self.ui,
4830 for name in names: 4814 for name in names:
4831 if name: 4815 if name:
4832 try: 4816 try:
4833 self.__createZipDirEntries( 4817 self.__createZipDirEntries(
4834 os.path.split(name)[0], archiveFile) 4818 os.path.split(name)[0], archiveFile)
4835 if snapshot and name == self.pdata["MAINSCRIPT"][0]: 4819 if snapshot and name == self.pdata["MAINSCRIPT"]:
4836 snapshotSource, version = self.__createSnapshotSource( 4820 snapshotSource, version = self.__createSnapshotSource(
4837 os.path.join(self.ppath, 4821 os.path.join(self.ppath,
4838 self.pdata["MAINSCRIPT"][0])) 4822 self.pdata["MAINSCRIPT"]))
4839 archiveFile.writestr(name, snapshotSource) 4823 archiveFile.writestr(name, snapshotSource)
4840 else: 4824 else:
4841 archiveFile.write(os.path.join(self.ppath, name), name) 4825 archiveFile.write(os.path.join(self.ppath, name), name)
4842 if name == self.pdata["MAINSCRIPT"][0]: 4826 if name == self.pdata["MAINSCRIPT"]:
4843 version = self.__pluginExtractVersion( 4827 version = self.__pluginExtractVersion(
4844 os.path.join(self.ppath, 4828 os.path.join(self.ppath,
4845 self.pdata["MAINSCRIPT"][0])) 4829 self.pdata["MAINSCRIPT"]))
4846 except OSError as why: 4830 except OSError as why:
4847 E5MessageBox.critical( 4831 E5MessageBox.critical(
4848 self.ui, 4832 self.ui,
4849 self.tr("Create Plugin Archive"), 4833 self.tr("Create Plugin Archive"),
4850 self.tr( 4834 self.tr(

eric ide

mercurial