src/eric7/Graphics/ApplicationDiagramBuilder.py

branch
server
changeset 10586
1b365d69ccef
parent 10439
21c28b0f9e41
child 10596
ea35c92a3c7c
equal deleted inserted replaced
10585:83e5a9a64543 10586:1b365d69ccef
13 13
14 from PyQt6.QtWidgets import QApplication, QInputDialog 14 from PyQt6.QtWidgets import QApplication, QInputDialog
15 15
16 from eric7 import Globals, Preferences 16 from eric7 import Globals, Preferences
17 from eric7.EricWidgets import EricMessageBox 17 from eric7.EricWidgets import EricMessageBox
18 from eric7.EricWidgets.EricApplication import ericApp
18 from eric7.EricWidgets.EricProgressDialog import EricProgressDialog 19 from eric7.EricWidgets.EricProgressDialog import EricProgressDialog
19 from eric7.SystemUtilities import FileSystemUtilities 20 from eric7.SystemUtilities import FileSystemUtilities
20 21
21 from .UMLDiagramBuilder import UMLDiagramBuilder 22 from .UMLDiagramBuilder import UMLDiagramBuilder
22 23
47 48
48 self.umlView.setDiagramName( 49 self.umlView.setDiagramName(
49 self.tr("Application Diagram {0}").format(self.project.getProjectName()) 50 self.tr("Application Diagram {0}").format(self.project.getProjectName())
50 ) 51 )
51 52
53 self.__remotefsInterface = (
54 ericApp().getObject("EricServer").getServiceInterface("FileSystem")
55 )
56
52 def __buildModulesDict(self): 57 def __buildModulesDict(self):
53 """ 58 """
54 Private method to build a dictionary of modules contained in the 59 Private method to build a dictionary of modules contained in the
55 application. 60 application.
56 61
62 extensions = Preferences.getPython("Python3Extensions") + [".rb"] 67 extensions = Preferences.getPython("Python3Extensions") + [".rb"]
63 moduleDict = {} 68 moduleDict = {}
64 mods = self.project.getProjectData(dataKey="SOURCES") 69 mods = self.project.getProjectData(dataKey="SOURCES")
65 modules = [] 70 modules = []
66 for module in mods: 71 for module in mods:
67 modules.append( 72 if FileSystemUtilities.isRemoteFileName(self.project.getProjectPath()):
68 FileSystemUtilities.normabsjoinpath(self.project.ppath, module) 73 modules.append(
69 ) 74 self.__remotefsInterface.join(self.project.getProjectPath(), module)
75 )
76 else:
77 modules.append(
78 FileSystemUtilities.normabsjoinpath(
79 self.project.getProjectPath(), module
80 )
81 )
70 tot = len(modules) 82 tot = len(modules)
71 progress = EricProgressDialog( 83 progress = EricProgressDialog(
72 self.tr("Parsing modules..."), 84 self.tr("Parsing modules..."),
73 None, 85 None,
74 0, 86 0,
109 121
110 @return application root path 122 @return application root path
111 @rtype str 123 @rtype str
112 """ 124 """
113 candidates = [] 125 candidates = []
114 path = self.project.getProjectPath() 126 ppath = self.project.getProjectPath()
115 init = os.path.join(path, "__init__.py") 127
116 if os.path.exists(init): 128 if FileSystemUtilities.isRemoteFileName(ppath):
117 # project is a package 129 init = self.__remotefsInterface.join(ppath, "__init__.py")
118 return path 130 if self.__remotefsInterface.exists(init):
131 # remote project is a package
132 return ppath
133 else:
134 # check, if any of the top directories is a package
135 for entry in self.__remotefsInterface.listdir(ppath)[2]:
136 if (
137 not entry["name"].startswith(".")
138 and entry["is_dir"]
139 and self.__remotefsInterface.exists(
140 self.__remotefsInterface.join(entry["path"], "__init__.py")
141 )
142 ):
143 candidates.append(entry["path"])
144
145 # check, if project uses the 'src' layout
146 srcPath = self.__remotefsInterface.join(ppath, "src")
147 if self.__remotefsInterface.exists(srcPath):
148 for entry in self.__remotefsInterface.listdir(srcPath)[2]:
149 if (
150 not entry["name"].startswith(".")
151 and entry["is_dir"]
152 and self.__remotefsInterface.exists(
153 self.__remotefsInterface.join(
154 entry["path"], "__init__.py"
155 )
156 )
157 ):
158 candidates.append(entry["path"])
159
119 else: 160 else:
120 # check, if any of the top directories is a package 161 init = os.path.join(ppath, "__init__.py")
121 with os.scandir(path) as dirEntriesIterator: 162 if os.path.exists(init):
122 for entry in [ 163 # project is a package
123 e for e in dirEntriesIterator if not e.name.startswith(".") 164 return ppath
124 ]: 165 else:
125 if entry.is_dir() and os.path.exists( 166 # check, if any of the top directories is a package
126 os.path.join(entry.path, "__init__.py") 167 with os.scandir(ppath) as dirEntriesIterator:
127 ):
128 candidates.append(entry.path)
129
130 # check, if project uses the 'src' layout
131 srcPath = os.path.join(path, "src")
132 if os.path.exists(srcPath):
133 with os.scandir(srcPath) as dirEntriesIterator:
134 for entry in [ 168 for entry in [
135 e for e in dirEntriesIterator if not e.name.startswith(".") 169 e for e in dirEntriesIterator if not e.name.startswith(".")
136 ]: 170 ]:
137 if entry.is_dir() and os.path.exists( 171 if entry.is_dir() and os.path.exists(
138 os.path.join(entry.path, "__init__.py") 172 os.path.join(entry.path, "__init__.py")
139 ): 173 ):
140 candidates.append(entry.path) 174 candidates.append(entry.path)
175
176 # check, if project uses the 'src' layout
177 srcPath = os.path.join(ppath, "src")
178 if os.path.exists(srcPath):
179 with os.scandir(srcPath) as dirEntriesIterator:
180 for entry in [
181 e for e in dirEntriesIterator if not e.name.startswith(".")
182 ]:
183 if entry.is_dir() and os.path.exists(
184 os.path.join(entry.path, "__init__.py")
185 ):
186 candidates.append(entry.path)
141 187
142 if len(candidates) == 1: 188 if len(candidates) == 1:
143 return candidates[0] 189 return candidates[0]
144 elif len(candidates) > 1: 190 elif len(candidates) > 1:
145 root, ok = QInputDialog.getItem( 191 root, ok = QInputDialog.getItem(
170 rpath = self.__findApplicationRoot() 216 rpath = self.__findApplicationRoot()
171 if rpath is None: 217 if rpath is None:
172 # no root path detected 218 # no root path detected
173 return 219 return
174 220
175 root = os.path.splitdrive(rpath)[1].replace(os.sep, ".")[1:] 221 if FileSystemUtilities.isRemoteFileName(rpath):
222 root = self.__remotefsInterface.splitdrive(rpath)[1][1:].replace(
223 self.__remotefsInterface.separator(), "."
224 )
225 else:
226 root = os.path.splitdrive(rpath)[1][1:].replace(os.sep, ".")
176 227
177 packages = {} 228 packages = {}
178 self.__shapes = {} 229 self.__shapes = {}
179 230
180 modules = self.__buildModulesDict() 231 modules = self.__buildModulesDict()

eric ide

mercurial