~launchpad-pqm/launchpad/devel

8687.15.12 by Karl Fogel
Add the copyright header block to files under lib/lp/archivepublisher/
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
3
4
"""The processing of dist-upgrader tarballs."""
5
6
__metaclass__ = type
7
3838.1.4 by James Henstridge
move dist_upgrader.py over to refactored code
8
__all__ = ['process_dist_upgrader']
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
9
10
import os
11
8426.7.1 by Julian Edwards
migrate archivepublisher to the lp tree.
12
from lp.archivepublisher.customupload import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
13
    CustomUpload,
14
    CustomUploadError,
15
    )
10245.6.5 by Jelmer Vernooij
Revert imports.
16
from lp.archivepublisher.debversion import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
17
    BadUpstreamError,
18
    Version as make_version,
19
    )
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
20
3838.1.4 by James Henstridge
move dist_upgrader.py over to refactored code
21
22
class DistUpgraderAlreadyExists(CustomUploadError):
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
23
    """A build for this type, version already exists."""
24
    def __init__(self, arch, version):
25
        message = ('dist-upgrader build %s for architecture %s already exists'%
26
                   (arch, version))
3838.1.4 by James Henstridge
move dist_upgrader.py over to refactored code
27
        CustomUploadError.__init__(self, message)
28
29
30
class DistUpgraderBadVersion(CustomUploadError):
31
    def __init__(self, tarfile_path, exc):
32
        message = "bad version found in '%s': %s" % (tarfile_path, str(exc))
33
        CustomUploadError.__init__(self, message)
34
35
36
class DistUpgraderUpload(CustomUpload):
3838.1.11 by Celso Providelo
applying review comments [r=bjornt]
37
    """Dist Upgrader custom upload processor.
38
39
    Dist-Upgrader is a tarball containing files for performing automatic
5121.2.7 by Stuart Bishop
More required code changes
40
    distroseries upgrades, driven by architecture.
3838.1.11 by Celso Providelo
applying review comments [r=bjornt]
41
42
    The tarball should be name as:
43
44
      <NAME>_<VERSION>_<ARCH>.tar.gz
45
46
    where:
47
48
     * NAME: can be anything reasonable like 'dist-upgrader', it's not used;
49
     * VERSION: debian-like version token;
50
     * ARCH: debian-like architecture tag.
51
52
    and should contain:
53
54
     * ReleaseAnnouncement text file;
5121.2.7 by Stuart Bishop
More required code changes
55
     * <distroseries>.tar.gz file.
3838.1.11 by Celso Providelo
applying review comments [r=bjornt]
56
57
    Dist-Upgrader versions are published under:
58
59
    <ARCHIVE>/dists/<SUITE>/main/dist-upgrader-<ARCH>/<VERSION>/
60
61
    A 'current' symbolic link points to the most recent version.
62
    """
5121.2.7 by Stuart Bishop
More required code changes
63
    def __init__(self, archive_root, tarfile_path, distroseries):
64
        CustomUpload.__init__(self, archive_root, tarfile_path, distroseries)
3838.1.4 by James Henstridge
move dist_upgrader.py over to refactored code
65
66
        tarfile_base = os.path.basename(tarfile_path)
67
        name, self.version, arch = tarfile_base.split('_')
68
        arch = arch.split('.')[0]
69
5121.2.7 by Stuart Bishop
More required code changes
70
        self.targetdir = os.path.join(archive_root, 'dists', distroseries,
3838.1.4 by James Henstridge
move dist_upgrader.py over to refactored code
71
                                      'main', 'dist-upgrader-%s' % arch)
72
73
        # Make sure the target version doesn't already exist. If it does, raise
74
        # DistUpgraderAlreadyExists.
75
        if os.path.exists(os.path.join(self.targetdir, self.version)):
76
            raise DistUpgraderAlreadyExists(arch, self.version)
77
78
    def shouldInstall(self, filename):
3838.1.11 by Celso Providelo
applying review comments [r=bjornt]
79
        """ Install files from a dist-upgrader tarball.
80
81
        It raises DistUpgraderBadVersion if if finds a directory name that
82
        could not be treated as a valid Debian version.
83
84
        It returns False for extracted contents of a directory named
85
        'current' (since it would obviously conflict with the symbolic
86
        link in the archive).
87
88
        Return True for contents of 'versionable' directories.
89
        """
3838.1.12 by Celso Providelo
more review comments.
90
        # Only the first path part (directory name) must be *versionable*
91
        # and we may allow subdirectories.
92
        directory_name = filename.split(os.path.sep)[0]
3838.1.4 by James Henstridge
move dist_upgrader.py over to refactored code
93
        try:
94
            version = make_version(directory_name)
10245.6.7 by Jelmer Vernooij
Re-add comments.
95
        except BadUpstreamError, exc:
3838.1.4 by James Henstridge
move dist_upgrader.py over to refactored code
96
            raise DistUpgraderBadVersion(self.tarfile_path, exc)
97
        return version and not filename.startswith('current')
98
3838.1.10 by Celso Providelo
Improve documentation and tests.
99
5121.2.7 by Stuart Bishop
More required code changes
100
def process_dist_upgrader(archive_root, tarfile_path, distroseries):
3686.1.16 by Celso Providelo
more review comments, workaround custom format processor API, remove unused variables and other minor issues.
101
    """Process a raw-dist-upgrader tarfile.
102
5121.2.7 by Stuart Bishop
More required code changes
103
    Unpacking it into the given archive for the given distroseries.
3838.1.4 by James Henstridge
move dist_upgrader.py over to refactored code
104
    Raises CustomUploadError (or some subclass thereof) if anything goes
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
105
    wrong.
106
    """
5121.2.7 by Stuart Bishop
More required code changes
107
    upload = DistUpgraderUpload(archive_root, tarfile_path, distroseries)
3838.1.4 by James Henstridge
move dist_upgrader.py over to refactored code
108
    upload.process()