Răsfoiți Sursa

Fixes to allow individual patch files in the patchwork.

[SVN r37622]
Rene Rivera 19 ani în urmă
părinte
comite
4bc5fcaa54
2 a modificat fișierele cu 90 adăugiri și 29 ștergeri
  1. 87 29
      tools/buildbot/src/boost/patchwork.py
  2. 3 0
      tools/buildbot/src/buildbot.py

+ 87 - 29
tools/buildbot/src/boost/patchwork.py

@@ -15,6 +15,28 @@ import zipfile
 import re
 import re
 
 
 
 
+class patchwork_module:
+    
+    def __init__(self,zip_path):
+        self.zip_path = zip_path
+        self.zip = zipfile.ZipFile(zip_path,'r')
+    
+    def execute(self, args, scope = globals(), scripts = None):
+        if scripts:
+            script = None
+            files = self.zip.namelist()
+            reScripts = re.compile(scripts)
+            for zipPath in files:
+                if reScripts.match(zipPath):
+                    if not zipPath.endswith('/'):
+                        zipPath = os.path.dirname(zipPath)
+                    script = zipPath+os.path.basename(args[0])
+                    break
+            print "Running: %s" % (script)
+            exec self.zip.read(script) in scope
+        else:
+            exec self.zip.read(args[0]) in scope
+
 class patchwork_globals:
 class patchwork_globals:
     
     
     def __init__(self):
     def __init__(self):
@@ -29,18 +51,17 @@ class patchwork_globals:
 
 
 _g_ = patchwork_globals()
 _g_ = patchwork_globals()
 
 
-def _key_and_file_(file_match,file_entry):
-    m = re.match(file_match,file_entry)
-    if m:
-        return [ map(lambda y: int(y), m.groups()), file_entry ]
-    else:
-        return None
-
 #~ Define a module path, which can be a zip file, and its packages.
 #~ Define a module path, which can be a zip file, and its packages.
 def def_modules(dir_and_file,packages):
 def def_modules(dir_and_file,packages):
     #~ print "--- patchwork.def_modules(%s,{...})" % (dir_and_file)
     #~ print "--- patchwork.def_modules(%s,{...})" % (dir_and_file)
     
     
-    #~ pathDir = os.path.dirname
+    def _key_and_file_(file_match,file_entry):
+        m = re.match(file_match,file_entry)
+        if m:
+            return [ map(lambda y: int(y), m.groups()), file_entry ]
+        else:
+            return None
+
     dir = filter(
     dir = filter(
             None,
             None,
             map(
             map(
@@ -53,19 +74,26 @@ def def_modules(dir_and_file,packages):
     path = os.path.join(dir_and_file[0],dir[0][1])
     path = os.path.join(dir_and_file[0],dir[0][1])
     print "Using: %s" % (path)
     print "Using: %s" % (path)
     
     
+    module = None
     if path.endswith('.zip') and not _g_.importers.has_key(path):
     if path.endswith('.zip') and not _g_.importers.has_key(path):
-        zip = zipfile.ZipFile(path,'r')
+        module = patchwork_module(path)
+        zip = module.zip
         files = zip.namelist()
         files = zip.namelist()
         _g_.importers[path] = zipimport.zipimporter(path)
         _g_.importers[path] = zipimport.zipimporter(path)
         for package in packages.keys():
         for package in packages.keys():
-            rePackage = re.compile(packages[package])
-            for zipPath in files:
-                if rePackage.match(zipPath):
-                    if not zipPath.endswith('/'):
-                        zipPath = os.path.dirname(zipPath)
-                    #~ print "--- patchwork.def_modules found zip path %s" % (zipPath)
-                    _g_.packages[package] = { 'path' : zipPath, 'importer' : path }
-                    break
+            if os.path.exists(packages[package]):
+                #~ print "--| SRC FILE: %s" % (packages[package]);
+                _g_.packages[package] = { 'path' : packages[package], 'importer' : path }
+            else:
+                rePackage = re.compile(packages[package])
+                for zipPath in files:
+                    if rePackage.match(zipPath):
+                        if not zipPath.endswith('/'):
+                            zipPath = os.path.dirname(zipPath)
+                        #~ print "--- patchwork.def_modules found zip path %s" % (zipPath)
+                        #~ print "--| ZIP FILE: %s" % (zipPath);
+                        _g_.packages[package] = { 'path' : zipPath, 'importer' : path }
+                        break
         _g_.packages_to_search = _g_.packages.keys()
         _g_.packages_to_search = _g_.packages.keys()
         _g_.packages_to_search.sort()
         _g_.packages_to_search.sort()
         _g_.packages_to_search.reverse()
         _g_.packages_to_search.reverse()
@@ -73,6 +101,8 @@ def def_modules(dir_and_file,packages):
     else:
     else:
         raise ImportError
         raise ImportError
     
     
+    return module
+
 
 
 def _open_(filename, mode = 'r', bufsize = -1):
 def _open_(filename, mode = 'r', bufsize = -1):
     #~ print "--- patchwork.open(%s,%s,%d)\n" % (filename,mode,bufsize)
     #~ print "--- patchwork.open(%s,%s,%d)\n" % (filename,mode,bufsize)
@@ -88,19 +118,32 @@ def _file_(filename, mode = 'r', bufsize = -1):
 #~ Direct loader of modules, and packages, from other importers.
 #~ Direct loader of modules, and packages, from other importers.
 class patchwork_loader:
 class patchwork_loader:
     
     
-    def __init__(self,importer,path):
-        #~ print "--- patchwork.patchwork_loader.__init__"
+    def __init__(self,importer,module,path):
+        #~ print "--- patchwork_loader.__init__(self,importer,\n\t%s,\n\t%s)" % (module,path)
         
         
         self.importer = importer
         self.importer = importer
+        self.module = module
         self.path = path
         self.path = path
     
     
+    def find_module(self,fullname,path=None):
+        #~ print "--- patchwork_loader.find_module(self,\n\t%s,\n\t%s)" % (fullname,path)
+        return self.importer.find_module(fullname,path=path)
+    
     def load_module(self,fullname):
     def load_module(self,fullname):
-        #~ print "--- %s.load_module(self,%s)" % (self,fullname)
+        #~ print "--- patchwork_loader.load_module(self,\n\t%s)" % (fullname)
         
         
         source = ""
         source = ""
-        source += self.importer.get_data(self.path).replace("\r\n","\n").replace("\r","\n")
+        if os.path.exists(self.path):
+            #~ print "\tRC FILE: %s" % (self.path);
+            source += file(self.path,"rU").read()
+        else:
+            #~ print "\tZIP FILE: %s" % (self.path);
+            source += self.importer.get_data(self.path).replace("\r\n","\n").replace("\r","\n")
         source += "\n\n"
         source += "\n\n"
-        source += "from boost.patchwork import _open_ as open, _file_ as file\n"
+        #~ source += "print '[%s].[open] == %s ... %s' % (__name__,open, isinstance(open,type) )\n"
+        #~ source += "print '[%s].[file] == %s ... %s' % (__name__,file, isinstance(file,type) )\n"
+        source += "if isinstance(open,type):\n\tfrom boost.patchwork import _open_ as open\n"
+        source += "if isinstance(file,type):\n\tfrom boost.patchwork import _file_ as file\n"
         code = compiler.compile(source,self.path,'exec')
         code = compiler.compile(source,self.path,'exec')
         mod = sys.modules.setdefault(fullname, imp.new_module(fullname))
         mod = sys.modules.setdefault(fullname, imp.new_module(fullname))
         mod.__file__ = os.path.join(self.importer.archive,self.path)
         mod.__file__ = os.path.join(self.importer.archive,self.path)
@@ -116,7 +159,7 @@ class patchwork_loader:
 class patchwork_importer:
 class patchwork_importer:
     
     
     def __init__(self,archivepath):
     def __init__(self,archivepath):
-        #~ print "--- %s.__init__(self,%s)" % (self,archivepath)
+        #~ print "--- patchwork_importer.__init__(self,%s)" % (archivepath)
         
         
         found = None
         found = None
         for importer in _g_.importers.keys():
         for importer in _g_.importers.keys():
@@ -128,7 +171,7 @@ class patchwork_importer:
             raise ImportError
             raise ImportError
     
     
     def find_module(self,fullname,path=None):
     def find_module(self,fullname,path=None):
-        #~ print "--- %s.find_module(self,%s,%s)" % (self,fullname,path)
+        print "--- patchwork_importer.find_module(self,\n\t%s,\n\t%s)" % (fullname,path)
         
         
         loader = None
         loader = None
         for package in _g_.packages_to_search:
         for package in _g_.packages_to_search:
@@ -139,19 +182,34 @@ class patchwork_importer:
                 fullname_base = fullname.split('.')[len(package_dirname):]
                 fullname_base = fullname.split('.')[len(package_dirname):]
                 
                 
                 importer = _g_.importers[_g_.packages[package]['importer']]
                 importer = _g_.importers[_g_.packages[package]['importer']]
-                path_base = os.path.join(_g_.packages[package]['path'],*fullname_base)
+                if os.path.exists(_g_.packages[package]['path']):
+                    path_base = _g_.packages[package]['path']
+                else:
+                    path_base = os.path.join(_g_.packages[package]['path'],*fullname_base)
                 
                 
-                if importer._files.has_key(os.path.join(path_base,"__init__")+".py"):
+                if os.path.exists(os.path.join(path_base,"__init__")+".py"):
+                    #~ Source package.
+                    loader = patchwork_loader(importer,fullname,
+                        os.path.join(path_base,"__init__")+".py")
+                elif os.path.exists(path_base):
+                    #~ Source module.
+                    loader = patchwork_loader(importer,fullname,
+                        path_base)
+                elif os.path.exists(path_base+".py"):
+                    #~ Source module.
+                    loader = patchwork_loader(importer,fullname,
+                        path_base+".py")
+                elif importer._files.has_key(os.path.join(path_base,"__init__")+".py"):
                     #~ Source package.
                     #~ Source package.
-                    loader = patchwork_loader(importer,
+                    loader = patchwork_loader(importer,fullname,
                         os.path.join(path_base,"__init__")+".py")
                         os.path.join(path_base,"__init__")+".py")
                 elif importer._files.has_key(path_base+".py"):
                 elif importer._files.has_key(path_base+".py"):
                     #~ Source module.
                     #~ Source module.
-                    loader = patchwork_loader(importer,
+                    loader = patchwork_loader(importer,fullname,
                         path_base+".py")
                         path_base+".py")
                 
                 
                 if loader:
                 if loader:
-                    #~ print "--- %s.find_module(self,%s,%s)" % (self,fullname,path)
+                    #~ print "--- patchwork_importer.find_module(self,%s,%s)" % (fullname,path)
                     #~ print "---      package = %s" % (package)
                     #~ print "---      package = %s" % (package)
                     #~ print "---      %s.path = %s" % (loader,loader.path)
                     #~ print "---      %s.path = %s" % (loader,loader.path)
                     break;
                     break;

+ 3 - 0
tools/buildbot/src/buildbot.py

@@ -14,6 +14,9 @@ from boost.patchwork import def_modules
 #~ The directory this file is in.
 #~ The directory this file is in.
 root = os.path.abspath( os.path.dirname(__file__ ) )
 root = os.path.abspath( os.path.dirname(__file__ ) )
 
 
+#~ Bootstrap Boost package.
+#~ sys.path.insert(0,os.path.join(root,'_packages','boost-0.0.1.zip'))
+
 #~ The zip files we import from...
 #~ The zip files we import from...
 
 
 #~ BuildBot has a simple single package tree.
 #~ BuildBot has a simple single package tree.

粤ICP备19079148号