3 """ Copies the installer from one suite to another """
4 # Copyright (C) 2011 Torsten Werner <twerner@debian.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ################################################################################
22 from daklib.config import Config
24 import apt_pkg, glob, os.path, re, shutil, sys
26 def usage(exit_code = 0):
27 print """Usage: dak copy-installer [OPTION]... VERSION
28 -h, --help show this help and exit
29 -s, --source source suite (defaults to unstable)
30 -d, --destination destination suite (defaults to testing)
31 -n, --no-action don't change anything
33 Exactly 1 version must be specified."""
39 ('h', "help", "Copy-Installer::Options::Help"),
40 ('s', "source", "Copy-Installer::Options::Source", "HasArg"),
41 ('d', "destination", "Copy-Installer::Options::Destination", "HasArg"),
42 ('n', "no-action", "Copy-Installer::Options::No-Action"),
44 for option in [ "help", "source", "destination", "no-action" ]:
45 if not cnf.has_key("Copy-Installer::Options::%s" % (option)):
46 cnf["Copy-Installer::Options::%s" % (option)] = ""
47 extra_arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
48 Options = cnf.subtree("Copy-Installer::Options")
52 if len(extra_arguments) != 1:
55 initializer = { "version": extra_arguments[0] }
56 if Options["Source"] != "":
57 initializer["source"] = Options["Source"]
58 if Options["Destination"] != "":
59 initializer["dest"] = Options["Destination"]
61 copier = InstallerCopier(**initializer)
62 print copier.get_message()
63 if Options["No-Action"]:
64 print 'Do nothing because --no-action has been set.'
67 print 'Installer has been copied successfully.'
69 root_dir = Config()['Dir::Root']
71 class InstallerCopier:
72 def __init__(self, source = 'unstable', dest = 'testing',
76 if 'version' not in keywords:
77 raise KeyError('no version specified')
78 self.version = keywords['version']
80 self.source_dir = os.path.join(root_dir, 'dists', source, 'main')
81 self.dest_dir = os.path.join(root_dir, 'dists', dest, 'main')
82 self.check_dir(self.source_dir, 'source does not exist')
83 self.check_dir(self.dest_dir, 'destination does not exist')
85 self.architectures = []
86 self.skip_architectures = []
87 self.trees_to_copy = []
88 self.symlinks_to_create = []
89 arch_pattern = os.path.join(self.source_dir, 'installer-*', self.version)
90 for arch_dir in glob.glob(arch_pattern):
91 self.check_architecture(arch_dir)
93 def check_dir(self, dir, message):
94 if not os.path.isdir(dir):
95 raise IOError(message)
97 def check_architecture(self, arch_dir):
98 architecture = re.sub('.*?/installer-(.*?)/.*', r'\1', arch_dir)
99 dest_basedir = os.path.join(self.dest_dir, \
100 'installer-%s' % architecture)
101 dest_dir = os.path.join(dest_basedir, self.version)
102 if os.path.isdir(dest_dir):
103 self.skip_architectures.append(architecture)
105 self.architectures.append(architecture)
106 self.trees_to_copy.append((arch_dir, dest_dir))
107 symlink_target = os.path.join(dest_basedir, 'current')
108 self.symlinks_to_create.append((self.version, symlink_target))
110 def get_message(self):
112 Will copy installer version %(version)s from suite %(source)s to
114 Architectures to copy: %(arch_list)s
115 Architectures to skip: %(skip_arch_list)s""" % {
116 'version': self.version,
117 'source': self.source,
119 'arch_list': ', '.join(self.architectures),
120 'skip_arch_list': ', '.join(self.skip_architectures)}
123 for source, dest in self.trees_to_copy:
124 shutil.copytree(source, dest, symlinks=True)
125 for source, dest in self.symlinks_to_create:
126 if os.path.lexists(dest):
128 os.symlink(source, dest)
131 if __name__ == '__main__':