--- /dev/null
+#!/usr/bin/env python
+
+from daklib.config import Config
+
+import glob, os.path, re, shutil
+
+root_dir = Config()['Dir::Root']
+
+class InstallerCopier:
+ def __init__(self, source = 'unstable', dest = 'testing',
+ **keywords):
+ self.source = source
+ self.dest = dest
+ if 'version' not in keywords:
+ raise KeyError('no version specified')
+ self.version = keywords['version']
+
+ self.source_dir = os.path.join(root_dir, 'dists', source, 'main')
+ self.dest_dir = os.path.join(root_dir, 'dists', dest, 'main')
+ self.check_dir(self.source_dir, 'source does not exist')
+ self.check_dir(self.dest_dir, 'destination does not exist')
+
+ self.architectures = []
+ self.skip_architectures = []
+ self.trees_to_copy = []
+ self.symlinks_to_create = []
+ arch_pattern = os.path.join(self.source_dir, 'installer-*', self.version)
+ for arch_dir in glob.glob(arch_pattern):
+ self.check_architecture(arch_dir)
+
+ def check_dir(self, dir, message):
+ if not os.path.isdir(dir):
+ raise IOError(message)
+
+ def check_architecture(self, arch_dir):
+ architecture = re.sub('.*?/installer-(.*?)/.*', r'\1', arch_dir)
+ dest_basedir = os.path.join(self.dest_dir, \
+ 'installer-%s' % architecture)
+ dest_dir = os.path.join(dest_basedir, self.version)
+ if os.path.isdir(dest_dir):
+ self.skip_architectures.append(architecture)
+ else:
+ self.architectures.append(architecture)
+ self.trees_to_copy.append((arch_dir, dest_dir))
+ symlink_target = os.path.join(dest_basedir, 'current')
+ self.symlinks_to_create.append((self.version, symlink_target))
+
+ def get_message(self):
+ return """
+Will copy installer version %(version)s from suite %(source)s to
+%(dest)s.
+Architectures to copy: %(arch_list)s
+Architectures to skip: %(skip_arch_list)s""" % {
+ 'version': self.version,
+ 'source': self.source,
+ 'dest': self.dest,
+ 'arch_list': ', '.join(self.architectures),
+ 'skip_arch_list': ', '.join(self.skip_architectures)}
+
+ def do_copy(self):
+ for source, dest in self.trees_to_copy:
+ shutil.copytree(source, dest)
+ for source, dest in self.symlinks_to_create:
+ if os.path.lexists(dest):
+ os.unlink(dest)
+ os.symlink(source, dest)
--- /dev/null
+#!/usr/bin/env python
+
+from base_test import DakTestCase
+
+from dak.copy_installer import InstallerCopier
+
+import unittest
+
+class ImportTestCase(DakTestCase):
+ def test_arguments(self):
+ '''test constructor arguments'''
+ # version argument is required
+ self.assertRaises(KeyError, InstallerCopier)
+
+ copier = InstallerCopier(version = '20110106')
+ self.assertEqual('20110106', copier.version)
+ self.assertEqual('unstable', copier.source)
+ self.assertEqual('testing', copier.dest)
+
+ copier = InstallerCopier(version = '20110106', source = \
+ 'proposed-updates')
+ self.assertEqual('proposed-updates', copier.source)
+
+ copier = InstallerCopier(version = '20110106', dest = 'stable')
+ self.assertEqual('stable', copier.dest)
+
+ def test_dir_names(self):
+ copier = InstallerCopier(version = '20110106')
+ self.assertEqual('fixtures/ftp/dists/unstable/main',
+ copier.source_dir)
+ self.assertEqual('fixtures/ftp/dists/testing/main',
+ copier.dest_dir)
+
+ def missing_source(self):
+ copier = InstallerCopier(version = '20110106', source = 'foo')
+
+ def missing_dest(self):
+ copier = InstallerCopier(version = '20110106', dest = 'bar')
+
+ def test_suites(self):
+ self.assertRaises(IOError, self.missing_source)
+ self.assertRaises(IOError, self.missing_dest)
+
+ def test_copy(self):
+ copier = InstallerCopier(version = '20110106')
+ self.assertEqual(['amd64'], copier.architectures)
+ self.assertEqual(['i386'], copier.skip_architectures)
+ self.assertEqual( \
+ [('fixtures/ftp/dists/unstable/main/installer-amd64/20110106', \
+ 'fixtures/ftp/dists/testing/main/installer-amd64/20110106'),], \
+ copier.trees_to_copy)
+ self.assertEqual([('20110106', \
+ 'fixtures/ftp/dists/testing/main/installer-amd64/current')], \
+ copier.symlinks_to_create)
+ self.assertEqual('''
+Will copy installer version 20110106 from suite unstable to
+testing.
+Architectures to copy: amd64
+Architectures to skip: i386''', copier.get_message())
+
+if __name__ == '__main__':
+ unittest.main()