~ubuntu-branches/ubuntu/intrepid/devmapper/intrepid

« back to all changes in this revision

Viewing changes to debian/bin/genorig.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2008-06-02 17:22:40 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080602172240-tb5pinmq9zxghxyb
Tags: 2:1.02.25-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - Call dmsetup from udev rules to name the device, so udev creates them
    if they do not already exist, and fill in information about the
    filesystem on the device afterwards.
    (forwarded to Debian #455746):
    + Add debian/dmsetup.udev: Naming udev rules.
    + debian/rules: Call dh_installudev to install above file.
    + debian/control: Add Recommends: dmsetup to the library and the udeb.
  - Support udev-controlled devmapper in initramfs, for consistent device
    discovery/naming during boot and hotplug:
    + Add debian/dmsetup.initramfs: Hook for copying dmsetup and udev rules
      to the initramfs.
    + debian/rules: Copy hook to build directory.
    + debian/dmsetup.install: Install above file from build directory.
    + debian/dmsetup.postinst: Call update-initramfs.
  - debian/rules: Copy po/device-mapper.po to device-mapper.pot so Rosetta
    has a POT file to import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import os, os.path, re, shutil, sys
 
4
 
 
5
class GenOrig(object):
 
6
    log = sys.stdout.write
 
7
 
 
8
    source = 'devmapper'
 
9
 
 
10
    def __init__(self, input_tar, version):
 
11
        self.input_tar, self.version = input_tar, version
 
12
 
 
13
    def __call__(self):
 
14
        import tempfile
 
15
        self.dir = tempfile.mkdtemp(prefix = 'genorig', dir = 'debian')
 
16
        try:
 
17
            self.orig_dir = "%s-%s" % (self.source, self.version)
 
18
            self.orig_tar = "%s_%s.orig.tar.gz" % (self.source, self.version)
 
19
 
 
20
            self.do_upstream()
 
21
            self.do_orig()
 
22
        finally:
 
23
            shutil.rmtree(self.dir)
 
24
 
 
25
    def do_upstream(self):
 
26
        self.log("Extracting tarball %s\n" % self.input_tar)
 
27
        match = re.match(r'(^|.*/)(?P<dir>device-mapper\.\d+\.\d+\.\d+)\.t(?P<extension>(gz|bz2))$', self.input_tar)
 
28
        if not match:
 
29
            raise RuntimeError("Can't identify name of tarball")
 
30
        cmdline = ['tar -xf', self.input_tar, '-C', self.dir]
 
31
        extension = match.group('extension')
 
32
        if extension == 'bz2':
 
33
            cmdline.append('-j')
 
34
        elif extension == 'gz':
 
35
            cmdline.append('-z')
 
36
        if os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', ' '.join(cmdline)]):
 
37
            raise RuntimeError("Can't extract tarball")
 
38
        os.rename(os.path.join(self.dir, match.group('dir')), os.path.join(self.dir, self.orig_dir))
 
39
 
 
40
    def do_orig(self):
 
41
        out = "../orig/%s" % self.orig_tar
 
42
 
 
43
        try:
 
44
            os.mkdir("../orig")
 
45
        except OSError: pass
 
46
        try:
 
47
            os.stat(out)
 
48
        except OSError: pass
 
49
        else:
 
50
            raise RuntimeError("Destination already exists")
 
51
 
 
52
        self.log("Generate tarball %s\n" % out)
 
53
        cmdline = ['tar -czf', out, '-C', self.dir, self.orig_dir]
 
54
        try:
 
55
            if os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', ' '.join(cmdline)]):
 
56
                raise RuntimeError("Can't patch source")
 
57
            os.chmod(out, 0644)
 
58
        except:
 
59
            try:
 
60
                os.unlink(out)
 
61
            except OSError:
 
62
                pass
 
63
            raise
 
64
 
 
65
if __name__ == '__main__':
 
66
    from optparse import OptionParser
 
67
    p = OptionParser()
 
68
    #p.add_option("-v", "--version", dest = "version")
 
69
    options, args = p.parse_args(sys.argv)
 
70
 
 
71
    input_tar = args[1]
 
72
    version = args[2]
 
73
 
 
74
    GenOrig(input_tar, version)()