[kernel] r6070 - in people/waldi/scripts: . snapshot

Bastian Blank waldi at costa.debian.org
Sun Mar 5 11:45:13 UTC 2006


Author: waldi
Date: Sun Mar  5 11:45:11 2006
New Revision: 6070

Added:
   people/waldi/scripts/
   people/waldi/scripts/snapshot/
   people/waldi/scripts/snapshot/package.py   (contents, props changed)
Log:
* /scripts, /scripts/snapshot: New directory.
* /scripts/snapshot/package.py: Add.


Added: people/waldi/scripts/snapshot/package.py
==============================================================================
--- (empty file)
+++ people/waldi/scripts/snapshot/package.py	Sun Mar  5 11:45:11 2006
@@ -0,0 +1,240 @@
+#!/usr/bin/env python2.4
+
+# Copyright (C) 2005 Bastian Blank <waldi at debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+import debian_linux, os.path, shutil, sys, time
+
+base = os.path.expanduser("~/debian/kernel/snapshot")
+repository = "svn+ssh://svn.debian.org/svn/kernel/"
+orig_base = os.path.expanduser("~/debian/kernel/orig")
+
+def _spawnvefn(mode, file, args, env, func, prepare, prepare_arg):
+    # Internal helper; func is the exec*() function to use
+    pid = os.fork()
+    if not pid:
+        # Child
+        prepare(prepare_arg)
+        try:
+            if env is None:
+                func(file, args)
+            else:
+                func(file, args, env)
+        except:
+            os._exit(127)
+    else:
+        # Parent
+        if mode == os.P_NOWAIT:
+            return pid # Caller is responsible for waiting!
+        while 1:
+            wpid, sts = os.waitpid(pid, 0)
+            if os.WIFSTOPPED(sts):
+                continue
+            elif os.WIFSIGNALED(sts):
+                return -os.WTERMSIG(sts)
+            elif os.WIFEXITED(sts):
+                return os.WEXITSTATUS(sts)
+            else:
+                raise error, "Not stopped, signaled or exited???"
+
+def spawnv_chdir(mode, file, args, dir):
+    return _spawnvefn(mode, file, args, None, os.execvp, spawnv_chdir_prepare, dir)
+
+def spawnv_chdir_prepare(arg):
+    os.chdir(arg)
+
+class storage(object):
+    def __init__(self, dir):
+        self.dir = dir
+
+    def _cp(self, source, target, prune = []):
+        source = os.path.normpath(source)
+        source_list = source.split(os.sep) 
+        try: 
+            os.stat(target)
+        except OSError:
+            self._mk(target)
+        for root, dirs, files in os.walk(source):
+            rel_root_list = root.split(os.sep)[len(source_list):]
+            rel_root = os.sep.join(rel_root_list)
+            target_root = os.path.join(target, rel_root)
+            for i in prune:
+                try:
+                    dirs.remove(i)
+                except ValueError:
+                    pass
+            for name in dirs:
+                os.mkdir(os.path.join(target_root, name))
+            for name in files:
+                os.link(os.path.join(root, name), os.path.join(target_root, name))
+
+    def _exec(self, executable, args):
+        args_real = [executable.split(os.sep)[-1]] + args
+        ret = os.spawnv(os.P_WAIT, executable, args_real)
+        if ret:
+            raise ExecutionError(ret)
+
+    def _exec_chdir(self, executable, args, dir, force = False, output = True):
+        args_real = [executable.split(os.sep)[-1]] + args
+        ret = spawnv_chdir(os.P_WAIT, executable, args_real, dir)
+        if ret:
+            raise ExecutionError(ret)
+
+    def _mk(self, dir):
+        try:
+            os.makedirs(dir, 0755)
+        except OSError:
+            pass
+
+    def _rm(self, dir):
+        try:
+          shutil.rmtree(dir)
+        except OSError:
+          pass
+
+    def copy(self, target, target_class = None, **args):
+        self._rm(target)
+        self._cp(self.dir, target, ['.svn'])
+        if not target_class:
+            target_class = self.__class__
+        return target_class(target, **args)
+
+    def remove(self):
+        self._rm(self.dir)
+
+class repository_svn(storage):
+    def __init__(self, dir, path):
+        storage.__init__(self, dir)
+        self.path = path
+        self.checkout()
+
+    def checkout(self):
+        path_real = '%s/%s' % (repository, self.path)
+        args = ['co', '-q', path_real, self.dir]
+        self.exec_svn(args)
+
+    def exec_svn(self, args):
+        self._exec("/usr/bin/svn", args)
+
+def package(path, dist):
+    checkout_dir = "checkout-" + path.replace('/', '_')
+    last_file = "last-" + path.replace('/', '_')
+    checkout_storage = repository_svn(checkout_dir, path)
+    changelog_entry = debian_linux.read_changelog(checkout_dir)[0]
+    package_name = changelog_entry['Source']
+    package_version = changelog_entry['Version']['source_upstream']
+    package = "%s-%s" % (package_name, package_version)
+    package_dir = "gen/%s" % package
+    package_orig_tar = "%s_%s.orig.tar.gz" % (package_name, package_version)
+    package_orig_source = "%s/%s" % (orig_base, package)
+    package_orig_source_tar = "%s/%s" % (orig_base, package_orig_tar)
+
+    for line in os.popen("svn info %s" % checkout_dir, 'r').read().split('\n'):
+        if line.startswith('Last Changed Rev: '):
+            revision = int(line.split()[-1])
+
+    last_revision = 0
+    last_upstream = None
+    if os.path.exists(last_file):
+        i = file(last_file).read().strip()
+        last_revision, last_upstream = i.split()
+        last_revision = int(last_revision)
+    elif not os.path.exists("out"):
+        os.makedirs("out" , 0755)
+
+    if revision <= last_revision:
+        return
+
+    version_upstream = changelog_entry['Version']['upstream']
+    version_debian = changelog_entry['Version']['debian'].split('.')
+    version_debian_end = int(version_debian[-1])
+    if changelog_entry['Distribution'] in ('stable', 'testing', 'unstable', 'experimental'):
+        pass
+    elif changelog_entry['Distribution'] in ('UNRELEASED',):
+        version_debian_end -= 1
+    else:
+        raise "Unknown distribution"
+
+    version_debian[-1] = "%dsnapshot.%d" % (version_debian_end, revision)
+    version_debian = '.'.join(version_debian)
+
+    package_storage = checkout_storage.copy(package_dir, storage)
+    package_storage._mk("gen/orig")
+    try:
+        os.unlink("gen/orig/%s" % package)
+    except OSError: pass
+    try:
+        os.unlink("gen/%s" % package_orig_tar)
+    except OSError: pass
+    try:
+        os.unlink("out/%s" % package_orig_tar)
+    except OSError: pass
+    os.symlink(package_orig_source, "gen/orig/%s" % package)
+    os.symlink(package_orig_source_tar, "gen/%s" % package_orig_tar)
+    os.symlink(package_orig_source_tar, "out/%s" % package_orig_tar)
+
+    changelog = "%s/debian/changelog" % package_dir
+    changelog_text = file(changelog).read()
+    os.unlink(changelog)
+    f = file(changelog, "w")
+    f.write("""\
+%s (%s-%s) %s; urgency=low
+
+  * Snapshot.
+
+ -- Bastian Blank <waldi at debian.org>  %s
+
+""" % (
+        package_name, package_version, version_debian, dist,
+        time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()),
+    )
+)
+    f.write(changelog_text)
+    del f
+    spawnv_chdir(os.P_WAIT, "debian/rules", ['debian/rules', 'debian/control'], package_dir)
+    spawnv_chdir(os.P_WAIT, "debian/rules", ['debian/rules', 'orig'], package_dir)
+
+    list = ['dpkg-buildpackage', '-kDAEE1CDC', '-S', '-i^(Documentation|arch|drivers|include)']
+    if version_upstream != last_upstream:
+        spawnv_chdir(os.P_WAIT, "dpkg-buildpackage", list + ['-sa'], package_dir)
+    else:
+        spawnv_chdir(os.P_WAIT, "dpkg-buildpackage", list + ['-sd'], package_dir)
+
+    for suffix in ('.diff.gz', '.dsc', '_source.changes'):
+        prefix = '%s_%s-%s' % (package_name, package_version, version_debian)
+        os.link("gen/%s%s" % (prefix, suffix), "out/%s%s" % (prefix, suffix))
+        os.unlink("gen/%s%s" % (prefix, suffix))
+
+    file(last_file, 'w').write("%d %s\n" % (revision, version_upstream))
+
+    package_storage.remove()
+
+    spawnv_chdir(os.P_WAIT, 'dput', ['dput', 'debian-kernel', '%s_%s-%s_source.changes' % (package_name, package_version, version_debian)], "out")
+
+def main():
+    maps = {
+        "dists/sid/linux-2.6": "kernel-dists-sid",
+        "dists/trunk/linux-2.6": "kernel-dists-trunk",
+    }
+    if len(sys.argv) > 1:
+        paths = sys.argv[1:]
+    else:
+        paths = maps.keys()
+    for path in paths:
+        package(path, maps[path])
+
+if __name__ == '__main__':
+    main()



More information about the Kernel-svn-changes mailing list