23 Class implementing a builder for imports diagrams of a package. |
23 Class implementing a builder for imports diagrams of a package. |
24 |
24 |
25 Note: Only package internal imports are shown in order to maintain |
25 Note: Only package internal imports are shown in order to maintain |
26 some readability. |
26 some readability. |
27 """ |
27 """ |
28 def __init__(self, dialog, view, project, package, showExternalImports=False): |
28 def __init__(self, dialog, view, project, package, |
|
29 showExternalImports=False): |
29 """ |
30 """ |
30 Constructor |
31 Constructor |
31 |
32 |
32 @param dialog reference to the UML dialog (UMLDialog) |
33 @param dialog reference to the UML dialog (UMLDialog) |
33 @param view reference to the view object (UMLGraphicsView) |
34 @param view reference to the view object (UMLGraphicsView) |
34 @param project reference to the project object (Project) |
35 @param project reference to the project object (Project) |
35 @param package name of a python package to show the import |
36 @param package name of a python package to show the import |
36 relationships (string) |
37 relationships (string) |
37 @keyparam showExternalImports flag indicating to show exports from outside |
38 @keyparam showExternalImports flag indicating to show exports from |
38 the package (boolean) |
39 outside the package (boolean) |
39 """ |
40 """ |
40 super().__init__(dialog, view, project) |
41 super().__init__(dialog, view, project) |
41 self.setObjectName("ImportsDiagram") |
42 self.setObjectName("ImportsDiagram") |
42 |
43 |
43 self.showExternalImports = showExternalImports |
44 self.showExternalImports = showExternalImports |
45 |
46 |
46 def initialize(self): |
47 def initialize(self): |
47 """ |
48 """ |
48 Public method to initialize the object. |
49 Public method to initialize the object. |
49 """ |
50 """ |
50 self.package = os.path.splitdrive(self.packagePath)[1].replace(os.sep, '.')[1:] |
51 self.package = os.path.splitdrive(self.packagePath)[1].replace( |
|
52 os.sep, '.')[1:] |
51 hasInit = True |
53 hasInit = True |
52 ppath = self.packagePath |
54 ppath = self.packagePath |
53 while hasInit: |
55 while hasInit: |
54 ppath = os.path.dirname(ppath) |
56 ppath = os.path.dirname(ppath) |
55 hasInit = len(glob.glob(os.path.join(ppath, '__init__.*'))) > 0 |
57 hasInit = len(glob.glob(os.path.join(ppath, '__init__.*'))) > 0 |
56 self.shortPackage = self.packagePath.replace(ppath, '').replace(os.sep, '.')[1:] |
58 self.shortPackage = self.packagePath.replace(ppath, '').replace( |
|
59 os.sep, '.')[1:] |
57 |
60 |
58 pname = self.project.getProjectName() |
61 pname = self.project.getProjectName() |
59 if pname: |
62 if pname: |
60 name = self.trUtf8("Imports Diagramm {0}: {1}").format( |
63 name = self.trUtf8("Imports Diagramm {0}: {1}").format( |
61 pname, self.project.getRelativePath(self.packagePath)) |
64 pname, self.project.getRelativePath(self.packagePath)) |
62 else: |
65 else: |
63 name = self.trUtf8("Imports Diagramm: {0}").format(self.packagePath) |
66 name = self.trUtf8("Imports Diagramm: {0}").format( |
|
67 self.packagePath) |
64 self.umlView.setDiagramName(name) |
68 self.umlView.setDiagramName(name) |
65 |
69 |
66 def __buildModulesDict(self): |
70 def __buildModulesDict(self): |
67 """ |
71 """ |
68 Private method to build a dictionary of modules contained in the package. |
72 Private method to build a dictionary of modules contained in the |
|
73 package. |
69 |
74 |
70 @return dictionary of modules contained in the package. |
75 @return dictionary of modules contained in the package. |
71 """ |
76 """ |
72 import Utilities.ModuleParser |
77 import Utilities.ModuleParser |
73 extensions = Preferences.getPython("PythonExtensions") + \ |
78 extensions = Preferences.getPython("PythonExtensions") + \ |
74 Preferences.getPython("Python3Extensions") |
79 Preferences.getPython("Python3Extensions") |
75 moduleDict = {} |
80 moduleDict = {} |
76 modules = [] |
81 modules = [] |
77 for ext in Preferences.getPython("PythonExtensions") + \ |
82 for ext in Preferences.getPython("PythonExtensions") + \ |
78 Preferences.getPython("Python3Extensions"): |
83 Preferences.getPython("Python3Extensions"): |
79 modules.extend( |
84 modules.extend(glob.glob(Utilities.normjoinpath( |
80 glob.glob(Utilities.normjoinpath(self.packagePath, '*{0}'.format(ext)))) |
85 self.packagePath, '*{0}'.format(ext)))) |
81 |
86 |
82 tot = len(modules) |
87 tot = len(modules) |
83 try: |
88 try: |
84 prog = 0 |
89 prog = 0 |
85 progress = QProgressDialog(self.trUtf8("Parsing modules..."), |
90 progress = QProgressDialog(self.trUtf8("Parsing modules..."), |
89 for module in modules: |
94 for module in modules: |
90 progress.setValue(prog) |
95 progress.setValue(prog) |
91 QApplication.processEvents() |
96 QApplication.processEvents() |
92 prog = prog + 1 |
97 prog = prog + 1 |
93 try: |
98 try: |
94 mod = Utilities.ModuleParser.readModule(module, extensions=extensions, |
99 mod = Utilities.ModuleParser.readModule( |
95 caching=False) |
100 module, extensions=extensions, caching=False) |
96 except ImportError: |
101 except ImportError: |
97 continue |
102 continue |
98 else: |
103 else: |
99 name = mod.name |
104 name = mod.name |
100 if name.startswith(self.package): |
105 if name.startswith(self.package): |
111 """ |
116 """ |
112 initlist = glob.glob(os.path.join(self.packagePath, '__init__.*')) |
117 initlist = glob.glob(os.path.join(self.packagePath, '__init__.*')) |
113 if len(initlist) == 0: |
118 if len(initlist) == 0: |
114 ct = QGraphicsTextItem(None) |
119 ct = QGraphicsTextItem(None) |
115 ct.setHtml( |
120 ct.setHtml( |
116 self.trUtf8("The directory <b>'{0}'</b> is not a Python package.")\ |
121 self.trUtf8( |
|
122 "The directory <b>'{0}'</b> is not a Python package.") |
117 .format(self.package)) |
123 .format(self.package)) |
118 self.scene.addItem(ct) |
124 self.scene.addItem(ct) |
119 return |
125 return |
120 |
126 |
121 shapes = {} |
127 shapes = {} |
265 not parts[0].startswith("package=") or \ |
272 not parts[0].startswith("package=") or \ |
266 not parts[1].startswith("show_external="): |
273 not parts[1].startswith("show_external="): |
267 return False |
274 return False |
268 |
275 |
269 self.packagePath = parts[0].split("=", 1)[1].strip() |
276 self.packagePath = parts[0].split("=", 1)[1].strip() |
270 self.showExternalImports = Utilities.toBool(parts[1].split("=", 1)[1].strip()) |
277 self.showExternalImports = Utilities.toBool( |
|
278 parts[1].split("=", 1)[1].strip()) |
271 |
279 |
272 self.initialize() |
280 self.initialize() |
273 |
281 |
274 return True |
282 return True |