103 y = 10 |
103 y = 10 |
104 maxHeight = 0 |
104 maxHeight = 0 |
105 sceneRect = self.umlView.sceneRect() |
105 sceneRect = self.umlView.sceneRect() |
106 |
106 |
107 modules = self.__buildModulesDict() |
107 modules = self.__buildModulesDict() |
108 sortedkeys = sorted(modules.keys()) |
|
109 |
108 |
110 # step 1: build a dictionary of packages |
109 # step 1: build a dictionary of packages |
111 for module in sortedkeys: |
110 for module in sorted(modules.keys()): |
112 li = module.split('.') |
111 packageName, moduleName = module.rsplit(".", 1) |
113 package = '.'.join(li[:-1]) |
112 if packageName in packages: |
114 if package in packages: |
113 packages[packageName][0].append(moduleName) |
115 packages[package][0].append(li[-1]) |
|
116 else: |
114 else: |
117 packages[package] = ([li[-1]], []) |
115 packages[packageName] = ([moduleName], []) |
118 |
116 |
119 # step 2: assign modules to dictionaries and update import relationship |
117 # step 2: assign modules to dictionaries and update import relationship |
120 for module in sortedkeys: |
118 for module in sorted(modules.keys()): |
121 li = module.split('.') |
119 package = module.rsplit(".", 1)[0] |
122 package = '.'.join(li[:-1]) |
|
123 impLst = [] |
120 impLst = [] |
124 for i in modules[module].imports: |
121 for moduleImport in modules[module].imports: |
125 if i in modules: |
122 if moduleImport in modules: |
126 impLst.append(i) |
123 impLst.append(moduleImport) |
127 else: |
124 else: |
128 if i.find('.') == -1: |
125 if moduleImport.find('.') == -1: |
129 n = "{0}.{1}".format(modules[module].package, i) |
126 n = "{0}.{1}".format(modules[module].package, |
|
127 moduleImport) |
130 if n in modules: |
128 if n in modules: |
131 impLst.append(n) |
129 impLst.append(n) |
132 else: |
130 else: |
133 n = "{0}.{1}".format(project, i) |
131 n = "{0}.{1}".format(project, moduleImport) |
134 if n in modules: |
132 if n in modules: |
135 impLst.append(n) |
133 impLst.append(n) |
136 elif n in packages: |
134 elif n in packages: |
137 n = "{0}.<<Dummy>>".format(n) |
135 n = "{0}.<<Dummy>>".format(n) |
138 impLst.append(n) |
136 impLst.append(n) |
139 else: |
137 else: |
140 n = "{0}.{1}".format(project, i) |
138 n = "{0}.{1}".format(project, moduleImport) |
141 if n in modules: |
139 if n in modules: |
142 impLst.append(n) |
140 impLst.append(n) |
143 for i in list(modules[module].from_imports.keys()): |
141 for moduleImport in list(modules[module].from_imports.keys()): |
144 if i.startswith('.'): |
142 if moduleImport.startswith('.'): |
145 dots = len(i) - len(i.lstrip('.')) |
143 dots = len(moduleImport) - len(moduleImport.lstrip('.')) |
146 if dots == 1: |
144 if dots == 1: |
147 i = i[1:] |
145 moduleImport = moduleImport[1:] |
148 elif dots > 1: |
146 elif dots > 1: |
149 packagePath = os.path.dirname(modules[module].file) |
147 packagePath = os.path.dirname(modules[module].file) |
150 hasInit = True |
148 hasInit = True |
151 ppath = packagePath |
149 ppath = packagePath |
152 while hasInit: |
150 while hasInit: |
157 packagePath.replace(ppath, '') |
155 packagePath.replace(ppath, '') |
158 .replace(os.sep, '.')[1:] |
156 .replace(os.sep, '.')[1:] |
159 ) |
157 ) |
160 packageList = shortPackage.split('.')[1:] |
158 packageList = shortPackage.split('.')[1:] |
161 packageListLen = len(packageList) |
159 packageListLen = len(packageList) |
162 i = '.'.join( |
160 moduleImport = '.'.join( |
163 packageList[:packageListLen - dots + 1] + |
161 packageList[:packageListLen - dots + 1] + |
164 [i[dots:]]) |
162 [moduleImport[dots:]]) |
165 |
163 |
166 if i in modules: |
164 if moduleImport in modules: |
167 impLst.append(i) |
165 impLst.append(moduleImport) |
168 else: |
166 else: |
169 if i.find('.') == -1: |
167 if moduleImport.find('.') == -1: |
170 n = "{0}.{1}".format(modules[module].package, i) |
168 n = "{0}.{1}".format(modules[module].package, |
|
169 moduleImport) |
171 if n in modules: |
170 if n in modules: |
172 impLst.append(n) |
171 impLst.append(n) |
173 else: |
172 else: |
174 n = "{0}.{1}".format(project, i) |
173 n = "{0}.{1}".format(project, moduleImport) |
175 if n in modules: |
174 if n in modules: |
176 impLst.append(n) |
175 impLst.append(n) |
177 elif n in packages: |
176 elif n in packages: |
178 n = "{0}.<<Dummy>>".format(n) |
177 n = "{0}.<<Dummy>>".format(n) |
179 impLst.append(n) |
178 impLst.append(n) |
180 else: |
179 else: |
181 n = "{0}.{1}".format(project, i) |
180 n = "{0}.{1}".format(project, moduleImport) |
182 if n in modules: |
181 if n in modules: |
183 impLst.append(n) |
182 impLst.append(n) |
184 for imp in impLst: |
183 for moduleImport in impLst: |
185 impPackage = '.'.join(imp.split('.')[:-1]) |
184 impPackage = moduleImport.rsplit(".", 1)[0] |
186 if ( |
185 if ( |
187 impPackage not in packages[package][1] and |
186 impPackage not in packages[package][1] and |
188 impPackage != package |
187 impPackage != package |
189 ): |
188 ): |
190 packages[package][1].append(impPackage) |
189 packages[package][1].append(impPackage) |
191 |
190 |
192 sortedkeys = sorted(packages.keys()) |
191 for package in sorted(packages.keys()): |
193 for package in sortedkeys: |
|
194 if package: |
192 if package: |
195 relPackage = package.replace(project, '') |
193 relPackage = package.replace(project, '') |
196 if relPackage and relPackage[0] == '.': |
194 if relPackage and relPackage[0] == '.': |
197 relPackage = relPackage[1:] |
195 relPackage = relPackage[1:] |
198 else: |
196 else: |
249 """ |
247 """ |
250 Private method to generate the associations between the package shapes. |
248 Private method to generate the associations between the package shapes. |
251 |
249 |
252 @param shapes list of shapes |
250 @param shapes list of shapes |
253 """ |
251 """ |
254 from .AssociationItem import AssociationItem, Imports |
252 from .AssociationItem import AssociationItem, AssociationType |
255 for package in shapes: |
253 for package in shapes: |
256 for rel in shapes[package][1]: |
254 for rel in shapes[package][1]: |
257 assoc = AssociationItem( |
255 assoc = AssociationItem( |
258 shapes[package][0], shapes[rel][0], |
256 shapes[package][0], shapes[rel][0], |
259 Imports, |
257 AssociationType.IMPORTS, |
260 colors=self.umlView.getDrawingColors()) |
258 colors=self.umlView.getDrawingColors()) |
261 self.scene.addItem(assoc) |
259 self.scene.addItem(assoc) |
262 |
260 |
263 def getPersistenceData(self): |
261 def getPersistenceData(self): |
264 """ |
262 """ |