| 170 | | nodes = [] |
|---|
| 171 | | routes = [] |
|---|
| 172 | | |
|---|
| 173 | | for filepath, info in files.items(): |
|---|
| 174 | | nodes.append(filepath) |
|---|
| 175 | | for neededFilePath in info.requires: |
|---|
| 176 | | routes.append((neededFilePath, filepath)) |
|---|
| 177 | | |
|---|
| 178 | | for dependencyLevel in toposort(nodes, routes): |
|---|
| 179 | | for filepath in dependencyLevel: |
|---|
| 180 | | order.append(filepath) |
|---|
| | 168 | complete = False |
|---|
| | 169 | resolution_pass = 1 |
|---|
| | 170 | |
|---|
| | 171 | while not complete: |
|---|
| | 172 | order = [] # List of filepaths to output, in a dependency satisfying order |
|---|
| | 173 | nodes = [] |
|---|
| | 174 | routes = [] |
|---|
| | 175 | ## Resolve the dependencies |
|---|
| | 176 | print "Resolution pass %s... " % resolution_pass |
|---|
| | 177 | resolution_pass += 1 |
|---|
| | 178 | |
|---|
| | 179 | for filepath, info in files.items(): |
|---|
| | 180 | nodes.append(filepath) |
|---|
| | 181 | for neededFilePath in info.requires: |
|---|
| | 182 | routes.append((neededFilePath, filepath)) |
|---|
| | 183 | |
|---|
| | 184 | for dependencyLevel in toposort(nodes, routes): |
|---|
| | 185 | for filepath in dependencyLevel: |
|---|
| | 186 | order.append(filepath) |
|---|
| | 187 | if not files.has_key(filepath): |
|---|
| | 188 | print "Importing: %s" % filepath |
|---|
| | 189 | fullpath = os.path.join(sourceDirectory, filepath) |
|---|
| | 190 | content = open(fullpath, "U").read() # TODO: Ensure end of line @ EOF? |
|---|
| | 191 | files[filepath] = SourceFile(filepath, content) # TODO: Chop path? |
|---|
| | 192 | |
|---|
| | 193 | |
|---|
| | 194 | |
|---|
| | 195 | # Double check all dependencies have been met |
|---|
| | 196 | complete = True |
|---|
| | 197 | try: |
|---|
| | 198 | for fp in order: |
|---|
| | 199 | if max([order.index(rfp) for rfp in files[fp].requires] + |
|---|
| | 200 | [order.index(fp)]) != order.index(fp): |
|---|
| | 201 | complete = False |
|---|
| | 202 | except: |
|---|
| | 203 | complete = False |
|---|
| | 204 | |
|---|
| | 205 | print |
|---|