[kernel] r18112 - dists/trunk/linux-tools/debian/bin

Bastian Blank waldi at alioth.debian.org
Thu Sep 22 12:59:50 UTC 2011


Author: waldi
Date: Thu Sep 22 12:59:49 2011
New Revision: 18112

Log:
debian/bin/genorig.py: Support globs to copy files.

Modified:
   dists/trunk/linux-tools/debian/bin/genorig.py

Modified: dists/trunk/linux-tools/debian/bin/genorig.py
==============================================================================
--- dists/trunk/linux-tools/debian/bin/genorig.py	Thu Sep 22 03:29:51 2011	(r18111)
+++ dists/trunk/linux-tools/debian/bin/genorig.py	Thu Sep 22 12:59:49 2011	(r18112)
@@ -11,6 +11,41 @@
 
 from debian_linux.debian import Changelog, VersionLinux
 
+
+class FileGlob(object):
+    def __init__(self, root):
+        self.root = root or os.curdir
+
+    def __call__(self, pathname):
+        dirname, basename = os.path.split(pathname)
+        if dirname:
+            dirs = self(dirname)
+        else:
+            dirs = ('', )
+        for d in dirs:
+            if basename:
+                for name in self.glob(d, basename):
+                    yield os.path.join(d, name)
+            elif self.isdir(d):
+                yield os.path.join(d, '')
+
+    def glob(self, dirname, pattern):
+        import fnmatch
+        try:
+            names = self.listdir(dirname)
+        except os.error:
+            return ()
+        if pattern[0] != '.':
+            names = filter(lambda x: x[0] != '.', names)
+        return fnmatch.filter(names, pattern)
+
+    def isdir(self, dirname):
+        return os.path.isdir(os.path.join(self.root, dirname))
+
+    def listdir(self, dirname):
+        return os.listdir(os.path.join(self.root, dirname))
+
+
 class Main(object):
     def __init__(self, input_files, override_version, override_tag):
         self.log = sys.stdout.write
@@ -100,22 +135,32 @@
         self.log("Generate orig\n")
         orig = os.path.join(self.dir, self.orig)
         temp = os.path.join(self.dir, 'temp')
-        # TODO: move this informations somewhere else
-        os.mkdir(os.path.join(orig))
-        for i in 'COPYING', 'Kbuild', 'Makefile':
-            shutil.copyfile(os.path.join(temp, i), os.path.join(orig, i))
-        for i in 's390', 'x86':
-            os.makedirs(os.path.join(orig, 'arch', i, 'include'))
-            shutil.copyfile(os.path.join(temp, 'arch', i, 'Makefile'), os.path.join(orig, 'arch', i, 'Makefile'))
-            shutil.copytree(os.path.join(temp, 'arch', i, 'include', 'asm'), os.path.join(orig, 'arch', i, 'include', 'asm'))
-        os.mkdir(os.path.join(orig, 'arch', 'x86', 'lib'))
-        shutil.copyfile(os.path.join(temp, 'arch', 'x86', 'lib', 'memcpy_64.S'), os.path.join(orig, 'arch', 'x86', 'lib', 'memcpy_64.S'))
-        os.mkdir(os.path.join(orig, 'include'))
-        shutil.copytree(os.path.join(temp, 'include', 'linux'), os.path.join(orig, 'include', 'linux'))
-        os.mkdir(os.path.join(orig, 'lib'))
-        shutil.copyfile(os.path.join(temp, 'lib', 'rbtree.c'), os.path.join(orig, 'lib', 'rbtree.c'))
-        shutil.copytree(os.path.join(temp, 'scripts'), os.path.join(orig, 'scripts'))
-        shutil.copytree(os.path.join(temp, 'tools'), os.path.join(orig, 'tools'))
+
+        to_copy = (
+                'COPYING',
+                'Kbuild',
+                'Makefile',
+                'arch/*/include/',
+                'arch/*/Makefile',
+                'arch/x86/lib/memcpy_64.S',
+                'include/',
+                'lib/rbtree.c',
+                'scripts/',
+                'tools/',
+        )
+
+        glob = FileGlob(temp)
+        for i in to_copy:
+            for j in glob(i):
+                temp_j = os.path.join(temp, j)
+                orig_j = os.path.join(orig, j)
+                if j.endswith('/'):
+                    shutil.copytree(temp_j, orig_j)
+                else:
+                    d = os.path.dirname(orig_j)
+                    if not os.path.exists(d):
+                        os.makedirs(d)
+                    shutil.copyfile(temp_j, orig_j)
 
     def tar(self):
         out = os.path.join("../orig", self.orig_tar)



More information about the Kernel-svn-changes mailing list