1096 @param index key of the list to be checked |
1106 @param index key of the list to be checked |
1097 @type str |
1107 @type str |
1098 """ |
1108 """ |
1099 removed = False |
1109 removed = False |
1100 removelist = [] |
1110 removelist = [] |
1101 for file in self.__pdata[index]: |
1111 if FileSystemUtilities.isRemoteFileName(self.ppath): |
1102 if not os.path.exists(os.path.join(self.ppath, file)): |
1112 for file in self.__pdata[index]: |
1103 removelist.append(file) |
1113 if not self.__remotefsInterface.exists( |
1104 removed = True |
1114 self.__remotefsInterface.join(self.ppath, file) |
|
1115 ): |
|
1116 removelist.append(file) |
|
1117 removed = True |
|
1118 else: |
|
1119 for file in self.__pdata[index]: |
|
1120 if not os.path.exists(os.path.join(self.ppath, file)): |
|
1121 removelist.append(file) |
|
1122 removed = True |
1105 |
1123 |
1106 if removed: |
1124 if removed: |
1107 for file in removelist: |
1125 for file in removelist: |
1108 self.__pdata[index].remove(file) |
1126 self.__pdata[index].remove(file) |
1109 self.setDirty(True) |
1127 self.setDirty(True) |
1110 |
1128 |
1111 def __readProject(self, fn): |
1129 def __readProject(self, fn): |
1112 """ |
1130 """ |
1113 Private method to read in a project (.epj) file. |
1131 Private method to read in a project file (.epj). |
1114 |
1132 |
1115 @param fn filename of the project file to be read |
1133 @param fn filename of the project file to be read |
1116 @type str |
1134 @type str |
1117 @return flag indicating success |
1135 @return flag indicating success |
1118 @rtype bool |
1136 @rtype bool |
1119 """ |
1137 """ |
1120 with EricOverrideCursor(): |
1138 with EricOverrideCursor(): |
1121 res = self.__projectFile.readFile(fn) |
1139 res = self.__projectFile.readFile(fn) |
1122 |
1140 |
1123 if res: |
1141 if res: |
1124 self.pfile = os.path.abspath(fn) |
1142 if FileSystemUtilities.isRemoteFileName(fn): |
1125 self.ppath = os.path.abspath(os.path.dirname(fn)) |
1143 self.pfile = fn |
|
1144 self.ppath = self.__remotefsInterface.dirname(fn) |
|
1145 self.name = self.__remotefsInterface.splitext( |
|
1146 self.__remotefsInterface.basename(fn) |
|
1147 )[0] |
|
1148 self.__remotefsInterface.populateFsCache(self.ppath) |
|
1149 else: |
|
1150 self.pfile = os.path.abspath(fn) |
|
1151 self.ppath = os.path.abspath(os.path.dirname(fn)) |
|
1152 self.name = os.path.splitext(os.path.basename(fn))[0] |
1126 |
1153 |
1127 # insert filename into list of recently opened projects |
1154 # insert filename into list of recently opened projects |
1128 self.__syncRecent() |
1155 self.__syncRecent() |
1129 |
1156 |
1130 if self.__pdata["TRANSLATIONPATTERN"]: |
1157 if self.__pdata["TRANSLATIONPATTERN"]: |
1131 self.translationsRoot = self.__pdata["TRANSLATIONPATTERN"].split( |
1158 self.translationsRoot = self.__pdata["TRANSLATIONPATTERN"].split( |
1132 "%language%" |
1159 "%language%" |
1133 )[0] |
1160 )[0] |
1134 elif self.__pdata["MAINSCRIPT"]: |
1161 elif self.__pdata["MAINSCRIPT"]: |
1135 self.translationsRoot = os.path.splitext(self.__pdata["MAINSCRIPT"])[0] |
1162 self.translationsRoot = os.path.splitext(self.__pdata["MAINSCRIPT"])[0] |
1136 if os.path.isdir(os.path.join(self.ppath, self.translationsRoot)): |
1163 |
1137 dn = self.translationsRoot |
1164 if FileSystemUtilities.isRemoteFileName(self.ppath): |
|
1165 if self.__remotefsInterface.isdir( |
|
1166 self.__remotefsInterface.join(self.ppath, self.translationsRoot) |
|
1167 ): |
|
1168 dn = self.translationsRoot |
|
1169 else: |
|
1170 dn = self.__remotefsInterface.dirname(self.translationsRoot) |
1138 else: |
1171 else: |
1139 dn = os.path.dirname(self.translationsRoot) |
1172 if os.path.isdir(os.path.join(self.ppath, self.translationsRoot)): |
1140 if dn not in self.subdirs: |
1173 dn = self.translationsRoot |
|
1174 else: |
|
1175 dn = os.path.dirname(self.translationsRoot) |
|
1176 if dn and dn not in self.subdirs: |
1141 self.subdirs.append(dn) |
1177 self.subdirs.append(dn) |
1142 |
|
1143 self.name = os.path.splitext(os.path.basename(fn))[0] |
|
1144 |
1178 |
1145 # check, if the files of the project still exist in the |
1179 # check, if the files of the project still exist in the |
1146 # project directory |
1180 # project directory |
1147 for fileCategory in self.getFileCategories(): |
1181 for fileCategory in self.getFileCategories(): |
1148 self.__checkFilesExist(fileCategory) |
1182 self.__checkFilesExist(fileCategory) |
1149 |
1183 |
1150 # get the names of subdirectories the files are stored in |
1184 # get the names of subdirectories the files are stored in |
1151 for fileCategory in [c for c in self.getFileCategories() if c != "OTHERS"]: |
1185 for fileCategory in [c for c in self.getFileCategories() if c != "OTHERS"]: |
1152 for fn in self.__pdata[fileCategory]: |
1186 for fn in self.__pdata[fileCategory]: |
1153 dn = os.path.dirname(fn) |
1187 dn = ( |
1154 if dn not in self.subdirs: |
1188 self.__remotefsInterface.dirname(fn) |
|
1189 if FileSystemUtilities.isRemoteFileName(self.ppath) |
|
1190 else os.path.dirname(fn) |
|
1191 ) |
|
1192 if dn and dn not in self.subdirs: |
1155 self.subdirs.append(dn) |
1193 self.subdirs.append(dn) |
1156 |
1194 |
1157 # get the names of other subdirectories |
1195 # get the names of other subdirectories |
1158 for fn in self.__pdata["OTHERS"]: |
1196 for fn in self.__pdata["OTHERS"]: |
1159 dn = os.path.dirname(fn) |
1197 dn = ( |
1160 if dn not in self.otherssubdirs: |
1198 self.__remotefsInterface.dirname(fn) |
1161 self.otherssubdirs.append(dn) |
1199 if FileSystemUtilities.isRemoteFileName(fn) |
|
1200 else os.path.dirname(fn) |
|
1201 ) |
1162 |
1202 |
1163 return res |
1203 return res |
1164 |
1204 |
1165 def __writeProject(self, fn=None): |
1205 def __writeProject(self, fn=None): |
1166 """ |
1206 """ |
1211 Private method to read in the user specific project file (.eqj). |
1258 Private method to read in the user specific project file (.eqj). |
1212 """ |
1259 """ |
1213 if self.pfile is None: |
1260 if self.pfile is None: |
1214 return |
1261 return |
1215 |
1262 |
1216 fn1, ext = os.path.splitext(os.path.basename(self.pfile)) |
1263 if FileSystemUtilities.isRemoteFileName(self.pfile): |
1217 fn = os.path.join(self.getProjectManagementDir(), "{0}.eqj".format(fn1)) |
1264 fn1, _ext = self.__remotefsInterface.splitext( |
1218 if os.path.exists(fn): |
1265 self.__remotefsInterface.basename(self.pfile) |
1219 self.__userProjectFile.readFile(fn) |
1266 ) |
|
1267 fn = self.__remotefsInterface.join( |
|
1268 self.getProjectManagementDir(), f"{fn1}.eqj" |
|
1269 ) |
|
1270 if not self.__remotefsInterface.exists(fn): |
|
1271 return |
|
1272 else: |
|
1273 fn1, _ext = os.path.splitext(os.path.basename(self.pfile)) |
|
1274 fn = os.path.join(self.getProjectManagementDir(), f"{fn1}.eqj") |
|
1275 if not os.path.exists(fn): |
|
1276 return |
|
1277 |
|
1278 self.__userProjectFile.readFile(fn) |
1220 |
1279 |
1221 def __writeUserProperties(self): |
1280 def __writeUserProperties(self): |
1222 """ |
1281 """ |
1223 Private method to write the user specific project data to a JSON file. |
1282 Private method to write the user specific project data to a JSON file. |
1224 """ |
1283 """ |
1225 if self.pfile is None: |
1284 if self.pfile is None: |
1226 return |
1285 return |
1227 |
1286 |
1228 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
1287 if FileSystemUtilities.isRemoteFileName(self.pfile): |
1229 fn = os.path.join(self.getProjectManagementDir(), "{0}.eqj".format(fn)) |
1288 fn1, _ext = self.__remotefsInterface.splitext( |
|
1289 self.__remotefsInterface.basename(self.pfile) |
|
1290 ) |
|
1291 fn = self.__remotefsInterface.join( |
|
1292 self.getProjectManagementDir(), f"{fn1}.eqj" |
|
1293 ) |
|
1294 else: |
|
1295 fn1, _ext = os.path.splitext(os.path.basename(self.pfile)) |
|
1296 fn = os.path.join(self.getProjectManagementDir(), f"{fn1}.eqj") |
1230 |
1297 |
1231 with EricOverrideCursor(): |
1298 with EricOverrideCursor(): |
1232 self.__userProjectFile.writeFile(fn) |
1299 self.__userProjectFile.writeFile(fn) |
1233 |
1300 |
1234 def __showContextMenuSession(self): |
1301 def __showContextMenuSession(self): |
1309 self.tr("Delete Project Session"), |
1401 self.tr("Delete Project Session"), |
1310 self.tr("Please save the project first."), |
1402 self.tr("Please save the project first."), |
1311 ) |
1403 ) |
1312 return |
1404 return |
1313 |
1405 |
1314 fname, ext = os.path.splitext(os.path.basename(self.pfile)) |
1406 try: |
1315 |
1407 if FileSystemUtilities.isRemoteFileName(self.pfile): |
1316 fn = os.path.join(self.getProjectManagementDir(), f"{fname}.esj") |
1408 title = self.tr("Delete Remote Project Session") |
1317 if os.path.exists(fn): |
1409 fname, _ext = self.__remotefsInterface.splitext( |
1318 try: |
1410 self.__remotefsInterface.basename(self.pfile) |
1319 os.remove(fn) |
|
1320 except OSError: |
|
1321 EricMessageBox.critical( |
|
1322 self.ui, |
|
1323 self.tr("Delete Project Session"), |
|
1324 self.tr( |
|
1325 "<p>The project session file <b>{0}</b> could" |
|
1326 " not be deleted.</p>" |
|
1327 ).format(fn), |
|
1328 ) |
1411 ) |
|
1412 fn = self.__remotefsInterface.join( |
|
1413 self.getProjectManagementDir(), f"{fname}.esj" |
|
1414 ) |
|
1415 if self.__remotefsInterface.exists(fn): |
|
1416 self.__remotefsInterface.remove(fn) |
|
1417 else: |
|
1418 title = self.tr("Delete Project Session") |
|
1419 fname, _ext = os.path.splitext(os.path.basename(self.pfile)) |
|
1420 fn = os.path.join(self.getProjectManagementDir(), f"{fname}.esj") |
|
1421 if os.path.exists(fn): |
|
1422 os.remove(fn) |
|
1423 except OSError: |
|
1424 EricMessageBox.critical( |
|
1425 self.ui, |
|
1426 title, |
|
1427 self.tr( |
|
1428 "<p>The project session file <b>{0}</b> could" |
|
1429 " not be deleted.</p>" |
|
1430 ).format(fn), |
|
1431 ) |
1329 |
1432 |
1330 def __readTasks(self): |
1433 def __readTasks(self): |
1331 """ |
1434 """ |
1332 Private method to read in the project tasks file (.etj). |
1435 Private method to read in the project tasks file (.etj). |
1333 """ |
1436 """ |
1337 self.tr("Read Tasks"), |
1440 self.tr("Read Tasks"), |
1338 self.tr("Please save the project first."), |
1441 self.tr("Please save the project first."), |
1339 ) |
1442 ) |
1340 return |
1443 return |
1341 |
1444 |
1342 base, ext = os.path.splitext(os.path.basename(self.pfile)) |
1445 if FileSystemUtilities.isRemoteFileName(self.pfile): |
1343 fn = os.path.join(self.getProjectManagementDir(), "{0}.etj".format(base)) |
1446 base, _ext = self.__remotefsInterface.splitext( |
1344 if os.path.exists(fn): |
1447 self.__remotefsInterface.basename(self.pfile) |
1345 self.__tasksFile.readFile(fn) |
1448 ) |
|
1449 fn = self.__remotefsInterface.join( |
|
1450 self.getProjectManagementDir(), f"{base}.etj" |
|
1451 ) |
|
1452 if not self.__remotefsInterface.exists(fn): |
|
1453 return |
|
1454 else: |
|
1455 base, ext = os.path.splitext(os.path.basename(self.pfile)) |
|
1456 fn = os.path.join(self.getProjectManagementDir(), f"{base}.etj") |
|
1457 if not os.path.exists(fn): |
|
1458 return |
|
1459 |
|
1460 self.__tasksFile.readFile(fn) |
1346 |
1461 |
1347 def writeTasks(self): |
1462 def writeTasks(self): |
1348 """ |
1463 """ |
1349 Public method to write the tasks data to a JSON file (.etj). |
1464 Public method to write the tasks data to a JSON file (.etj). |
1350 """ |
1465 """ |
1351 if self.pfile is None: |
1466 if self.pfile is None: |
1352 return |
1467 return |
1353 |
1468 |
1354 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
1469 if FileSystemUtilities.isRemoteFileName(self.pfile): |
1355 |
1470 base, _ext = self.__remotefsInterface.splitext( |
1356 fn = os.path.join(self.getProjectManagementDir(), "{0}.etj".format(fn)) |
1471 self.__remotefsInterface.basename(self.pfile) |
|
1472 ) |
|
1473 fn = self.__remotefsInterface.join( |
|
1474 self.getProjectManagementDir(), f"{base}.etj" |
|
1475 ) |
|
1476 else: |
|
1477 base, ext = os.path.splitext(os.path.basename(self.pfile)) |
|
1478 fn = os.path.join(self.getProjectManagementDir(), f"{base}.etj") |
|
1479 |
1357 self.__tasksFile.writeFile(fn) |
1480 self.__tasksFile.writeFile(fn) |
1358 |
1481 |
1359 def __showContextMenuDebugger(self): |
1482 def __showContextMenuDebugger(self): |
1360 """ |
1483 """ |
1361 Private slot called before the Debugger menu is shown. |
1484 Private slot called before the Debugger menu is shown. |
1362 """ |
1485 """ |
1363 enable = True |
1486 enable = True |
1364 if self.pfile is None: |
1487 if self.pfile is None: |
1365 enable = False |
1488 enable = False |
1366 else: |
1489 else: |
1367 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
1490 if FileSystemUtilities.isRemoteFileName(self.pfile): |
1368 fn = os.path.join(self.getProjectManagementDir(), "{0}.edj".format(fn)) |
1491 fn1, _ext = self.__remotefsInterface.splitext( |
1369 enable = os.path.exists(fn) |
1492 self.__remotefsInterface.basename(self.pfile) |
|
1493 ) |
|
1494 fn = self.__remotefsInterface.join( |
|
1495 self.getProjectManagementDir(), f"{fn1}.edj" |
|
1496 ) |
|
1497 enable = self.__remotefsInterface.exists(fn) |
|
1498 else: |
|
1499 fn1, _ext = os.path.splitext(os.path.basename(self.pfile)) |
|
1500 fn = os.path.join(self.getProjectManagementDir(), f"{fn1}.edj") |
|
1501 enable = os.path.exists(fn) |
1370 self.dbgActGrp.findChild( |
1502 self.dbgActGrp.findChild( |
1371 QAction, "project_debugger_properties_load" |
1503 QAction, "project_debugger_properties_load" |
1372 ).setEnabled(enable) |
1504 ).setEnabled(enable) |
1373 self.dbgActGrp.findChild( |
1505 self.dbgActGrp.findChild( |
1374 QAction, "project_debugger_properties_delete" |
1506 QAction, "project_debugger_properties_delete" |
1432 self.tr("Delete Debugger Properties"), |
1584 self.tr("Delete Debugger Properties"), |
1433 self.tr("Please save the project first."), |
1585 self.tr("Please save the project first."), |
1434 ) |
1586 ) |
1435 return |
1587 return |
1436 |
1588 |
1437 fname, ext = os.path.splitext(os.path.basename(self.pfile)) |
1589 try: |
1438 |
1590 if FileSystemUtilities.isRemoteFileName(self.pfile): |
1439 fn = os.path.join(self.getProjectManagementDir(), f"{fname}.edj") |
1591 title = self.tr("Delete Remote Debugger Properties") |
1440 if os.path.exists(fn): |
1592 fname, _ext = self.__remotefsInterface.splitext( |
1441 try: |
1593 self.__remotefsInterface.basename(self.pfile) |
1442 os.remove(fn) |
|
1443 except OSError: |
|
1444 EricMessageBox.critical( |
|
1445 self.ui, |
|
1446 self.tr("Delete Debugger Properties"), |
|
1447 self.tr( |
|
1448 "<p>The project debugger properties file" |
|
1449 " <b>{0}</b> could not be deleted.</p>" |
|
1450 ).format(fn), |
|
1451 ) |
1594 ) |
|
1595 fn = self.__remotefsInterface.join( |
|
1596 self.getProjectManagementDir(), f"{fname}.edj" |
|
1597 ) |
|
1598 if self.__remotefsInterface.exists(fn): |
|
1599 self.__remotefsInterface.remove(fn) |
|
1600 else: |
|
1601 title = self.tr("Delete Debugger Properties") |
|
1602 fname, _ext = os.path.splitext(os.path.basename(self.pfile)) |
|
1603 fn = os.path.join(self.getProjectManagementDir(), f"{fname}.edj") |
|
1604 if os.path.exists(fn): |
|
1605 os.remove(fn) |
|
1606 except OSError: |
|
1607 EricMessageBox.critical( |
|
1608 self.ui, |
|
1609 title, |
|
1610 self.tr( |
|
1611 "<p>The project debugger properties file" |
|
1612 " <b>{0}</b> could not be deleted.</p>" |
|
1613 ).format(fn), |
|
1614 ) |
1452 |
1615 |
1453 def __initDebugProperties(self): |
1616 def __initDebugProperties(self): |
1454 """ |
1617 """ |
1455 Private method to initialize the debug properties. |
1618 Private method to initialize the debug properties. |
1456 """ |
1619 """ |
1667 """ |
1834 """ |
1668 tbPath = self.__pdata["TRANSLATIONSBINPATH"] |
1835 tbPath = self.__pdata["TRANSLATIONSBINPATH"] |
1669 for langFile in self.__pdata["TRANSLATIONS"][:]: |
1836 for langFile in self.__pdata["TRANSLATIONS"][:]: |
1670 qmFile = self.__binaryTranslationFile(langFile) |
1837 qmFile = self.__binaryTranslationFile(langFile) |
1671 if qmFile: |
1838 if qmFile: |
1672 if qmFile not in self.__pdata["TRANSLATIONS"] and os.path.exists( |
1839 if FileSystemUtilities.isRemoteFileName(self.ppath): |
1673 os.path.join(self.ppath, qmFile) |
1840 if qmFile not in self.__pdata[ |
1674 ): |
1841 "TRANSLATIONS" |
1675 self.appendFile(qmFile) |
1842 ] and self.__remotefsInterface.exists( |
1676 if tbPath: |
1843 self.__remotefsInterface.join(self.ppath, qmFile) |
1677 qmFile = os.path.join(tbPath, os.path.basename(qmFile)) |
1844 ): |
|
1845 self.appendFile(qmFile) |
|
1846 if tbPath: |
|
1847 qmFile = self.__remotefsInterface.join( |
|
1848 tbPath, self.__remotefsInterface.basename(qmFile) |
|
1849 ) |
|
1850 if qmFile not in self.__pdata[ |
|
1851 "TRANSLATIONS" |
|
1852 ] and self.__remotefsInterface.exists( |
|
1853 self.__remotefsInterface.join(self.ppath, qmFile) |
|
1854 ): |
|
1855 self.appendFile(qmFile) |
|
1856 else: |
1678 if qmFile not in self.__pdata["TRANSLATIONS"] and os.path.exists( |
1857 if qmFile not in self.__pdata["TRANSLATIONS"] and os.path.exists( |
1679 os.path.join(self.ppath, qmFile) |
1858 os.path.join(self.ppath, qmFile) |
1680 ): |
1859 ): |
1681 self.appendFile(qmFile) |
1860 self.appendFile(qmFile) |
|
1861 if tbPath: |
|
1862 qmFile = os.path.join(tbPath, os.path.basename(qmFile)) |
|
1863 if qmFile not in self.__pdata[ |
|
1864 "TRANSLATIONS" |
|
1865 ] and os.path.exists(os.path.join(self.ppath, qmFile)): |
|
1866 self.appendFile(qmFile) |
1682 |
1867 |
1683 def removeLanguageFile(self, langFile): |
1868 def removeLanguageFile(self, langFile): |
1684 """ |
1869 """ |
1685 Public slot to remove a translation from the project. |
1870 Public slot to remove a translation from the project. |
1686 |
1871 |
1773 """ |
1969 """ |
1774 dirty = False |
1970 dirty = False |
1775 |
1971 |
1776 # make it relative to the project root, if it starts with that path |
1972 # make it relative to the project root, if it starts with that path |
1777 # assume relative paths are relative to the project root |
1973 # assume relative paths are relative to the project root |
1778 newfn = self.getRelativePath(fn) if os.path.isabs(fn) else fn |
1974 if FileSystemUtilities.isRemoteFileName(self.ppath): |
1779 newdir = os.path.dirname(newfn) |
1975 newfn = self.getRelativePath(fn) if fn.startswith(self.ppath) else fn |
|
1976 newdir = self.__remotefsInterface.dirname(newfn) |
|
1977 else: |
|
1978 newfn = self.getRelativePath(fn) if os.path.isabs(fn) else fn |
|
1979 newdir = os.path.dirname(newfn) |
1780 |
1980 |
1781 if isSourceFile: |
1981 if isSourceFile: |
1782 filetype = "SOURCES" |
1982 filetype = "SOURCES" |
1783 else: |
1983 else: |
1784 filetype = "OTHERS" |
1984 filetype = "OTHERS" |
1785 bfn = os.path.basename(newfn) |
1985 bfn = ( |
|
1986 self.__remotefsInterface.basename(newfn) |
|
1987 if FileSystemUtilities.isRemoteFileName(self.ppath) |
|
1988 else os.path.basename(newfn) |
|
1989 ) |
1786 if fnmatch.fnmatch(bfn, "*.ts") or fnmatch.fnmatch(bfn, "*.qm"): |
1990 if fnmatch.fnmatch(bfn, "*.ts") or fnmatch.fnmatch(bfn, "*.qm"): |
1787 filetype = "TRANSLATIONS" |
1991 filetype = "TRANSLATIONS" |
1788 else: |
1992 else: |
1789 for pattern in sorted(self.__pdata["FILETYPES"], reverse=True): |
1993 for pattern in sorted(self.__pdata["FILETYPES"], reverse=True): |
1790 if fnmatch.fnmatch(bfn, pattern): |
1994 if fnmatch.fnmatch(bfn, pattern): |
1846 |
2048 |
1847 dlg = AddFileDialog(self, self.parent(), fileTypeFilter, startdir=startdir) |
2049 dlg = AddFileDialog(self, self.parent(), fileTypeFilter, startdir=startdir) |
1848 if dlg.exec() == QDialog.DialogCode.Accepted: |
2050 if dlg.exec() == QDialog.DialogCode.Accepted: |
1849 fnames, target, isSource = dlg.getData() |
2051 fnames, target, isSource = dlg.getData() |
1850 if target != "": |
2052 if target != "": |
|
2053 isRemote = FileSystemUtilities.isRemoteFileName(target) |
1851 for fn in fnames: |
2054 for fn in fnames: |
1852 targetfile = os.path.join(target, os.path.basename(fn)) |
2055 targetfile = ( |
1853 if not FileSystemUtilities.samepath(os.path.dirname(fn), target): |
2056 self.__remotefsInterface.join( |
|
2057 target, self.__remotefsInterface.basename(fn) |
|
2058 ) |
|
2059 if isRemote |
|
2060 else os.path.join(target, os.path.basename(fn)) |
|
2061 ) |
|
2062 if not FileSystemUtilities.samepath( |
|
2063 ( |
|
2064 self.__remotefsInterface.dirname(fn) |
|
2065 if isRemote |
|
2066 else os.path.dirname(fn) |
|
2067 ), |
|
2068 target, |
|
2069 ): |
1854 try: |
2070 try: |
1855 if not os.path.isdir(target): |
2071 if isRemote: |
1856 os.makedirs(target) |
2072 if not self.__remotefsInterface.isdir(target): |
1857 |
2073 self.__remotefsInterface.makedirs(target) |
1858 if os.path.exists(targetfile): |
2074 else: |
|
2075 if not os.path.isdir(target): |
|
2076 os.makedirs(target) |
|
2077 |
|
2078 if (not isRemote and os.path.exists(targetfile)) or ( |
|
2079 isRemote and self.__remotefsInterface.exists(targetfile) |
|
2080 ): |
1859 res = EricMessageBox.yesNo( |
2081 res = EricMessageBox.yesNo( |
1860 self.ui, |
2082 self.ui, |
1861 self.tr("Add file"), |
2083 self.tr("Add File"), |
1862 self.tr( |
2084 self.tr( |
1863 "<p>The file <b>{0}</b> already" |
2085 "<p>The file <b>{0}</b> already" |
1864 " exists.</p><p>Overwrite it?</p>" |
2086 " exists.</p><p>Overwrite it?</p>" |
1865 ).format(targetfile), |
2087 ).format(targetfile), |
1866 icon=EricMessageBox.Warning, |
2088 icon=EricMessageBox.Warning, |
1867 ) |
2089 ) |
1868 if not res: |
2090 if not res: |
1869 return # don't overwrite |
2091 return # don't overwrite |
1870 |
2092 |
1871 shutil.copy(fn, target) |
2093 if isRemote: |
|
2094 self.__remotefsInterface.shutilCopy(fn, target) |
|
2095 else: |
|
2096 shutil.copy(fn, target) |
1872 except OSError as why: |
2097 except OSError as why: |
1873 EricMessageBox.critical( |
2098 EricMessageBox.critical( |
1874 self.ui, |
2099 self.ui, |
1875 self.tr("Add file"), |
2100 self.tr("Add File"), |
1876 self.tr( |
2101 self.tr( |
1877 "<p>The selected file <b>{0}</b> could" |
2102 "<p>The selected file <b>{0}</b> could" |
1878 " not be added to <b>{1}</b>.</p>" |
2103 " not be added to <b>{1}</b>.</p>" |
1879 "<p>Reason: {2}</p>" |
2104 "<p>Reason: {2}</p>" |
1880 ).format(fn, target, str(why)), |
2105 ).format(fn, target, str(why)), |
1911 patterns.append(pattern) |
2136 patterns.append(pattern) |
1912 elif patterntype == "__IGNORE__": |
2137 elif patterntype == "__IGNORE__": |
1913 ignorePatterns.append(pattern) |
2138 ignorePatterns.append(pattern) |
1914 |
2139 |
1915 files = [] |
2140 files = [] |
|
2141 isRemote = FileSystemUtilities.isRemoteFileName(target) |
1916 for pattern in patterns: |
2142 for pattern in patterns: |
1917 sstring = "{0}{1}{2}".format(source, os.sep, pattern) |
2143 if isRemote: |
1918 files.extend(glob.glob(sstring)) |
2144 sstring = self.__remotefsInterface.join(source, pattern) |
|
2145 files.extend(self.__remotefsInterface.glob(sstring)) |
|
2146 else: |
|
2147 sstring = os.path.join(source, pattern) |
|
2148 files.extend(glob.glob(sstring)) |
1919 |
2149 |
1920 if len(files) == 0: |
2150 if len(files) == 0: |
1921 if not quiet: |
2151 if not quiet: |
1922 EricMessageBox.information( |
2152 EricMessageBox.information( |
1923 self.ui, |
2153 self.ui, |
1924 self.tr("Add directory"), |
2154 self.tr("Add Directory"), |
1925 self.tr( |
2155 self.tr( |
1926 "<p>The source directory doesn't contain" |
2156 "<p>The source directory doesn't contain" |
1927 " any files belonging to the selected category.</p>" |
2157 " any files belonging to the selected category.</p>" |
1928 ), |
2158 ), |
1929 ) |
2159 ) |
1930 return |
2160 return |
1931 |
2161 |
1932 if not FileSystemUtilities.samepath(target, source) and not os.path.isdir( |
2162 if not FileSystemUtilities.samepath(target, source) and not ( |
1933 target |
2163 (not isRemote and os.path.isdir(target)) |
|
2164 or (isRemote and self.__remotefsInterface.isdir(target)) |
1934 ): |
2165 ): |
1935 try: |
2166 try: |
1936 os.makedirs(target) |
2167 if isRemote: |
|
2168 self.__remotefsInterface.makedirs(target) |
|
2169 else: |
|
2170 os.makedirs(target) |
1937 except OSError as why: |
2171 except OSError as why: |
1938 EricMessageBox.critical( |
2172 EricMessageBox.critical( |
1939 self.ui, |
2173 self.ui, |
1940 self.tr("Add directory"), |
2174 self.tr("Add Directory"), |
1941 self.tr( |
2175 self.tr( |
1942 "<p>The target directory <b>{0}</b> could not be" |
2176 "<p>The target directory <b>{0}</b> could not be" |
1943 " created.</p><p>Reason: {1}</p>" |
2177 " created.</p><p>Reason: {1}</p>" |
1944 ).format(target, str(why)), |
2178 ).format(target, str(why)), |
1945 ) |
2179 ) |
1948 for file in files: |
2182 for file in files: |
1949 for pattern in ignorePatterns: |
2183 for pattern in ignorePatterns: |
1950 if fnmatch.fnmatch(file, pattern): |
2184 if fnmatch.fnmatch(file, pattern): |
1951 continue |
2185 continue |
1952 |
2186 |
1953 targetfile = os.path.join(target, os.path.basename(file)) |
2187 targetfile = ( |
|
2188 self.__remotefsInterface.join( |
|
2189 target, self.__remotefsInterface.basename(file) |
|
2190 ) |
|
2191 if isRemote |
|
2192 else os.path.join(target, os.path.basename(file)) |
|
2193 ) |
1954 if not FileSystemUtilities.samepath(target, source): |
2194 if not FileSystemUtilities.samepath(target, source): |
1955 try: |
2195 try: |
1956 if os.path.exists(targetfile): |
2196 if (not isRemote and os.path.exists(targetfile)) or ( |
|
2197 isRemote and self.__remotefsInterface.exists(targetfile) |
|
2198 ): |
1957 res = EricMessageBox.yesNo( |
2199 res = EricMessageBox.yesNo( |
1958 self.ui, |
2200 self.ui, |
1959 self.tr("Add directory"), |
2201 self.tr("Add Directory"), |
1960 self.tr( |
2202 self.tr( |
1961 "<p>The file <b>{0}</b> already exists.</p>" |
2203 "<p>The file <b>{0}</b> already exists.</p>" |
1962 "<p>Overwrite it?</p>" |
2204 "<p>Overwrite it?</p>" |
1963 ).format(targetfile), |
2205 ).format(targetfile), |
1964 icon=EricMessageBox.Warning, |
2206 icon=EricMessageBox.Warning, |
1965 ) |
2207 ) |
1966 if not res: |
2208 if not res: |
1967 continue |
2209 continue |
1968 # don't overwrite, carry on with next file |
2210 # don't overwrite, carry on with next file |
1969 |
2211 |
1970 shutil.copy(file, target) |
2212 if isRemote: |
|
2213 self.__remotefsInterface.shutilCopy(file, target) |
|
2214 else: |
|
2215 shutil.copy(file, target) |
1971 except OSError: |
2216 except OSError: |
1972 continue |
2217 continue |
1973 self.appendFile(targetfile) |
2218 self.appendFile(targetfile) |
1974 |
2219 |
1975 def __addRecursiveDirectory(self, filetype, source, target): |
2220 def __addRecursiveDirectory(self, filetype, source, target): |
2001 pattern |
2246 pattern |
2002 for pattern, filetype in self.__pdata["FILETYPES"].items() |
2247 for pattern, filetype in self.__pdata["FILETYPES"].items() |
2003 if filetype == "__IGNORE__" |
2248 if filetype == "__IGNORE__" |
2004 ] |
2249 ] |
2005 |
2250 |
2006 # now recurse into subdirectories |
2251 # now recurs into subdirectories |
2007 with os.scandir(source) as dirEntriesIterator: |
2252 if FileSystemUtilities.isRemoteFileName(target): |
2008 for dirEntry in dirEntriesIterator: |
2253 for entry in self.__remotefsInterface.listdir(source)[2]: |
2009 if dirEntry.is_dir() and not any( |
2254 if entry["is_dir"] and not any( |
2010 fnmatch.fnmatch(dirEntry.name, ignore_pattern) |
2255 fnmatch.fnmatch(entry["name"], ignore_pattern) |
2011 for ignore_pattern in ignore_patterns |
2256 for ignore_pattern in ignore_patterns |
2012 ): |
2257 ): |
2013 self.__addRecursiveDirectory( |
2258 self.__addRecursiveDirectory( |
2014 filetype, dirEntry.path, os.path.join(target, dirEntry.name) |
2259 filetype, |
|
2260 entry["path"], |
|
2261 self.__remotefsInterface.join(target, entry["name"]), |
2015 ) |
2262 ) |
|
2263 else: |
|
2264 with os.scandir(source) as dirEntriesIterator: |
|
2265 for dirEntry in dirEntriesIterator: |
|
2266 if dirEntry.is_dir() and not any( |
|
2267 fnmatch.fnmatch(dirEntry.name, ignore_pattern) |
|
2268 for ignore_pattern in ignore_patterns |
|
2269 ): |
|
2270 self.__addRecursiveDirectory( |
|
2271 filetype, dirEntry.path, os.path.join(target, dirEntry.name) |
|
2272 ) |
2016 |
2273 |
2017 @pyqtSlot() |
2274 @pyqtSlot() |
2018 def addDirectory(self, fileTypeFilter=None, startdir=None): |
2275 def addDirectory(self, fileTypeFilter=None, startdir=None): |
2019 """ |
2276 """ |
2020 Public method used to add all files of a directory to the project. |
2277 Public method used to add all files of a directory to the project. |
2107 @param newfn new filename of the file |
2367 @param newfn new filename of the file |
2108 @type str |
2368 @type str |
2109 @return flag indicating success |
2369 @return flag indicating success |
2110 @rtype bool |
2370 @rtype bool |
2111 """ |
2371 """ |
|
2372 isRemote = FileSystemUtilities.isRemoteFileName(oldfn) |
|
2373 |
2112 fn = self.getRelativePath(oldfn) |
2374 fn = self.getRelativePath(oldfn) |
2113 isSourceFile = fn in self.__pdata["SOURCES"] |
2375 isSourceFile = fn in self.__pdata["SOURCES"] |
2114 |
2376 |
2115 if newfn is None: |
2377 if newfn is None: |
2116 newfn = EricFileDialog.getSaveFileName( |
2378 if isRemote: |
2117 None, |
2379 newfn = EricServerFileDialog.getSaveFileName( |
2118 self.tr("Rename file"), |
2380 None, |
2119 oldfn, |
2381 self.tr("Rename File"), |
2120 "", |
2382 oldfn, |
2121 options=EricFileDialog.DontConfirmOverwrite, |
2383 "", |
2122 ) |
2384 ) |
|
2385 else: |
|
2386 newfn = EricFileDialog.getSaveFileName( |
|
2387 None, |
|
2388 self.tr("Rename File"), |
|
2389 oldfn, |
|
2390 "", |
|
2391 options=EricFileDialog.DontConfirmOverwrite, |
|
2392 ) |
|
2393 if newfn: |
|
2394 newfn = FileSystemUtilities.toNativeSeparators(newfn) |
|
2395 |
2123 if not newfn: |
2396 if not newfn: |
2124 return False |
2397 return False |
2125 newfn = FileSystemUtilities.toNativeSeparators(newfn) |
2398 |
2126 |
2399 if (not isRemote and os.path.exists(newfn)) or ( |
2127 if os.path.exists(newfn): |
2400 isRemote and self.__remotefsInterface.exists(newfn) |
|
2401 ): |
2128 res = EricMessageBox.yesNo( |
2402 res = EricMessageBox.yesNo( |
2129 self.ui, |
2403 self.ui, |
2130 self.tr("Rename File"), |
2404 self.tr("Rename File"), |
2131 self.tr( |
2405 self.tr( |
2132 """<p>The file <b>{0}</b> already exists.""" |
2406 """<p>The file <b>{0}</b> already exists.""" |
2187 @param start prefix |
2471 @param start prefix |
2188 @type str |
2472 @type str |
2189 @return list of files starting with a common prefix |
2473 @return list of files starting with a common prefix |
2190 @rtype list of str |
2474 @rtype list of str |
2191 """ |
2475 """ |
|
2476 isRemote = FileSystemUtilities.isRemoteFileName(self.ppath) |
|
2477 |
2192 filelist = [] |
2478 filelist = [] |
2193 start = self.getRelativePath(start) |
2479 start = self.getRelativePath(start) |
2194 for fileCategory in [ |
2480 for fileCategory in [ |
2195 c for c in self.getFileCategories() if c != "TRANSLATIONS" |
2481 c for c in self.getFileCategories() if c != "TRANSLATIONS" |
2196 ]: |
2482 ]: |
2197 for entry in self.__pdata[fileCategory][:]: |
2483 for entry in self.__pdata[fileCategory][:]: |
2198 if entry.startswith(start): |
2484 if entry.startswith(start): |
2199 filelist.append(os.path.join(self.ppath, entry)) |
2485 filelist.append( |
|
2486 self.__remotefsInterface.join(self.ppath, entry) |
|
2487 if isRemote |
|
2488 else os.path.join(self.ppath, entry) |
|
2489 ) |
2200 return filelist |
2490 return filelist |
2201 |
2491 |
2202 def __reorganizeFiles(self): |
2492 def __reorganizeFiles(self): |
2203 """ |
2493 """ |
2204 Private method to reorganize files stored in the project. |
2494 Private method to reorganize files stored in the project. |
2205 """ |
2495 """ |
2206 reorganized = False |
2496 reorganized = False |
2207 |
2497 isRemote = FileSystemUtilities.isRemoteFileName(self.ppath) |
2208 # init data store for the reorganization |
2498 |
|
2499 # initialize data store for the reorganization |
2209 newPdata = {} |
2500 newPdata = {} |
2210 for fileCategory in self.getFileCategories(): |
2501 for fileCategory in self.getFileCategories(): |
2211 newPdata[fileCategory] = [] |
2502 newPdata[fileCategory] = [] |
2212 |
2503 |
2213 # iterate over all files checking for a reassignment |
2504 # iterate over all files checking for a reassignment |
2214 for fileCategory in self.getFileCategories(): |
2505 for fileCategory in self.getFileCategories(): |
2215 for fn in self.__pdata[fileCategory][:]: |
2506 for fn in self.__pdata[fileCategory][:]: |
2216 filetype = fileCategory |
2507 filetype = fileCategory |
2217 bfn = os.path.basename(fn) |
2508 bfn = ( |
|
2509 self.__remotefsInterface.basename(fn) |
|
2510 if isRemote |
|
2511 else os.path.basename(fn) |
|
2512 ) |
2218 for pattern in sorted(self.__pdata["FILETYPES"], reverse=True): |
2513 for pattern in sorted(self.__pdata["FILETYPES"], reverse=True): |
2219 if fnmatch.fnmatch(bfn, pattern): |
2514 if fnmatch.fnmatch(bfn, pattern): |
2220 filetype = self.__pdata["FILETYPES"][pattern] |
2515 filetype = self.__pdata["FILETYPES"][pattern] |
2221 break |
2516 break |
2222 |
2517 |
2350 @type str |
2654 @type str |
2351 @return flag indicating success |
2655 @return flag indicating success |
2352 @rtype bool |
2656 @rtype bool |
2353 """ |
2657 """ |
2354 try: |
2658 try: |
2355 os.remove(os.path.join(self.ppath, fn)) |
2659 if FileSystemUtilities.isRemoteFileName(self.ppath): |
2356 path, ext = os.path.splitext(fn) |
2660 self.__remotefsInterface.remove( |
2357 if ext == ".ui": |
2661 self.__remotefsInterface.join(self.ppath, fn) |
2358 fn2 = os.path.join(self.ppath, "{0}.h".format(fn)) |
|
2359 if os.path.isfile(fn2): |
|
2360 os.remove(fn2) |
|
2361 head, tail = os.path.split(path) |
|
2362 for ext in [".pyc", ".pyo"]: |
|
2363 fn2 = os.path.join(self.ppath, path + ext) |
|
2364 if os.path.isfile(fn2): |
|
2365 os.remove(fn2) |
|
2366 pat = os.path.join( |
|
2367 self.ppath, head, "__pycache__", "{0}.*{1}".format(tail, ext) |
|
2368 ) |
2662 ) |
2369 for f in glob.glob(pat): |
2663 filepath = self.__remotefsInterface.splitext(fn)[0] |
2370 os.remove(f) |
2664 head, tail = self.__remotefsInterface.split(filepath) |
|
2665 for ext in [".pyc", ".pyo"]: |
|
2666 fn2 = self.__remotefsInterface.join(self.ppath, filepath + ext) |
|
2667 if self.__remotefsInterface.isfile(fn2): |
|
2668 self.__remotefsInterface.remove(fn2) |
|
2669 pat = self.__remotefsInterface.join( |
|
2670 self.ppath, head, "__pycache__", "{0}.*{1}".format(tail, ext) |
|
2671 ) |
|
2672 for f in self.__remotefsInterface.glob(pat): |
|
2673 self.__remotefsInterface.remove(f) |
|
2674 else: |
|
2675 os.remove(os.path.join(self.ppath, fn)) |
|
2676 filepath = os.path.splitext(fn)[0] |
|
2677 head, tail = os.path.split(filepath) |
|
2678 for ext in [".pyc", ".pyo"]: |
|
2679 fn2 = os.path.join(self.ppath, filepath + ext) |
|
2680 if os.path.isfile(fn2): |
|
2681 os.remove(fn2) |
|
2682 pat = os.path.join( |
|
2683 self.ppath, head, "__pycache__", "{0}.*{1}".format(tail, ext) |
|
2684 ) |
|
2685 for f in glob.glob(pat): |
|
2686 os.remove(f) |
2371 except OSError as err: |
2687 except OSError as err: |
2372 EricMessageBox.critical( |
2688 EricMessageBox.critical( |
2373 self.ui, |
2689 self.ui, |
2374 self.tr("Delete file"), |
2690 self.tr("Delete File"), |
2375 self.tr( |
2691 self.tr( |
2376 "<p>The selected file <b>{0}</b> could not be" |
2692 "<p>The selected file <b>{0}</b> could not be" |
2377 " deleted.</p><p>Reason: {1}</p>" |
2693 " deleted.</p><p>Reason: {1}</p>" |
2378 ).format(fn, str(err)), |
2694 ).format(fn, str(err)), |
2379 ) |
2695 ) |
2380 return False |
2696 return False |
2381 |
2697 |
2382 self.removeFile(fn) |
2698 self.removeFile(fn) |
2383 if ext == ".ui": |
|
2384 self.removeFile(fn + ".h") |
|
2385 return True |
2699 return True |
2386 |
2700 |
2387 def deleteDirectory(self, dn): |
2701 def deleteDirectory(self, dn): |
2388 """ |
2702 """ |
2389 Public method to delete a directory from the project directory. |
2703 Public method to delete a directory from the project directory. |
2456 self.initFileTypes() |
2775 self.initFileTypes() |
2457 self.setDirty(True) |
2776 self.setDirty(True) |
2458 self.reloadAct.setEnabled(True) |
2777 self.reloadAct.setEnabled(True) |
2459 self.closeAct.setEnabled(True) |
2778 self.closeAct.setEnabled(True) |
2460 self.saveasAct.setEnabled(True) |
2779 self.saveasAct.setEnabled(True) |
|
2780 self.saveasRemoteAct.setEnabled( |
|
2781 self.__remoteServer.isServerConnected() |
|
2782 and FileSystemUtilities.isRemoteFileName(self.pfile) |
|
2783 ) |
2461 self.actGrp2.setEnabled(True) |
2784 self.actGrp2.setEnabled(True) |
2462 self.propsAct.setEnabled(True) |
2785 self.propsAct.setEnabled(True) |
2463 self.userPropsAct.setEnabled(True) |
2786 self.userPropsAct.setEnabled(not isRemote) |
2464 self.filetypesAct.setEnabled(True) |
2787 self.filetypesAct.setEnabled(True) |
2465 self.lexersAct.setEnabled(True) |
2788 self.lexersAct.setEnabled(True) |
2466 self.sessActGrp.setEnabled(False) |
2789 self.sessActGrp.setEnabled(False) |
2467 self.dbgActGrp.setEnabled(True) |
2790 self.dbgActGrp.setEnabled(True) |
2468 self.menuDebuggerAct.setEnabled(True) |
2791 self.menuDebuggerAct.setEnabled(True) |
2469 self.menuSessionAct.setEnabled(False) |
2792 self.menuSessionAct.setEnabled(False) |
2470 self.menuCheckAct.setEnabled(True) |
2793 self.menuCheckAct.setEnabled(True) |
2471 self.menuShowAct.setEnabled(True) |
2794 self.menuShowAct.setEnabled(True) |
2472 self.menuDiagramAct.setEnabled(True) |
2795 self.menuDiagramAct.setEnabled(True) |
2473 self.menuApidocAct.setEnabled(True) |
2796 self.menuApidocAct.setEnabled( |
|
2797 not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
2798 ) |
2474 self.menuPackagersAct.setEnabled(True) |
2799 self.menuPackagersAct.setEnabled(True) |
2475 self.pluginGrp.setEnabled(self.__pdata["PROJECTTYPE"] in ["E7Plugin"]) |
2800 self.pluginGrp.setEnabled( |
|
2801 self.__pdata["PROJECTTYPE"] in ["E7Plugin"] |
|
2802 and not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
2803 ) |
2476 self.addLanguageAct.setEnabled(bool(self.__pdata["TRANSLATIONPATTERN"])) |
2804 self.addLanguageAct.setEnabled(bool(self.__pdata["TRANSLATIONPATTERN"])) |
2477 self.makeGrp.setEnabled(self.__pdata["MAKEPARAMS"]["MakeEnabled"]) |
2805 self.makeGrp.setEnabled( |
2478 self.menuMakeAct.setEnabled(self.__pdata["MAKEPARAMS"]["MakeEnabled"]) |
2806 self.__pdata["MAKEPARAMS"]["MakeEnabled"] |
|
2807 and not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
2808 ) |
|
2809 self.menuMakeAct.setEnabled( |
|
2810 self.__pdata["MAKEPARAMS"]["MakeEnabled"] |
|
2811 and not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
2812 ) |
2479 self.menuOtherToolsAct.setEnabled(True) |
2813 self.menuOtherToolsAct.setEnabled(True) |
2480 self.menuFormattingAct.setEnabled(True) |
2814 self.menuFormattingAct.setEnabled( |
|
2815 not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
2816 ) |
|
2817 self.menuVcsAct.setEnabled( |
|
2818 not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
2819 ) |
2481 |
2820 |
2482 self.projectAboutToBeCreated.emit() |
2821 self.projectAboutToBeCreated.emit() |
2483 |
2822 |
2484 hashStr = str( |
2823 hashStr = str( |
2485 QCryptographicHash.hash( |
2824 QCryptographicHash.hash( |
2515 return |
2862 return |
2516 |
2863 |
2517 # create an empty __init__.py file to make it a Python package |
2864 # create an empty __init__.py file to make it a Python package |
2518 # (only for Python and Python3) |
2865 # (only for Python and Python3) |
2519 if self.__pdata["PROGLANGUAGE"] in ["Python3", "MicroPython"]: |
2866 if self.__pdata["PROGLANGUAGE"] in ["Python3", "MicroPython"]: |
2520 fn = os.path.join(self.ppath, "__init__.py") |
2867 if isRemote: |
2521 with open(fn, "w", encoding="utf-8"): |
2868 fn = self.__remotefsInterface.join(self.ppath, "__init__.py") |
2522 pass |
2869 self.__remotefsInterface.writeFile(fn, b"") |
|
2870 else: |
|
2871 fn = os.path.join(self.ppath, "__init__.py") |
|
2872 with open(fn, "w", encoding="utf-8"): |
|
2873 pass |
2523 self.appendFile(fn, True) |
2874 self.appendFile(fn, True) |
2524 |
2875 |
2525 # create an empty main script file, if a name was given |
2876 # create an empty main script file, if a name was given |
2526 if self.__pdata["MAINSCRIPT"]: |
2877 if self.__pdata["MAINSCRIPT"]: |
2527 if not os.path.isabs(self.__pdata["MAINSCRIPT"]): |
2878 if isRemote: |
2528 ms = os.path.join(self.ppath, self.__pdata["MAINSCRIPT"]) |
2879 if not self.__remotefsInterface.isabs( |
|
2880 self.__pdata["MAINSCRIPT"] |
|
2881 ): |
|
2882 ms = self.__remotefsInterface.join( |
|
2883 self.ppath, self.__pdata["MAINSCRIPT"] |
|
2884 ) |
|
2885 else: |
|
2886 ms = self.__pdata["MAINSCRIPT"] |
|
2887 self.__remotefsInterface.makedirs( |
|
2888 self.__remotefsInterface.dirname(ms), exist_ok=True |
|
2889 ) |
|
2890 self.__remotefsInterface.writeFile(ms, b"") |
2529 else: |
2891 else: |
2530 ms = self.__pdata["MAINSCRIPT"] |
2892 if not os.path.isabs(self.__pdata["MAINSCRIPT"]): |
2531 os.makedirs(os.path.dirname(ms), exist_ok=True) |
2893 ms = os.path.join(self.ppath, self.__pdata["MAINSCRIPT"]) |
2532 with open(ms, "w"): |
2894 else: |
2533 pass |
2895 ms = self.__pdata["MAINSCRIPT"] |
|
2896 os.makedirs(os.path.dirname(ms), exist_ok=True) |
|
2897 with open(ms, "w"): |
|
2898 pass |
2534 self.appendFile(ms, True) |
2899 self.appendFile(ms, True) |
2535 |
2900 |
2536 if self.__pdata["MAKEPARAMS"]["MakeEnabled"]: |
2901 if self.__pdata["MAKEPARAMS"]["MakeEnabled"] and not isRemote: |
2537 mf = self.__pdata["MAKEPARAMS"]["MakeFile"] |
2902 mf = self.__pdata["MAKEPARAMS"]["MakeFile"] |
2538 if mf: |
2903 if mf: |
2539 if not os.path.isabs(mf): |
2904 if not os.path.isabs(mf): |
2540 mf = os.path.join(self.ppath, mf) |
2905 mf = os.path.join(self.ppath, mf) |
2541 else: |
2906 else: |
2543 os.makedirs(os.path.dirname(mf), exist_ok=True) |
2908 os.makedirs(os.path.dirname(mf), exist_ok=True) |
2544 with open(mf, "w"): |
2909 with open(mf, "w"): |
2545 pass |
2910 pass |
2546 self.appendFile(mf) |
2911 self.appendFile(mf) |
2547 |
2912 |
2548 tpd = os.path.join(self.ppath, self.translationsRoot) |
2913 if isRemote: |
2549 if not self.translationsRoot.endswith(os.sep): |
2914 tpd = self.__remotefsInterface.join( |
2550 tpd = os.path.dirname(tpd) |
2915 self.ppath, self.translationsRoot |
2551 if not os.path.isdir(tpd): |
2916 ) |
2552 os.makedirs(tpd, exist_ok=True) |
2917 if not self.translationsRoot.endswith( |
2553 if self.__pdata["TRANSLATIONSBINPATH"]: |
2918 self.__remotefsInterface.separator() |
2554 tpd = os.path.join(self.ppath, self.__pdata["TRANSLATIONSBINPATH"]) |
2919 ): |
|
2920 tpd = self.__remotefsInterface.dirname(tpd) |
|
2921 if not self.__remotefsInterface.isdir(tpd): |
|
2922 self.__remotefsInterface.makedirs(tpd, exist_ok=True) |
|
2923 if self.__pdata["TRANSLATIONSBINPATH"]: |
|
2924 tpd = self.__remotefsInterface.join( |
|
2925 self.ppath, self.__pdata["TRANSLATIONSBINPATH"] |
|
2926 ) |
|
2927 if not self.__remotefsInterface.isdir(tpd): |
|
2928 self.__remotefsInterface.makedirs(tpd, exist_ok=True) |
|
2929 else: |
|
2930 tpd = os.path.join(self.ppath, self.translationsRoot) |
|
2931 if not self.translationsRoot.endswith(os.sep): |
|
2932 tpd = os.path.dirname(tpd) |
2555 if not os.path.isdir(tpd): |
2933 if not os.path.isdir(tpd): |
2556 os.makedirs(tpd, exist_ok=True) |
2934 os.makedirs(tpd, exist_ok=True) |
|
2935 if self.__pdata["TRANSLATIONSBINPATH"]: |
|
2936 tpd = os.path.join( |
|
2937 self.ppath, self.__pdata["TRANSLATIONSBINPATH"] |
|
2938 ) |
|
2939 if not os.path.isdir(tpd): |
|
2940 os.makedirs(tpd, exist_ok=True) |
2557 |
2941 |
2558 # create management directory if not present |
2942 # create management directory if not present |
2559 self.createProjectManagementDir() |
2943 self.createProjectManagementDir() |
2560 |
2944 |
2561 self.saveProject() |
2945 self.saveProject() |
2576 # set the auto save flag to its supposed value |
2960 # set the auto save flag to its supposed value |
2577 Preferences.setProject("AutoSaveProject", autoSaveProject) |
2961 Preferences.setProject("AutoSaveProject", autoSaveProject) |
2578 return |
2962 return |
2579 |
2963 |
2580 if self.__pdata["MAINSCRIPT"]: |
2964 if self.__pdata["MAINSCRIPT"]: |
2581 if not os.path.isabs(self.__pdata["MAINSCRIPT"]): |
2965 if isRemote: |
2582 ms = os.path.join(self.ppath, self.__pdata["MAINSCRIPT"]) |
2966 if not self.__remotefsInterface.isabs( |
|
2967 self.__pdata["MAINSCRIPT"] |
|
2968 ): |
|
2969 ms = self.__remotefsInterface.join( |
|
2970 self.ppath, self.__pdata["MAINSCRIPT"] |
|
2971 ) |
|
2972 else: |
|
2973 ms = self.__pdata["MAINSCRIPT"] |
|
2974 msExists = self.__remotefsInterface.exists(ms) |
2583 else: |
2975 else: |
2584 ms = self.__pdata["MAINSCRIPT"] |
2976 if not os.path.isabs(self.__pdata["MAINSCRIPT"]): |
2585 if not os.path.exists(ms): |
2977 ms = os.path.join(self.ppath, self.__pdata["MAINSCRIPT"]) |
|
2978 else: |
|
2979 ms = self.__pdata["MAINSCRIPT"] |
|
2980 msExists = os.path.exists(ms) |
|
2981 if not msExists: |
2586 try: |
2982 try: |
2587 os.makedirs(os.path.dirname(ms), exist_ok=True) |
2983 if isRemote: |
2588 with open(ms, "w"): |
2984 self.__remotefsInterface.makedirs( |
2589 pass |
2985 self.__remotefsInterface.dirname(ms), exist_ok=True |
|
2986 ) |
|
2987 self.__remotefsInterface.writeFile(ms, b"") |
|
2988 else: |
|
2989 os.makedirs(os.path.dirname(ms), exist_ok=True) |
|
2990 with open(ms, "w"): |
|
2991 pass |
2590 except OSError as err: |
2992 except OSError as err: |
2591 EricMessageBox.critical( |
2993 EricMessageBox.critical( |
2592 self.ui, |
2994 self.ui, |
2593 self.tr("Create main script"), |
2995 self.tr("Create main script"), |
2594 self.tr( |
2996 self.tr( |
2595 "<p>The mainscript <b>{0}</b> could not" |
2997 "<p>The main script <b>{0}</b> could not" |
2596 " be created.<br/>Reason: {1}</p>" |
2998 " be created.<br/>Reason: {1}</p>" |
2597 ).format(ms, str(err)), |
2999 ).format(ms, str(err)), |
2598 ) |
3000 ) |
2599 self.appendFile(ms, True) |
3001 self.appendFile(ms, True) |
2600 else: |
3002 else: |
2601 ms = "" |
3003 ms = "" |
2602 |
3004 |
2603 if self.__pdata["MAKEPARAMS"]["MakeEnabled"]: |
3005 if self.__pdata["MAKEPARAMS"]["MakeEnabled"] and not isRemote: |
2604 mf = self.__pdata["MAKEPARAMS"]["MakeFile"] |
3006 mf = self.__pdata["MAKEPARAMS"]["MakeFile"] |
2605 if mf: |
3007 if mf: |
2606 if not os.path.isabs(mf): |
3008 if not os.path.isabs(mf): |
2607 mf = os.path.join(self.ppath, mf) |
3009 mf = os.path.join(self.ppath, mf) |
2608 else: |
3010 else: |
2629 self.tr("New Project"), |
3031 self.tr("New Project"), |
2630 self.tr("""Add existing files to the project?"""), |
3032 self.tr("""Add existing files to the project?"""), |
2631 yesDefault=True, |
3033 yesDefault=True, |
2632 ) |
3034 ) |
2633 if res: |
3035 if res: |
2634 self.newProjectAddFiles(ms) |
3036 self.newProjectAddFiles(ms, isRemote=isRemote) |
2635 addAllToVcs = res |
3037 addAllToVcs = res and not isRemote |
|
3038 |
2636 # create an empty __init__.py file to make it a Python package |
3039 # create an empty __init__.py file to make it a Python package |
2637 # if none exists (only for Python and Python3) |
3040 # if none exists (only for Python and Python3) |
2638 if self.__pdata["PROGLANGUAGE"] in ["Python3", "MicroPython"]: |
3041 if self.__pdata["PROGLANGUAGE"] in ["Python3", "MicroPython"]: |
2639 fn = os.path.join(self.ppath, "__init__.py") |
3042 if isRemote: |
2640 if not os.path.exists(fn): |
3043 fn = self.__remotefsInterface.join(self.ppath, "__init__.py") |
2641 with open(fn, "w", encoding="utf-8"): |
3044 if not self.__remotefsInterface.exists(fn): |
2642 pass |
3045 self.__remotefsInterface.writeFile(fn, b"") |
2643 self.appendFile(fn, True) |
3046 self.appendFile(fn, True) |
|
3047 else: |
|
3048 fn = os.path.join(self.ppath, "__init__.py") |
|
3049 if not os.path.exists(fn): |
|
3050 with open(fn, "w", encoding="utf-8"): |
|
3051 pass |
|
3052 self.appendFile(fn, True) |
2644 self.saveProject() |
3053 self.saveProject() |
2645 |
3054 |
2646 # check, if the existing project directory is already under |
3055 # check, if the existing project directory is already under |
2647 # VCS control |
3056 # VCS control |
2648 pluginManager = ericApp().getObject("PluginManager") |
3057 if not isRemote: |
2649 for indicator, vcsData in list( |
3058 pluginManager = ericApp().getObject("PluginManager") |
2650 pluginManager.getVcsSystemIndicators().items() |
3059 for indicator, vcsData in list( |
2651 ): |
3060 pluginManager.getVcsSystemIndicators().items() |
2652 if os.path.exists(os.path.join(self.ppath, indicator)): |
3061 ): |
2653 if len(vcsData) > 1: |
3062 if os.path.exists(os.path.join(self.ppath, indicator)): |
2654 vcsList = [] |
3063 if len(vcsData) > 1: |
2655 for _vcsSystemStr, vcsSystemDisplay in vcsData: |
3064 vcsList = [] |
2656 vcsList.append(vcsSystemDisplay) |
3065 for _vcsSystemStr, vcsSystemDisplay in vcsData: |
2657 res, vcs_ok = QInputDialog.getItem( |
3066 vcsList.append(vcsSystemDisplay) |
2658 None, |
3067 res, vcs_ok = QInputDialog.getItem( |
2659 self.tr("New Project"), |
3068 None, |
2660 self.tr("Select Version Control System"), |
3069 self.tr("New Project"), |
2661 vcsList, |
3070 self.tr("Select Version Control System"), |
2662 0, |
3071 vcsList, |
2663 False, |
3072 0, |
2664 ) |
3073 False, |
2665 if vcs_ok: |
3074 ) |
2666 for vcsSystemStr, vcsSystemDisplay in vcsData: |
3075 if vcs_ok: |
2667 if res == vcsSystemDisplay: |
3076 for vcsSystemStr, vcsSystemDisplay in vcsData: |
2668 vcsSystem = vcsSystemStr |
3077 if res == vcsSystemDisplay: |
2669 break |
3078 vcsSystem = vcsSystemStr |
|
3079 break |
|
3080 else: |
|
3081 vcsSystem = "None" |
2670 else: |
3082 else: |
2671 vcsSystem = "None" |
3083 vcsSystem = "None" |
2672 else: |
3084 else: |
2673 vcsSystem = "None" |
3085 vcsSystem = vcsData[0][1] |
2674 else: |
3086 self.__pdata["VCS"] = vcsSystem |
2675 vcsSystem = vcsData[0][1] |
3087 self.vcs = self.initVCS() |
2676 self.__pdata["VCS"] = vcsSystem |
3088 self.setDirty(True) |
2677 self.vcs = self.initVCS() |
3089 if self.vcs is not None: |
2678 self.setDirty(True) |
3090 # edit VCS command options |
2679 if self.vcs is not None: |
3091 if self.vcs.vcsSupportCommandOptions(): |
2680 # edit VCS command options |
3092 vcores = EricMessageBox.yesNo( |
2681 if self.vcs.vcsSupportCommandOptions(): |
3093 self.ui, |
2682 vcores = EricMessageBox.yesNo( |
3094 self.tr("New Project"), |
2683 self.ui, |
3095 self.tr( |
2684 self.tr("New Project"), |
3096 """Would you like to edit the VCS""" |
2685 self.tr( |
3097 """ command options?""" |
2686 """Would you like to edit the VCS""" |
3098 ), |
2687 """ command options?""" |
3099 ) |
2688 ), |
3100 else: |
2689 ) |
3101 vcores = False |
|
3102 if vcores: |
|
3103 codlg = VcsCommandOptionsDialog(self.vcs) |
|
3104 if codlg.exec() == QDialog.DialogCode.Accepted: |
|
3105 self.vcs.vcsSetOptions(codlg.getOptions()) |
|
3106 # add project file to repository |
|
3107 if res == 0: |
|
3108 apres = EricMessageBox.yesNo( |
|
3109 self.ui, |
|
3110 self.tr("New Project"), |
|
3111 self.tr( |
|
3112 "Shall the project file be added" |
|
3113 " to the repository?" |
|
3114 ), |
|
3115 yesDefault=True, |
|
3116 ) |
|
3117 if apres: |
|
3118 self.saveProject() |
|
3119 self.vcs.vcsAdd(self.pfile) |
2690 else: |
3120 else: |
2691 vcores = False |
3121 self.__pdata["VCS"] = "None" |
2692 if vcores: |
3122 self.saveProject() |
2693 codlg = VcsCommandOptionsDialog(self.vcs) |
3123 break |
2694 if codlg.exec() == QDialog.DialogCode.Accepted: |
|
2695 self.vcs.vcsSetOptions(codlg.getOptions()) |
|
2696 # add project file to repository |
|
2697 if res == 0: |
|
2698 apres = EricMessageBox.yesNo( |
|
2699 self.ui, |
|
2700 self.tr("New project"), |
|
2701 self.tr( |
|
2702 "Shall the project file be added" |
|
2703 " to the repository?" |
|
2704 ), |
|
2705 yesDefault=True, |
|
2706 ) |
|
2707 if apres: |
|
2708 self.saveProject() |
|
2709 self.vcs.vcsAdd(self.pfile) |
|
2710 else: |
|
2711 self.__pdata["VCS"] = "None" |
|
2712 self.saveProject() |
|
2713 break |
|
2714 |
3124 |
2715 # put the project under VCS control |
3125 # put the project under VCS control |
2716 if self.vcs is None and self.vcsSoftwareAvailable() and self.vcsRequested: |
3126 if ( |
|
3127 not isRemote |
|
3128 and self.vcs is None |
|
3129 and self.vcsSoftwareAvailable() |
|
3130 and self.vcsRequested |
|
3131 ): |
2717 vcsSystemsDict = ( |
3132 vcsSystemsDict = ( |
2718 ericApp() |
3133 ericApp() |
2719 .getObject("PluginManager") |
3134 .getObject("PluginManager") |
2720 .getPluginDisplayStrings("version_control") |
3135 .getPluginDisplayStrings("version_control") |
2721 ) |
3136 ) |
2779 self.newProject.emit() |
3194 self.newProject.emit() |
2780 |
3195 |
2781 # set the auto save flag to its supposed value |
3196 # set the auto save flag to its supposed value |
2782 Preferences.setProject("AutoSaveProject", autoSaveProject) |
3197 Preferences.setProject("AutoSaveProject", autoSaveProject) |
2783 |
3198 |
2784 if self.__pdata["EMBEDDED_VENV"]: |
3199 if self.__pdata[ |
|
3200 "EMBEDDED_VENV" |
|
3201 ] and not FileSystemUtilities.isRemoteFileName(self.ppath): |
2785 self.__createEmbeddedEnvironment() |
3202 self.__createEmbeddedEnvironment() |
2786 self.menuEnvironmentAct.setEnabled(self.__pdata["EMBEDDED_VENV"]) |
3203 self.menuEnvironmentAct.setEnabled( |
|
3204 self.__pdata["EMBEDDED_VENV"] |
|
3205 and not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
3206 ) |
2787 |
3207 |
2788 self.projectOpenedHooks.emit() |
3208 self.projectOpenedHooks.emit() |
2789 self.projectOpened.emit() |
3209 self.projectOpened.emit() |
2790 |
3210 |
2791 # open the main script |
3211 # open the main script |
2792 if self.__pdata["MAINSCRIPT"]: |
3212 if self.__pdata["MAINSCRIPT"]: |
2793 if not os.path.isabs(self.__pdata["MAINSCRIPT"]): |
3213 if isRemote: |
2794 ms = os.path.join(self.ppath, self.__pdata["MAINSCRIPT"]) |
3214 if not self.__remotefsInterface.isabs(self.__pdata["MAINSCRIPT"]): |
|
3215 ms = self.__remotefsInterface.join( |
|
3216 self.ppath, self.__pdata["MAINSCRIPT"] |
|
3217 ) |
|
3218 else: |
|
3219 ms = self.__pdata["MAINSCRIPT"] |
2795 else: |
3220 else: |
2796 ms = self.__pdata["MAINSCRIPT"] |
3221 if not os.path.isabs(self.__pdata["MAINSCRIPT"]): |
|
3222 ms = os.path.join(self.ppath, self.__pdata["MAINSCRIPT"]) |
|
3223 else: |
|
3224 ms = self.__pdata["MAINSCRIPT"] |
2797 self.sourceFile.emit(ms) |
3225 self.sourceFile.emit(ms) |
2798 |
3226 |
2799 def newProjectAddFiles(self, mainscript): |
3227 def newProjectAddFiles(self, mainscript, isRemote=False): |
2800 """ |
3228 """ |
2801 Public method to add files to a new project. |
3229 Public method to add files to a new project. |
2802 |
3230 |
2803 @param mainscript name of the mainscript |
3231 @param mainscript name of the mainscript |
2804 @type str |
3232 @type str |
|
3233 @param isRemote flag indicating a remote project (defaults to False) |
|
3234 @type bool (optional) |
2805 """ |
3235 """ |
2806 # Show the file type associations for the user to change |
3236 # Show the file type associations for the user to change |
2807 self.__showFiletypeAssociations() |
3237 self.__showFiletypeAssociations() |
2808 |
3238 |
2809 ignoreList = [] |
3239 ignoreList = [] |
2810 if self.__pdata["EMBEDDED_VENV"]: |
3240 if self.__pdata["EMBEDDED_VENV"]: |
2811 environmentPath = self.__findEmbeddedEnvironment() |
3241 environmentPath = self.__findEmbeddedEnvironment() |
2812 if environmentPath: |
3242 if environmentPath: |
2813 # there is already an embeded venv; ignore thie whenn adding files |
3243 # there is already an embedded venv; ignore this when adding files |
2814 ignoreList = [os.path.split(environmentPath)[-1]] |
3244 ignoreList = ( |
|
3245 [self.__remotefsInterface.split(environmentPath)[-1]] |
|
3246 if isRemote |
|
3247 else [os.path.split(environmentPath)[-1]] |
|
3248 ) |
2815 with EricOverrideCursor(): |
3249 with EricOverrideCursor(): |
2816 # search the project directory for files with known extensions |
3250 # search the project directory for files with known extensions |
2817 for filespec in self.__pdata["FILETYPES"]: |
3251 for filespec in self.__pdata["FILETYPES"]: |
2818 files = FileSystemUtilities.direntries( |
3252 files = ( |
2819 self.ppath, |
3253 self.__remotefsInterface.direntries( |
2820 filesonly=True, |
3254 self.ppath, |
2821 pattern=filespec, |
3255 filesonly=True, |
2822 ignore=ignoreList, |
3256 pattern=filespec, |
|
3257 ignore=ignoreList, |
|
3258 ) |
|
3259 if isRemote |
|
3260 else FileSystemUtilities.direntries( |
|
3261 self.ppath, |
|
3262 filesonly=True, |
|
3263 pattern=filespec, |
|
3264 ignore=ignoreList, |
|
3265 ) |
2823 ) |
3266 ) |
2824 for file in files: |
3267 for file in files: |
2825 self.appendFile(file) |
3268 self.appendFile(file) |
2826 |
3269 |
2827 # special handling for translation files |
3270 # special handling for translation files |
2828 if self.translationsRoot: |
3271 if self.translationsRoot: |
2829 tpd = os.path.join(self.ppath, self.translationsRoot) |
3272 if isRemote: |
2830 if not self.translationsRoot.endswith(os.sep): |
3273 tpd = self.__remotefsInterface.join( |
2831 tpd = os.path.dirname(tpd) |
3274 self.ppath, self.translationsRoot |
|
3275 ) |
|
3276 if not self.translationsRoot.endswith(os.sep): |
|
3277 tpd = self.__remotefsInterface.dirname(tpd) |
|
3278 else: |
|
3279 tpd = os.path.join(self.ppath, self.translationsRoot) |
|
3280 if not self.translationsRoot.endswith(os.sep): |
|
3281 tpd = os.path.dirname(tpd) |
2832 else: |
3282 else: |
2833 tpd = self.ppath |
3283 tpd = self.ppath |
2834 tslist = [] |
3284 tslist = [] |
2835 if self.__pdata["TRANSLATIONPATTERN"]: |
3285 if self.__pdata["TRANSLATIONPATTERN"]: |
2836 pattern = os.path.basename(self.__pdata["TRANSLATIONPATTERN"]) |
3286 pattern = ( |
|
3287 self.__remotefsInterface.basename( |
|
3288 self.__pdata["TRANSLATIONPATTERN"] |
|
3289 ) |
|
3290 if isRemote |
|
3291 else os.path.basename(self.__pdata["TRANSLATIONPATTERN"]) |
|
3292 ) |
2837 if "%language%" in pattern: |
3293 if "%language%" in pattern: |
2838 pattern = pattern.replace("%language%", "*") |
3294 pattern = pattern.replace("%language%", "*") |
2839 else: |
3295 else: |
2840 tpd = self.__pdata["TRANSLATIONPATTERN"].split("%language%")[0] |
3296 tpd = self.__pdata["TRANSLATIONPATTERN"].split("%language%")[0] |
2841 else: |
3297 else: |
2842 pattern = "*.ts" |
3298 pattern = "*.ts" |
2843 tslist.extend(FileSystemUtilities.direntries(tpd, True, pattern)) |
3299 tslist.extend( |
|
3300 self.__remotefsInterface.direntries(tpd, True, pattern) |
|
3301 if isRemote |
|
3302 else FileSystemUtilities.direntries(tpd, True, pattern) |
|
3303 ) |
|
3304 |
2844 pattern = self.__binaryTranslationFile(pattern) |
3305 pattern = self.__binaryTranslationFile(pattern) |
2845 if pattern: |
3306 if pattern: |
2846 tslist.extend(FileSystemUtilities.direntries(tpd, True, pattern)) |
3307 tslist.extend( |
|
3308 self.__remotefsInterface.direntries(tpd, True, pattern) |
|
3309 if isRemote |
|
3310 else FileSystemUtilities.direntries(tpd, True, pattern) |
|
3311 ) |
2847 if tslist: |
3312 if tslist: |
2848 if "_" in os.path.basename(tslist[0]): |
3313 hasUnderscore = ( |
2849 # the first entry determines the mainscript name |
3314 "_" in self.__remotefsInterface.basename(tslist[0]) |
2850 mainscriptname = ( |
3315 if isRemote |
2851 os.path.splitext(mainscript)[0] |
3316 else "_" in os.path.basename(tslist[0]) |
2852 or os.path.basename(tslist[0]).split("_")[0] |
3317 ) |
2853 ) |
3318 if hasUnderscore: |
2854 self.__pdata["TRANSLATIONPATTERN"] = os.path.join( |
3319 # the first entry determines the main script name |
2855 os.path.dirname(tslist[0]), |
3320 if isRemote: |
2856 "{0}_%language%{1}".format( |
3321 mainscriptname = ( |
2857 os.path.basename(tslist[0]).split("_")[0], |
3322 self.__remotefsInterface.splitext(mainscript)[0] |
2858 os.path.splitext(tslist[0])[1], |
3323 or self.__remotefsInterface.basename(tslist[0]).split("_")[ |
2859 ), |
3324 0 |
2860 ) |
3325 ] |
|
3326 ) |
|
3327 self.__pdata["TRANSLATIONPATTERN"] = ( |
|
3328 self.__remotefsInterface.join( |
|
3329 self.__remotefsInterface.dirname(tslist[0]), |
|
3330 "{0}_%language%{1}".format( |
|
3331 self.__remotefsInterface.basename(tslist[0]).split( |
|
3332 "_" |
|
3333 )[0], |
|
3334 self.__remotefsInterface.splitext(tslist[0])[1], |
|
3335 ), |
|
3336 ) |
|
3337 ) |
|
3338 else: |
|
3339 mainscriptname = ( |
|
3340 os.path.splitext(mainscript)[0] |
|
3341 or os.path.basename(tslist[0]).split("_")[0] |
|
3342 ) |
|
3343 self.__pdata["TRANSLATIONPATTERN"] = os.path.join( |
|
3344 os.path.dirname(tslist[0]), |
|
3345 "{0}_%language%{1}".format( |
|
3346 os.path.basename(tslist[0]).split("_")[0], |
|
3347 os.path.splitext(tslist[0])[1], |
|
3348 ), |
|
3349 ) |
2861 else: |
3350 else: |
2862 mainscriptname = "" |
3351 mainscriptname = "" |
2863 pattern, ok = QInputDialog.getText( |
3352 pattern, ok = QInputDialog.getText( |
2864 None, |
3353 None, |
2865 self.tr("Translation Pattern"), |
3354 self.tr("Translation Pattern"), |
2883 for ts in tslist: |
3372 for ts in tslist: |
2884 if fnmatch.fnmatch(ts, pattern): |
3373 if fnmatch.fnmatch(ts, pattern): |
2885 self.__pdata["TRANSLATIONS"].append(ts) |
3374 self.__pdata["TRANSLATIONS"].append(ts) |
2886 self.projectFileAdded.emit(ts, "TRANSLATIONS") |
3375 self.projectFileAdded.emit(ts, "TRANSLATIONS") |
2887 if self.__pdata["TRANSLATIONSBINPATH"]: |
3376 if self.__pdata["TRANSLATIONSBINPATH"]: |
2888 tpd = os.path.join( |
3377 if isRemote: |
2889 self.ppath, self.__pdata["TRANSLATIONSBINPATH"] |
3378 tpd = self.__remotefsInterface.join( |
2890 ) |
3379 self.ppath, self.__pdata["TRANSLATIONSBINPATH"] |
2891 pattern = os.path.basename( |
3380 ) |
2892 self.__pdata["TRANSLATIONPATTERN"] |
3381 pattern = self.__remotefsInterface.basename( |
2893 ).replace("%language%", "*") |
3382 self.__pdata["TRANSLATIONPATTERN"] |
|
3383 ).replace("%language%", "*") |
|
3384 else: |
|
3385 tpd = os.path.join( |
|
3386 self.ppath, self.__pdata["TRANSLATIONSBINPATH"] |
|
3387 ) |
|
3388 pattern = os.path.basename( |
|
3389 self.__pdata["TRANSLATIONPATTERN"] |
|
3390 ).replace("%language%", "*") |
2894 pattern = self.__binaryTranslationFile(pattern) |
3391 pattern = self.__binaryTranslationFile(pattern) |
2895 qmlist = FileSystemUtilities.direntries(tpd, True, pattern) |
3392 qmlist = FileSystemUtilities.direntries(tpd, True, pattern) |
2896 for qm in qmlist: |
3393 for qm in qmlist: |
2897 self.__pdata["TRANSLATIONS"].append(qm) |
3394 self.__pdata["TRANSLATIONS"].append(qm) |
2898 self.projectFileAdded.emit(qm, "TRANSLATIONS") |
3395 self.projectFileAdded.emit(qm, "TRANSLATIONS") |
2907 """ |
3404 """ |
2908 Private slot to display the properties dialog. |
3405 Private slot to display the properties dialog. |
2909 """ |
3406 """ |
2910 from .PropertiesDialog import PropertiesDialog |
3407 from .PropertiesDialog import PropertiesDialog |
2911 |
3408 |
2912 dlg = PropertiesDialog(self, new=False) |
3409 isRemote = FileSystemUtilities.isRemoteFileName(self.ppath) |
|
3410 dlg = PropertiesDialog(self, new=False, isRemote=isRemote) |
2913 if dlg.exec() == QDialog.DialogCode.Accepted: |
3411 if dlg.exec() == QDialog.DialogCode.Accepted: |
2914 fileTypesDict = copy.copy(self.__pdata["FILETYPES"]) |
3412 fileTypesDict = copy.copy(self.__pdata["FILETYPES"]) |
2915 dlg.storeData() |
3413 dlg.storeData() |
2916 self.setDirty(True) |
3414 self.setDirty(True) |
2917 if self.__pdata["MAINSCRIPT"]: |
3415 if self.__pdata["MAINSCRIPT"]: |
2918 if not os.path.isabs(self.__pdata["MAINSCRIPT"]): |
3416 if isRemote: |
2919 ms = os.path.join(self.ppath, self.__pdata["MAINSCRIPT"]) |
3417 if not self.__remotefsInterface.isabs(self.__pdata["MAINSCRIPT"]): |
|
3418 ms = self.__remotefsInterface.join( |
|
3419 self.ppath, self.__pdata["MAINSCRIPT"] |
|
3420 ) |
|
3421 else: |
|
3422 ms = self.__pdata["MAINSCRIPT"] |
|
3423 if self.__remotefsInterface.exists(ms): |
|
3424 self.appendFile(ms) |
2920 else: |
3425 else: |
2921 ms = self.__pdata["MAINSCRIPT"] |
3426 if not os.path.isabs(self.__pdata["MAINSCRIPT"]): |
2922 if os.path.exists(ms): |
3427 ms = os.path.join(self.ppath, self.__pdata["MAINSCRIPT"]) |
2923 self.appendFile(ms) |
3428 else: |
|
3429 ms = self.__pdata["MAINSCRIPT"] |
|
3430 if os.path.exists(ms): |
|
3431 self.appendFile(ms) |
2924 |
3432 |
2925 if self.__pdata["MAKEPARAMS"]["MakeEnabled"]: |
3433 if self.__pdata["MAKEPARAMS"]["MakeEnabled"]: |
2926 mf = self.__pdata["MAKEPARAMS"]["MakeFile"] |
3434 mf = self.__pdata["MAKEPARAMS"]["MakeFile"] |
2927 if mf: |
3435 if isRemote: |
2928 if not os.path.isabs(mf): |
3436 if mf: |
2929 mf = os.path.join(self.ppath, mf) |
3437 if not self.__remotefsInterface.isabs(mf): |
|
3438 mf = self.__remotefsInterface.join(self.ppath, mf) |
|
3439 else: |
|
3440 mf = self.__remotefsInterface.join( |
|
3441 self.ppath, Project.DefaultMakefile |
|
3442 ) |
|
3443 exists = self.__remotefsInterface.exists(mf) |
2930 else: |
3444 else: |
2931 mf = os.path.join(self.ppath, Project.DefaultMakefile) |
3445 if mf: |
2932 if not os.path.exists(mf): |
3446 if not os.path.isabs(mf): |
|
3447 mf = os.path.join(self.ppath, mf) |
|
3448 else: |
|
3449 mf = os.path.join(self.ppath, Project.DefaultMakefile) |
|
3450 exists = os.path.exists(mf) |
|
3451 if not exists: |
2933 try: |
3452 try: |
2934 with open(mf, "w"): |
3453 if isRemote: |
2935 pass |
3454 self.__remotefsInterface.writeFile(mf, b"") |
|
3455 else: |
|
3456 with open(mf, "w"): |
|
3457 pass |
2936 except OSError as err: |
3458 except OSError as err: |
2937 EricMessageBox.critical( |
3459 EricMessageBox.critical( |
2938 self.ui, |
3460 self.ui, |
2939 self.tr("Create Makefile"), |
3461 self.tr("Create Makefile"), |
2940 self.tr( |
3462 self.tr( |
2943 ).format(mf, str(err)), |
3465 ).format(mf, str(err)), |
2944 ) |
3466 ) |
2945 self.appendFile(mf) |
3467 self.appendFile(mf) |
2946 |
3468 |
2947 if self.translationsRoot: |
3469 if self.translationsRoot: |
2948 tp = os.path.join(self.ppath, self.translationsRoot) |
3470 if isRemote: |
2949 if not self.translationsRoot.endswith(os.sep): |
3471 tp = self.__remotefsInterface.join( |
2950 tp = os.path.dirname(tp) |
3472 self.ppath, self.translationsRoot |
|
3473 ) |
|
3474 if not self.translationsRoot.endswith( |
|
3475 self.__remotefsInterface.separator() |
|
3476 ): |
|
3477 tp = self.__remotefsInterface.dirname(tp) |
|
3478 if not self.__remotefsInterface.isdir(tp): |
|
3479 self.__remotefsInterface.makedirs(tp) |
|
3480 else: |
|
3481 tp = os.path.join(self.ppath, self.translationsRoot) |
|
3482 if not self.translationsRoot.endswith(os.sep): |
|
3483 tp = os.path.dirname(tp) |
|
3484 if not os.path.isdir(tp): |
|
3485 os.makedirs(tp) |
2951 else: |
3486 else: |
2952 tp = self.ppath |
3487 tp = self.ppath |
2953 if not os.path.isdir(tp): |
|
2954 os.makedirs(tp) |
|
2955 if tp != self.ppath and tp not in self.subdirs: |
3488 if tp != self.ppath and tp not in self.subdirs: |
2956 self.subdirs.append(tp) |
3489 self.subdirs.append(tp) |
2957 |
3490 |
2958 if self.__pdata["TRANSLATIONSBINPATH"]: |
3491 if self.__pdata["TRANSLATIONSBINPATH"]: |
2959 tp = os.path.join(self.ppath, self.__pdata["TRANSLATIONSBINPATH"]) |
3492 if isRemote: |
2960 if not os.path.isdir(tp): |
3493 tp = self.__remotefsInterface.join( |
2961 os.makedirs(tp) |
3494 self.ppath, self.__pdata["TRANSLATIONSBINPATH"] |
|
3495 ) |
|
3496 if not self.__remotefsInterface.isdir(tp): |
|
3497 self.__remotefsInterface.makedirs(tp) |
|
3498 else: |
|
3499 tp = os.path.join(self.ppath, self.__pdata["TRANSLATIONSBINPATH"]) |
|
3500 if not os.path.isdir(tp): |
|
3501 os.makedirs(tp) |
2962 if tp != self.ppath and tp not in self.subdirs: |
3502 if tp != self.ppath and tp not in self.subdirs: |
2963 self.subdirs.append(tp) |
3503 self.subdirs.append(tp) |
2964 |
3504 |
2965 self.pluginGrp.setEnabled(self.__pdata["PROJECTTYPE"] in ["E7Plugin"]) |
3505 self.pluginGrp.setEnabled(self.__pdata["PROJECTTYPE"] in ["E7Plugin"]) |
2966 |
3506 |
3143 self.__readUserProperties() |
3687 self.__readUserProperties() |
3144 |
3688 |
3145 with EricOverrideCursor(): |
3689 with EricOverrideCursor(): |
3146 oldState = self.isDirty() |
3690 oldState = self.isDirty() |
3147 self.vcs = self.initVCS() |
3691 self.vcs = self.initVCS() |
3148 if self.vcs is None and self.isDirty() == oldState: |
3692 if not FileSystemUtilities.isRemoteFileName(self.ppath): |
3149 # check, if project is version controlled |
3693 if self.vcs is None and self.isDirty() == oldState: |
3150 pluginManager = ericApp().getObject("PluginManager") |
3694 # check, if project is version controlled |
3151 for ( |
3695 pluginManager = ericApp().getObject("PluginManager") |
3152 indicator, |
3696 for ( |
3153 vcsData, |
3697 indicator, |
3154 ) in pluginManager.getVcsSystemIndicators().items(): |
3698 vcsData, |
3155 if os.path.exists(os.path.join(self.ppath, indicator)): |
3699 ) in pluginManager.getVcsSystemIndicators().items(): |
3156 if len(vcsData) > 1: |
3700 if os.path.exists(os.path.join(self.ppath, indicator)): |
3157 vcsList = [] |
3701 if len(vcsData) > 1: |
3158 for _vcsSystemStr, vcsSystemDisplay in vcsData: |
3702 vcsList = [] |
3159 vcsList.append(vcsSystemDisplay) |
3703 for _vcsSystemStr, vcsSystemDisplay in vcsData: |
3160 with EricOverridenCursor(): |
3704 vcsList.append(vcsSystemDisplay) |
3161 res, vcs_ok = QInputDialog.getItem( |
3705 with EricOverridenCursor(): |
3162 None, |
3706 res, vcs_ok = QInputDialog.getItem( |
3163 self.tr("New Project"), |
3707 None, |
3164 self.tr("Select Version Control System"), |
3708 self.tr("New Project"), |
3165 vcsList, |
3709 self.tr( |
3166 0, |
3710 "Select Version Control System" |
3167 False, |
3711 ), |
3168 ) |
3712 vcsList, |
3169 if vcs_ok: |
3713 0, |
3170 for vcsSystemStr, vcsSystemDisplay in vcsData: |
3714 False, |
3171 if res == vcsSystemDisplay: |
3715 ) |
3172 vcsSystem = vcsSystemStr |
3716 if vcs_ok: |
3173 break |
3717 for ( |
|
3718 vcsSystemStr, |
|
3719 vcsSystemDisplay, |
|
3720 ) in vcsData: |
|
3721 if res == vcsSystemDisplay: |
|
3722 vcsSystem = vcsSystemStr |
|
3723 break |
|
3724 else: |
|
3725 vcsSystem = "None" |
3174 else: |
3726 else: |
3175 vcsSystem = "None" |
3727 vcsSystem = "None" |
3176 else: |
3728 else: |
3177 vcsSystem = "None" |
3729 vcsSystem = vcsData[0][0] |
3178 else: |
3730 self.__pdata["VCS"] = vcsSystem |
3179 vcsSystem = vcsData[0][0] |
3731 self.vcs = self.initVCS() |
3180 self.__pdata["VCS"] = vcsSystem |
3732 self.setDirty(True) |
3181 self.vcs = self.initVCS() |
3733 if self.vcs is not None and ( |
3182 self.setDirty(True) |
3734 self.vcs.vcsRegisteredState(self.ppath) |
3183 if self.vcs is not None and ( |
3735 != VersionControlState.Controlled |
3184 self.vcs.vcsRegisteredState(self.ppath) |
3736 ): |
3185 != VersionControlState.Controlled |
3737 self.__pdata["VCS"] = "None" |
3186 ): |
3738 self.vcs = self.initVCS() |
3187 self.__pdata["VCS"] = "None" |
|
3188 self.vcs = self.initVCS() |
|
3189 self.reloadAct.setEnabled(True) |
3739 self.reloadAct.setEnabled(True) |
3190 self.closeAct.setEnabled(True) |
3740 self.closeAct.setEnabled(True) |
3191 self.saveasAct.setEnabled(True) |
3741 self.saveasAct.setEnabled(True) |
|
3742 self.saveasRemoteAct.setEnabled( |
|
3743 self.__remoteServer.isServerConnected() |
|
3744 and FileSystemUtilities.isRemoteFileName(self.pfile) |
|
3745 ) |
3192 self.actGrp2.setEnabled(True) |
3746 self.actGrp2.setEnabled(True) |
3193 self.propsAct.setEnabled(True) |
3747 self.propsAct.setEnabled(True) |
3194 self.userPropsAct.setEnabled(True) |
3748 self.userPropsAct.setEnabled( |
|
3749 not FileSystemUtilities.isRemoteFileName(self.pfile) |
|
3750 ) |
3195 self.filetypesAct.setEnabled(True) |
3751 self.filetypesAct.setEnabled(True) |
3196 self.lexersAct.setEnabled(True) |
3752 self.lexersAct.setEnabled(True) |
3197 self.sessActGrp.setEnabled(True) |
3753 self.sessActGrp.setEnabled(True) |
3198 self.dbgActGrp.setEnabled(True) |
3754 self.dbgActGrp.setEnabled(True) |
3199 self.menuDebuggerAct.setEnabled(True) |
3755 self.menuDebuggerAct.setEnabled(True) |
3200 self.menuSessionAct.setEnabled(True) |
3756 self.menuSessionAct.setEnabled(True) |
3201 self.menuCheckAct.setEnabled(True) |
3757 self.menuCheckAct.setEnabled(True) |
3202 self.menuShowAct.setEnabled(True) |
3758 self.menuShowAct.setEnabled(True) |
3203 self.menuDiagramAct.setEnabled(True) |
3759 self.menuDiagramAct.setEnabled(True) |
3204 self.menuApidocAct.setEnabled(True) |
3760 self.menuApidocAct.setEnabled( |
3205 self.menuPackagersAct.setEnabled(True) |
3761 not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
3762 ) |
|
3763 self.menuPackagersAct.setEnabled( |
|
3764 not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
3765 ) |
3206 self.pluginGrp.setEnabled( |
3766 self.pluginGrp.setEnabled( |
3207 self.__pdata["PROJECTTYPE"] in ["E7Plugin"] |
3767 self.__pdata["PROJECTTYPE"] in ["E7Plugin"] |
|
3768 and not FileSystemUtilities.isRemoteFileName(self.ppath) |
3208 ) |
3769 ) |
3209 self.addLanguageAct.setEnabled( |
3770 self.addLanguageAct.setEnabled( |
3210 bool(self.__pdata["TRANSLATIONPATTERN"]) |
3771 bool(self.__pdata["TRANSLATIONPATTERN"]) |
3211 ) |
3772 ) |
3212 self.makeGrp.setEnabled(self.__pdata["MAKEPARAMS"]["MakeEnabled"]) |
3773 self.makeGrp.setEnabled( |
|
3774 self.__pdata["MAKEPARAMS"]["MakeEnabled"] |
|
3775 and not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
3776 ) |
3213 self.menuMakeAct.setEnabled( |
3777 self.menuMakeAct.setEnabled( |
3214 self.__pdata["MAKEPARAMS"]["MakeEnabled"] |
3778 self.__pdata["MAKEPARAMS"]["MakeEnabled"] |
|
3779 and not FileSystemUtilities.isRemoteFileName(self.ppath) |
3215 ) |
3780 ) |
3216 self.menuOtherToolsAct.setEnabled(True) |
3781 self.menuOtherToolsAct.setEnabled(True) |
3217 self.menuFormattingAct.setEnabled(True) |
3782 self.menuFormattingAct.setEnabled( |
|
3783 not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
3784 ) |
|
3785 self.menuVcsAct.setEnabled( |
|
3786 not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
3787 ) |
3218 |
3788 |
3219 # open a project debugger properties file being quiet |
3789 # open a project debugger properties file being quiet |
3220 # about errors |
3790 # about errors |
3221 if Preferences.getProject("AutoLoadDbgProperties"): |
3791 if Preferences.getProject("AutoLoadDbgProperties"): |
3222 self.__readDebugProperties(True) |
3792 self.__readDebugProperties(True) |
3223 |
3793 |
3224 self.__model.projectOpened() |
3794 self.__model.projectOpened() |
3225 |
3795 |
3226 if self.__pdata["EMBEDDED_VENV"]: |
3796 if self.__pdata[ |
|
3797 "EMBEDDED_VENV" |
|
3798 ] and not FileSystemUtilities.isRemoteFileName(self.ppath): |
3227 envPath = self.__findEmbeddedEnvironment() |
3799 envPath = self.__findEmbeddedEnvironment() |
3228 if bool(envPath): |
3800 if bool(envPath): |
3229 self.__loadEnvironmentConfiguration() |
3801 self.__loadEnvironmentConfiguration() |
3230 if not bool( |
3802 if not bool( |
3231 self.__venvConfiguration["interpreter"] |
3803 self.__venvConfiguration["interpreter"] |
3787 |
4387 |
3788 @return name of the project |
4388 @return name of the project |
3789 @rtype str |
4389 @rtype str |
3790 """ |
4390 """ |
3791 if self.pfile: |
4391 if self.pfile: |
3792 name = os.path.splitext(self.pfile)[0] |
4392 return self.name |
3793 return os.path.basename(name) |
|
3794 else: |
4393 else: |
3795 return "" |
4394 return "" |
3796 |
4395 |
3797 def getProjectManagementDir(self): |
4396 def getProjectManagementDir(self): |
3798 """ |
4397 """ |
3799 Public method to get the path of the management directory. |
4398 Public method to get the path of the management directory. |
3800 |
4399 |
3801 @return path of the management directory |
4400 @return path of the management directory |
3802 @rtype str |
4401 @rtype str |
3803 """ |
4402 """ |
3804 return os.path.join(self.ppath, ".eric7project") |
4403 if FileSystemUtilities.isRemoteFileName(self.ppath): |
|
4404 return self.__remotefsInterface.join(self.ppath, ".eric7project") |
|
4405 else: |
|
4406 return os.path.join(self.ppath, ".eric7project") |
3805 |
4407 |
3806 def createProjectManagementDir(self): |
4408 def createProjectManagementDir(self): |
3807 """ |
4409 """ |
3808 Public method to create the project management directory. |
4410 Public method to create the project management directory. |
3809 |
4411 |
3810 It does nothing, if it already exists. |
4412 It does nothing, if it already exists. |
3811 """ |
4413 """ |
3812 # create management directory if not present |
4414 # create management directory if not present |
3813 mgmtDir = self.getProjectManagementDir() |
4415 mgmtDir = self.getProjectManagementDir() |
3814 if not os.path.exists(mgmtDir): |
4416 if FileSystemUtilities.isRemoteFileName(mgmtDir): |
3815 os.makedirs(mgmtDir) |
4417 self.__remotefsInterface.makedirs(mgmtDir, exist_ok=True) |
|
4418 else: |
|
4419 os.makedirs(mgmtDir, exist_ok=True) |
3816 |
4420 |
3817 def getHash(self): |
4421 def getHash(self): |
3818 """ |
4422 """ |
3819 Public method to get the project hash. |
4423 Public method to get the project hash. |
3820 |
4424 |
3821 @return project hash as a hex string |
4425 @return project hash as a hex string |
3822 @rtype str |
4426 @rtype str |
3823 """ |
4427 """ |
3824 return self.__pdata["HASH"] |
4428 return self.__pdata["HASH"] |
3825 |
4429 |
3826 def getRelativePath(self, path): |
4430 def getRelativePath(self, fullpath): |
3827 """ |
4431 """ |
3828 Public method to convert a file path to a project relative |
4432 Public method to convert a file path to a project relative |
3829 file path. |
4433 file path. |
3830 |
4434 |
3831 @param path file or directory name to convert |
4435 @param fullpath file or directory name to convert |
3832 @type str |
4436 @type str |
3833 @return project relative path or unchanged path, if path doesn't |
4437 @return project relative path or unchanged path, if path doesn't |
3834 belong to the project |
4438 belong to the project |
3835 @rtype str |
4439 @rtype str |
3836 """ |
4440 """ |
3837 if path is None: |
4441 if fullpath is None: |
3838 return "" |
4442 return "" |
3839 |
4443 |
3840 try: |
4444 try: |
3841 return str(pathlib.Path(path).relative_to(self.ppath)) |
4445 if FileSystemUtilities.isRemoteFileName(self.ppath): |
|
4446 if self.__remotefsInterface.separator() == "\\": |
|
4447 return str( |
|
4448 pathlib.PureWindowsPath(fullpath).relative_to(self.ppath) |
|
4449 ) |
|
4450 else: |
|
4451 return str(pathlib.PurePosixPath(fullpath).relative_to(self.ppath)) |
|
4452 else: |
|
4453 return str(pathlib.PurePath(fullpath).relative_to(self.ppath)) |
3842 except ValueError: |
4454 except ValueError: |
3843 return path |
4455 return fullpath |
3844 |
4456 |
3845 def getRelativeUniversalPath(self, path): |
4457 def getRelativeUniversalPath(self, fullpath): |
3846 """ |
4458 """ |
3847 Public method to convert a file path to a project relative |
4459 Public method to convert a file path to a project relative |
3848 file path with universal separators. |
4460 file path with universal separators. |
3849 |
4461 |
3850 @param path file or directory name to convert |
4462 @param fullpath file or directory name to convert |
3851 @type str |
4463 @type str |
3852 @return project relative path or unchanged path, if path doesn't |
4464 @return project relative path or unchanged path, if path doesn't |
3853 belong to the project |
4465 belong to the project |
3854 @rtype str |
4466 @rtype str |
3855 """ |
4467 """ |
3856 return FileSystemUtilities.fromNativeSeparators(self.getRelativePath(path)) |
4468 if FileSystemUtilities.isRemoteFileName(self.ppath): |
|
4469 return self.__remotefsInterface.fromNativeSeparators( |
|
4470 self.getRelativePath(fullpath) |
|
4471 ) |
|
4472 else: |
|
4473 return FileSystemUtilities.fromNativeSeparators( |
|
4474 self.getRelativePath(fullpath) |
|
4475 ) |
3857 |
4476 |
3858 def getAbsolutePath(self, fn): |
4477 def getAbsolutePath(self, fn): |
3859 """ |
4478 """ |
3860 Public method to convert a project relative file path to an absolute |
4479 Public method to convert a project relative file path to an absolute |
3861 file path. |
4480 file path. |
5450 def __showMenu(self): |
6143 def __showMenu(self): |
5451 """ |
6144 """ |
5452 Private method to set up the project menu. |
6145 Private method to set up the project menu. |
5453 """ |
6146 """ |
5454 self.menuRecentAct.setEnabled(len(self.recent) > 0) |
6147 self.menuRecentAct.setEnabled(len(self.recent) > 0) |
5455 self.menuEnvironmentAct.setEnabled(self.__pdata["EMBEDDED_VENV"]) |
6148 self.menuEnvironmentAct.setEnabled( |
|
6149 self.__pdata["EMBEDDED_VENV"] |
|
6150 and not FileSystemUtilities.isRemoteFileName(self.ppath) |
|
6151 ) |
5456 |
6152 |
5457 self.showMenu.emit("Main", self.__menus["Main"]) |
6153 self.showMenu.emit("Main", self.__menus["Main"]) |
5458 |
6154 |
5459 def __syncRecent(self): |
6155 def __syncRecent(self): |
5460 """ |
6156 """ |
5461 Private method to synchronize the list of recently opened projects |
6157 Private method to synchronize the list of recently opened projects |
5462 with the central store. |
6158 with the central store. |
5463 """ |
6159 """ |
5464 for recent in self.recent[:]: |
6160 for recent in self.recent[:]: |
5465 if FileSystemUtilities.samepath(self.pfile, recent): |
6161 if ( |
|
6162 FileSystemUtilities.isRemoteFileName(recent) and recent == self.pfile |
|
6163 ) or FileSystemUtilities.samepath(self.pfile, recent): |
5466 self.recent.remove(recent) |
6164 self.recent.remove(recent) |
5467 self.recent.insert(0, self.pfile) |
6165 self.recent.insert(0, self.pfile) |
5468 maxRecent = Preferences.getProject("RecentNumber") |
6166 maxRecent = Preferences.getProject("RecentNumber") |
5469 if len(self.recent) > maxRecent: |
6167 if len(self.recent) > maxRecent: |
5470 self.recent = self.recent[:maxRecent] |
6168 self.recent = self.recent[:maxRecent] |
5594 continue |
6319 continue |
5595 |
6320 |
5596 # set fn to project relative name |
6321 # set fn to project relative name |
5597 # then reset ns to fully qualified name for insertion, |
6322 # then reset ns to fully qualified name for insertion, |
5598 # possibly. |
6323 # possibly. |
5599 fn = os.path.join(directory, ns) if directory else ns |
6324 if isRemote: |
5600 ns = os.path.abspath(os.path.join(curpath, ns)) |
6325 fn = ( |
|
6326 self.__remotefsInterface.join(directory, ns) |
|
6327 if directory |
|
6328 else ns |
|
6329 ) |
|
6330 ns = self.__remotefsInterface.abspath( |
|
6331 self.__remotefsInterface.join(curpath, ns) |
|
6332 ) |
|
6333 |
|
6334 isdir_ns = self.__remotefsInterface.isdir(ns) |
|
6335 else: |
|
6336 fn = os.path.join(directory, ns) if directory else ns |
|
6337 ns = os.path.abspath(os.path.join(curpath, ns)) |
|
6338 isdir_ns = os.path.isdir(ns) |
5601 |
6339 |
5602 # do not bother with dirs here... |
6340 # do not bother with dirs here... |
5603 if os.path.isdir(ns): |
6341 if isdir_ns: |
5604 if recursiveSearch: |
6342 if recursiveSearch: |
5605 d = self.getRelativePath(ns) |
6343 d = self.getRelativePath(ns) |
5606 if d not in dirs: |
6344 if d not in dirs: |
5607 dirs.append(d) # noqa: M569 |
6345 dirs.append(d) # noqa: M569 |
5608 continue |
6346 continue |
5609 |
6347 |
5610 filetype = "" |
6348 filetype = "" |
5611 bfn = os.path.basename(fn) |
6349 bfn = ( |
|
6350 self.__remotefsInterface.basename(fn) |
|
6351 if isRemote |
|
6352 else os.path.basename(fn) |
|
6353 ) |
5612 |
6354 |
5613 # check against ignore patterns first (see issue 553) |
6355 # check against ignore patterns first (see issue 553) |
5614 if any( |
6356 if any( |
5615 fnmatch.fnmatch(bfn, ignore_pattern) |
6357 fnmatch.fnmatch(bfn, ignore_pattern) |
5616 for ignore_pattern in ignore_patterns |
6358 for ignore_pattern in ignore_patterns |
6604 Public method to test, if make is enabled for the project. |
7366 Public method to test, if make is enabled for the project. |
6605 |
7367 |
6606 @return flag indicating enabled make support |
7368 @return flag indicating enabled make support |
6607 @rtype bool |
7369 @rtype bool |
6608 """ |
7370 """ |
6609 return self.__pdata["MAKEPARAMS"]["MakeEnabled"] |
7371 return self.__pdata["MAKEPARAMS"][ |
|
7372 "MakeEnabled" |
|
7373 ] and not FileSystemUtilities.isRemoteFileName(self.ppath) |
6610 |
7374 |
6611 @pyqtSlot() |
7375 @pyqtSlot() |
6612 def __autoExecuteMake(self): |
7376 def __autoExecuteMake(self): |
6613 """ |
7377 """ |
6614 Private slot to execute a project specific make run (auto-run) |
7378 Private slot to execute a project specific make run (auto-run) |
6615 (execute or question). |
7379 (execute or question). |
6616 """ |
7380 """ |
6617 if Preferences.getProject("AutoExecuteMake"): |
7381 if Preferences.getProject( |
|
7382 "AutoExecuteMake" |
|
7383 ) and not FileSystemUtilities.isRemoteFileName(self.ppath): |
6618 self.__executeMake(questionOnly=self.__pdata["MAKEPARAMS"]["MakeTestOnly"]) |
7384 self.__executeMake(questionOnly=self.__pdata["MAKEPARAMS"]["MakeTestOnly"]) |
6619 |
7385 |
6620 @pyqtSlot() |
7386 @pyqtSlot() |
6621 def __executeMake(self, questionOnly=False): |
7387 def __executeMake(self, questionOnly=False): |
6622 """ |
7388 """ |
6623 Private method to execute a project specific make run. |
7389 Private method to execute a project specific make run. |
6624 |
7390 |
6625 @param questionOnly flag indicating to ask make for changes only |
7391 @param questionOnly flag indicating to ask make for changes only |
6626 @type bool |
7392 @type bool |
6627 """ |
7393 """ |
|
7394 if FileSystemUtilities.isRemoteFileName(self.ppath): |
|
7395 EricMessageBox.critical( |
|
7396 self.ui, |
|
7397 self.tr("Execute Make"), |
|
7398 self.tr("'Make' is not supported for remote projects. Aborting..."), |
|
7399 ) |
|
7400 return |
|
7401 |
6628 if ( |
7402 if ( |
6629 not self.__pdata["MAKEPARAMS"]["MakeEnabled"] |
7403 not self.__pdata["MAKEPARAMS"]["MakeEnabled"] |
6630 or self.__makeProcess is not None |
7404 or self.__makeProcess is not None |
6631 ): |
7405 ): |
6632 return |
7406 return |
6988 |
7766 |
6989 @return path of the embedded virtual environment (empty if not found) |
7767 @return path of the embedded virtual environment (empty if not found) |
6990 @rtype str |
7768 @rtype str |
6991 """ |
7769 """ |
6992 ppath = self.getProjectPath() |
7770 ppath = self.getProjectPath() |
6993 if ppath and os.path.exists(ppath): |
7771 if FileSystemUtilities.isRemoteFileName(ppath): |
6994 with os.scandir(self.getProjectPath()) as ppathDirEntriesIterator: |
7772 # check for some common names |
6995 for dirEntry in ppathDirEntriesIterator: |
|
6996 # potential venv directory; check for 'pyvenv.cfg' |
|
6997 if dirEntry.is_dir() and os.path.exists( |
|
6998 os.path.join(dirEntry.path, "pyvenv.cfg") |
|
6999 ): |
|
7000 return dirEntry.path |
|
7001 |
|
7002 # check for some common names in case 'pyvenv.cfg' is missing |
|
7003 for venvPathName in (".venv", "venv", ".env", "env"): |
7773 for venvPathName in (".venv", "venv", ".env", "env"): |
7004 venvPath = os.path.join(self.getProjectPath(), venvPathName) |
7774 venvPath = self.__remotefsInterface.join(ppath, venvPathName) |
7005 if os.path.isdir(venvPath): |
7775 if self.__remotefsInterface.isdir(venvPath): |
7006 return venvPath |
7776 return venvPath |
|
7777 else: |
|
7778 if ppath and os.path.exists(ppath): |
|
7779 with os.scandir(self.getProjectPath()) as ppathDirEntriesIterator: |
|
7780 for dirEntry in ppathDirEntriesIterator: |
|
7781 # potential venv directory; check for 'pyvenv.cfg' |
|
7782 if dirEntry.is_dir() and os.path.exists( |
|
7783 os.path.join(dirEntry.path, "pyvenv.cfg") |
|
7784 ): |
|
7785 return dirEntry.path |
|
7786 |
|
7787 # check for some common names in case 'pyvenv.cfg' is missing |
|
7788 for venvPathName in (".venv", "venv", ".env", "env"): |
|
7789 venvPath = os.path.join(ppath, venvPathName) |
|
7790 if os.path.isdir(venvPath): |
|
7791 return venvPath |
7007 |
7792 |
7008 return "" |
7793 return "" |
7009 |
7794 |
7010 def __setEmbeddedEnvironmentProjectConfig(self, value): |
7795 def __setEmbeddedEnvironmentProjectConfig(self, value): |
7011 """ |
7796 """ |
7207 with os.scandir(directory) as dirEntriesIterator: |
7992 with os.scandir(directory) as dirEntriesIterator: |
7208 for dirEntry in dirEntriesIterator: |
7993 for dirEntry in dirEntriesIterator: |
7209 if dirEntry.is_dir(): |
7994 if dirEntry.is_dir(): |
7210 self.__clearByteCodeCaches(dirEntry.path) |
7995 self.__clearByteCodeCaches(dirEntry.path) |
7211 |
7996 |
|
7997 ############################################################################# |
|
7998 ## Below are methods implementing the support for 'eric-ide server projects |
|
7999 ############################################################################# |
|
8000 |
|
8001 @pyqtSlot(bool) |
|
8002 def remoteConnectionChanged(self, connected): |
|
8003 """ |
|
8004 Public slot to handle a change of the 'eric-ide' server connection state. |
|
8005 |
|
8006 @param connected flag indicating the connection state |
|
8007 @type bool |
|
8008 """ |
|
8009 self.openRemoteAct.setEnabled(connected) |
|
8010 self.saveasRemoteAct.setEnabled( |
|
8011 connected |
|
8012 and self.opened |
|
8013 and FileSystemUtilities.isRemoteFileName(self.pfile) |
|
8014 ) |
|
8015 if not connected and FileSystemUtilities.isRemoteFileName(self.ppath): |
|
8016 self.closeProject(noSave=True) |
|
8017 |
|
8018 @pyqtSlot() |
|
8019 def __openRemoteProject(self): |
|
8020 """ |
|
8021 Private slot to open a project of an 'eric-ide' server. |
|
8022 """ |
|
8023 fn = EricServerFileDialog.getOpenFileName( |
|
8024 self.parent(), |
|
8025 self.tr("Open Remote Project"), |
|
8026 "", |
|
8027 self.tr("Project Files (*.epj)"), |
|
8028 ) |
|
8029 if fn: |
|
8030 self.openProject(fn=fn) |
|
8031 |
|
8032 @pyqtSlot() |
|
8033 def __saveRemoteProjectAs(self): |
|
8034 """ |
|
8035 Private slot to save the current remote project to different remote file. |
|
8036 """ |
|
8037 defaultFilter = self.tr("Project Files (*.epj)") |
|
8038 defaultPath = self.ppath if self.ppath else "" |
|
8039 fn, selectedFilter = EricServerFileDialog.getSaveFileNameAndFilter( |
|
8040 self.parent(), |
|
8041 self.tr("Save Remote Project"), |
|
8042 defaultPath, |
|
8043 self.tr("Project Files (*.epj)"), |
|
8044 defaultFilter, |
|
8045 ) |
|
8046 |
|
8047 if fn: |
|
8048 fname, ext = self.__remotefsInterface.splitext(fn) |
|
8049 if not ext: |
|
8050 ex = selectedFilter.split("(*")[1].split(")")[0] |
|
8051 if ex: |
|
8052 fn = f"{fname}{ex}" |
|
8053 if self.__remotefsInterface.exists(fn): |
|
8054 res = EricMessageBox.yesNo( |
|
8055 self.ui, |
|
8056 self.tr("Save Remote Project"), |
|
8057 self.tr( |
|
8058 """<p>The file <b>{0}</b> already exists.""" |
|
8059 """ Overwrite it?</p>""" |
|
8060 ).format(fn), |
|
8061 icon=EricMessageBox.Warning, |
|
8062 ) |
|
8063 if not res: |
|
8064 return |
|
8065 |
|
8066 ok = self.__writeProject(fn) |
|
8067 |
|
8068 if ok: |
|
8069 # create management directory if not present |
|
8070 self.createProjectManagementDir() |
|
8071 |
|
8072 # now save the tasks |
|
8073 self.writeTasks() |
|
8074 |
|
8075 self.sessActGrp.setEnabled(ok) |
|
8076 self.menuSessionAct.setEnabled(ok) |
|
8077 self.projectClosedHooks.emit() |
|
8078 self.projectClosed.emit(False) |
|
8079 self.projectOpenedHooks.emit() |
|
8080 self.projectOpened.emit() |
|
8081 |
7212 |
8082 |
7213 # |
8083 # |
7214 # eflag: noqa = M601 |
8084 # eflag: noqa = M601 |