[OpenLayers-Commits] r10980 - sandbox/tschaub/uncircular/tools

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Sat Jan 1 15:29:26 EST 2011


Author: tschaub
Date: 2011-01-01 12:29:26 -0800 (Sat, 01 Jan 2011)
New Revision: 10980

Modified:
   sandbox/tschaub/uncircular/tools/mergejs.py
Log:
Using the simpler toposort.

Modified: sandbox/tschaub/uncircular/tools/mergejs.py
===================================================================
--- sandbox/tschaub/uncircular/tools/mergejs.py	2011-01-01 20:28:19 UTC (rev 10979)
+++ sandbox/tschaub/uncircular/tools/mergejs.py	2011-01-01 20:29:26 UTC (rev 10980)
@@ -44,6 +44,10 @@
 SUFFIX_JAVASCRIPT = ".js"
 
 RE_REQUIRE = "@requires:? (.*)\n" # TODO: Ensure in comment?
+
+class MissingImport(Exception):
+    """Exception raised when a listed import is not found in the lib."""
+
 class SourceFile:
     """
     Represents a Javascript source code file.
@@ -161,8 +165,6 @@
 
     files = {}
 
-    order = [] # List of filepaths to output, in a dependency satisfying order 
-
     ## Import file source code
     ## TODO: Do import when we walk the directories above?
     for filepath in allFiles:
@@ -179,41 +181,31 @@
     resolution_pass = 1
 
     while not complete:
-        order = [] # List of filepaths to output, in a dependency satisfying order 
-        nodes = []
-        routes = []
+        complete = True
+
         ## Resolve the dependencies
         print "Resolution pass %s... " % resolution_pass
         resolution_pass += 1 
 
         for filepath, info in files.items():
-            nodes.append(filepath)
-            for neededFilePath in info.requires:
-                routes.append((neededFilePath, filepath))
-
-        for dependencyLevel in toposort(nodes, routes):
-            for filepath in dependencyLevel:
-                order.append(filepath)
-                if not files.has_key(filepath):
-                    print "Importing: %s" % filepath
-                    fullpath = os.path.join(sourceDirectory, filepath).strip()
-                    content = open(fullpath, "U").read() # TODO: Ensure end of line @ EOF?
-                    files[filepath] = SourceFile(filepath, content) # TODO: Chop path?
-        
-
-
-        # Double check all dependencies have been met
-        complete = True
-        try:
-            for fp in order:
-                if max([order.index(rfp) for rfp in files[fp].requires] +
-                       [order.index(fp)]) != order.index(fp):
+            for path in info.requires:
+                if not files.has_key(path):
                     complete = False
-        except:
-            complete = False
+                    fullpath = os.path.join(sourceDirectory, path).strip()
+                    if os.path.exists(fullpath):
+                        print "Importing: %s" % path
+                        content = open(fullpath, "U").read() # TODO: Ensure end of line @ EOF?
+                        files[path] = SourceFile(path, content) # TODO: Chop path?
+                    else:
+                        raise MissingImport("File '%s' not found (required by '%s')." % (path, filepath))
         
-        print    
+    # create dictionary of dependencies
+    dependencies = {}
+    for filepath, info in files.items():
+        dependencies[filepath] = info.requires
 
+    print "Sorting..."
+    order = toposort(dependencies) #[x for x in toposort(dependencies)]
 
     ## Move forced first and last files to the required position
     if cfg:



More information about the Commits mailing list