14 from itertools import zip_longest |
14 from itertools import zip_longest |
15 |
15 |
16 from PyQt6.QtWidgets import QApplication, QGraphicsTextItem |
16 from PyQt6.QtWidgets import QApplication, QGraphicsTextItem |
17 |
17 |
18 from eric7 import Globals, Preferences |
18 from eric7 import Globals, Preferences |
|
19 from eric7.EricWidgets.EricApplication import ericApp |
19 from eric7.EricWidgets.EricProgressDialog import EricProgressDialog |
20 from eric7.EricWidgets.EricProgressDialog import EricProgressDialog |
20 from eric7.SystemUtilities import FileSystemUtilities |
21 from eric7.SystemUtilities import FileSystemUtilities |
21 |
22 |
22 from .UMLDiagramBuilder import UMLDiagramBuilder |
23 from .UMLDiagramBuilder import UMLDiagramBuilder |
23 |
24 |
43 @type bool |
44 @type bool |
44 """ |
45 """ |
45 super().__init__(dialog, view, project) |
46 super().__init__(dialog, view, project) |
46 self.setObjectName("PackageDiagram") |
47 self.setObjectName("PackageDiagram") |
47 |
48 |
48 self.package = os.path.abspath(package) |
49 if FileSystemUtilities.isRemoteFileName(package): |
|
50 self.package = package |
|
51 else: |
|
52 self.package = os.path.abspath(package) |
49 self.noAttrs = noAttrs |
53 self.noAttrs = noAttrs |
50 |
54 |
51 self.__relPackage = ( |
55 self.__relPackage = ( |
52 self.project.getRelativePath(self.package) |
56 self.project.getRelativePath(self.package) |
53 if self.project.isProjectCategory(self.package, "SOURCES") |
57 if self.project.isProjectCategory(self.package, "SOURCES") |
54 else "" |
58 else "" |
|
59 ) |
|
60 |
|
61 self.__remotefsInterface = ( |
|
62 ericApp().getObject("EricServer").getServiceInterface("FileSystem") |
55 ) |
63 ) |
56 |
64 |
57 def initialize(self): |
65 def initialize(self): |
58 """ |
66 """ |
59 Public method to initialize the object. |
67 Public method to initialize the object. |
95 extensions = Preferences.getPython("Python3Extensions") + [".rb"] |
103 extensions = Preferences.getPython("Python3Extensions") + [".rb"] |
96 |
104 |
97 moduleDict = {} |
105 moduleDict = {} |
98 modules = [] |
106 modules = [] |
99 for ext in supportedExt: |
107 for ext in supportedExt: |
100 modules.extend( |
108 if FileSystemUtilities.isRemoteFileName(self.package): |
101 glob.glob(FileSystemUtilities.normjoinpath(self.package, ext)) |
109 modules.extend( |
102 ) |
110 [ |
|
111 FileSystemUtilities.remoteFileName(f) |
|
112 for f in self.__remotefsInterface.glob( |
|
113 os.path.join(self.package, ext) |
|
114 ) |
|
115 ] |
|
116 ) |
|
117 else: |
|
118 modules.extend( |
|
119 glob.glob(FileSystemUtilities.normjoinpath(self.package, ext)) |
|
120 ) |
103 tot = len(modules) |
121 tot = len(modules) |
104 progress = EricProgressDialog( |
122 progress = EricProgressDialog( |
105 self.tr("Parsing modules..."), |
123 self.tr("Parsing modules..."), |
106 None, |
124 None, |
107 0, |
125 0, |
152 extensions = Preferences.getPython("Python3Extensions") + [".rb"] |
170 extensions = Preferences.getPython("Python3Extensions") + [".rb"] |
153 |
171 |
154 subpackagesDict = {} |
172 subpackagesDict = {} |
155 subpackagesList = [] |
173 subpackagesList = [] |
156 |
174 |
157 with os.scandir(self.package) as dirEntriesIterator: |
175 if FileSystemUtilities.isRemoteFileName(self.package): |
158 for subpackage in dirEntriesIterator: |
176 for subpackage in self.__remotefsInterface.listdir(self.package)[2]: |
159 if ( |
177 if ( |
160 subpackage.is_dir() |
178 subpackage["is_dir"] |
161 and subpackage.name != "__pycache__" |
179 and subpackage["name"] != "__pycache__" |
162 and len(glob.glob(os.path.join(subpackage.path, "__init__.*"))) != 0 |
180 and len( |
|
181 self.__remotefsInterface.glob( |
|
182 os.path.join(subpackage["path"], "__init__.*") |
|
183 ) |
|
184 ) != 0 |
163 ): |
185 ): |
164 subpackagesList.append(subpackage.path) |
186 subpackagesList.append( |
|
187 FileSystemUtilities.remoteFileName(subpackage["path"]) |
|
188 ) |
|
189 else: |
|
190 with os.scandir(self.package) as dirEntriesIterator: |
|
191 for subpackage in dirEntriesIterator: |
|
192 if ( |
|
193 subpackage.is_dir() |
|
194 and subpackage.name != "__pycache__" |
|
195 and len(glob.glob(os.path.join(subpackage.path, "__init__.*"))) != 0 |
|
196 ): |
|
197 subpackagesList.append(subpackage.path) |
165 |
198 |
166 tot = 0 |
199 tot = 0 |
167 for ext in supportedExt: |
200 for ext in supportedExt: |
168 for subpackage in subpackagesList: |
201 for subpackage in subpackagesList: |
169 tot += len(glob.glob(FileSystemUtilities.normjoinpath(subpackage, ext))) |
202 tot += len(glob.glob(FileSystemUtilities.normjoinpath(subpackage, ext))) |
185 for subpackage in subpackagesList: |
218 for subpackage in subpackagesList: |
186 packageName = os.path.basename(subpackage) |
219 packageName = os.path.basename(subpackage) |
187 subpackagesDict[packageName] = [] |
220 subpackagesDict[packageName] = [] |
188 modules = [] |
221 modules = [] |
189 for ext in supportedExt: |
222 for ext in supportedExt: |
190 modules.extend( |
223 if FileSystemUtilities.isRemoteFileName(subpackage): |
191 glob.glob(FileSystemUtilities.normjoinpath(subpackage, ext)) |
224 modules.extend( |
192 ) |
225 [ |
|
226 FileSystemUtilities.remoteFileName(f) |
|
227 for f in self.__remotefsInterface.glob( |
|
228 os.path.join(subpackage, ext) |
|
229 ) |
|
230 ] |
|
231 ) |
|
232 else: |
|
233 modules.extend( |
|
234 glob.glob(FileSystemUtilities.normjoinpath(subpackage, ext)) |
|
235 ) |
193 for prog, module in enumerate(modules, start=start): |
236 for prog, module in enumerate(modules, start=start): |
194 progress.setValue(prog) |
237 progress.setValue(prog) |
195 if time.monotonic() - now > 0.01: |
238 if time.monotonic() - now > 0.01: |
196 QApplication.processEvents() |
239 QApplication.processEvents() |
197 now = time.monotonic() |
240 now = time.monotonic() |
223 |
266 |
224 The algorithm is borrowed from Boa Constructor. |
267 The algorithm is borrowed from Boa Constructor. |
225 """ |
268 """ |
226 self.allClasses = {} |
269 self.allClasses = {} |
227 |
270 |
228 initlist = glob.glob(os.path.join(self.package, "__init__.*")) |
271 globPattern = os.path.join(self.package, "__init__.*") |
|
272 if FileSystemUtilities.isRemoteFileName(self.package): |
|
273 initlist = self.__remotefsInterface.glob(globPattern) |
|
274 else: |
|
275 initlist = glob.glob(globPattern) |
229 if len(initlist) == 0: |
276 if len(initlist) == 0: |
230 ct = QGraphicsTextItem(None) |
277 ct = QGraphicsTextItem(None) |
231 self.scene.addItem(ct) |
278 self.scene.addItem(ct) |
232 ct.setHtml( |
279 ct.setHtml( |
233 self.tr("The directory <b>'{0}'</b> is not a package.").format( |
280 self.tr("The directory <b>'{0}'</b> is not a package.").format( |