3 from daklib.config import Config
5 import glob, os.path, re, shutil
7 root_dir = Config()['Dir::Root']
10 def __init__(self, source = 'unstable', dest = 'testing',
14 if 'version' not in keywords:
15 raise KeyError('no version specified')
16 self.version = keywords['version']
18 self.source_dir = os.path.join(root_dir, 'dists', source, 'main')
19 self.dest_dir = os.path.join(root_dir, 'dists', dest, 'main')
20 self.check_dir(self.source_dir, 'source does not exist')
21 self.check_dir(self.dest_dir, 'destination does not exist')
23 self.architectures = []
24 self.skip_architectures = []
25 self.trees_to_copy = []
26 self.symlinks_to_create = []
27 arch_pattern = os.path.join(self.source_dir, 'installer-*', self.version)
28 for arch_dir in glob.glob(arch_pattern):
29 self.check_architecture(arch_dir)
31 def check_dir(self, dir, message):
32 if not os.path.isdir(dir):
33 raise IOError(message)
35 def check_architecture(self, arch_dir):
36 architecture = re.sub('.*?/installer-(.*?)/.*', r'\1', arch_dir)
37 dest_basedir = os.path.join(self.dest_dir, \
38 'installer-%s' % architecture)
39 dest_dir = os.path.join(dest_basedir, self.version)
40 if os.path.isdir(dest_dir):
41 self.skip_architectures.append(architecture)
43 self.architectures.append(architecture)
44 self.trees_to_copy.append((arch_dir, dest_dir))
45 symlink_target = os.path.join(dest_basedir, 'current')
46 self.symlinks_to_create.append((self.version, symlink_target))
48 def get_message(self):
50 Will copy installer version %(version)s from suite %(source)s to
52 Architectures to copy: %(arch_list)s
53 Architectures to skip: %(skip_arch_list)s""" % {
54 'version': self.version,
55 'source': self.source,
57 'arch_list': ', '.join(self.architectures),
58 'skip_arch_list': ', '.join(self.skip_architectures)}
61 for source, dest in self.trees_to_copy:
62 shutil.copytree(source, dest)
63 for source, dest in self.symlinks_to_create:
64 if os.path.lexists(dest):
66 os.symlink(source, dest)