diff options
author | Andoni Morales Alastruey <ylatuya@gmail.com> | 2012-05-09 22:26:43 +0200 |
---|---|---|
committer | Andoni Morales Alastruey <ylatuya@gmail.com> | 2012-05-10 10:45:49 +0200 |
commit | bf288bbc02e10d659f84fe5abc874cf841f61056 (patch) | |
tree | 9db6c1310f3f93db30101aa2572c69be24fea502 | |
parent | 76849d97274b9c9efa76a85491c5c8d8bdcc1b15 (diff) |
packages: clean up linux packager and add unit tests
-rw-r--r-- | cerbero/packages/linux.py | 92 | ||||
-rw-r--r-- | test/test_cerbero_packages_linux.py | 179 | ||||
-rw-r--r-- | test/test_common.py | 5 |
3 files changed, 230 insertions, 46 deletions
diff --git a/cerbero/packages/linux.py b/cerbero/packages/linux.py index af70009..93f70ce 100644 --- a/cerbero/packages/linux.py +++ b/cerbero/packages/linux.py @@ -33,15 +33,10 @@ class LinuxPackager(PackagerBase): def __init__(self, config, package, store): PackagerBase.__init__(self, config, package, store) self.package_prefix = '' - if self.config.packages_prefix is not None and not\ - package.ignore_package_prefix: - self.package_prefix = '%s-' % self.config.packages_prefix - self.full_package_name = '%s%s-%s' % (self.package_prefix, - self.package.name, self.package.version) + self.package_prefix = self._package_prefix(self.package) + self.full_package_name = self._full_package_name() self.packager = self.config.packager - if self.packager == DEFAULT_PACKAGER: - m.warning(_('No packager defined, using default ' - 'packager "%s"') % self.packager) + self._check_packager() def pack(self, output_dir, devel=True, force=False, pack_deps=True, tmpdir=None): @@ -88,6 +83,15 @@ class LinuxPackager(PackagerBase): def create_tree(self, tmpdir): pass + def setup_source(self, tarball, tmpdir, packagedir, srcdir): + pass + + def prepare(self, tarname, tmpdir, packagedir, srcdir): + pass + + def build(self, output_dir, tarname, tmpdir, packagedir, srcdir): + pass + def pack_deps(self, output_dir, tmpdir, force): for p in self.store.get_package_deps(self.package.name): stamp_path = os.path.join(tmpdir, p.name + '-stamp') @@ -103,15 +107,6 @@ class LinuxPackager(PackagerBase): except EmptyPackageError: self._empty_packages.append(p) - def setup_source(self, tarball, tmpdir, packagedir, srcdir): - pass - - def prepare(self, tarname, tmpdir, packagedir, srcdir): - pass - - def build(self, output_dir, tarname, tmpdir, packagedir, srcdir): - pass - def get_meta_requires(self, package_type, package_suffix): requires = [] suggests = [] @@ -119,16 +114,13 @@ class LinuxPackager(PackagerBase): for p in self.package.packages: package = self.store.get_package(p[0]) if package_type == PackageType.DEVEL: - if hasattr(package, 'has_devel_package'): - if not package.has_devel_package: - continue - package_name = p[0] - if self.config.packages_prefix is not None \ - and not package.ignore_package_prefix: - package_name = ('%s-%s' % (self.config.packages_prefix, p[0])) - package_name += package_suffix + if not self._has_devel_package(package): + continue + package_name = '%s%s' % (self._package_prefix(package), p[0]) + if package_type == PackageType.DEVEL: + package_name += package_suffix if p[1]: - requires.append(package_name) + requires.append(package_name) elif p[2]: recommends.append(package_name) else: @@ -136,31 +128,21 @@ class LinuxPackager(PackagerBase): return (requires, recommends, suggests) def get_requires(self, package_type, devel_suffix): - deps = [p.name for p in self.store.get_package_deps(self.package.name)] + deps = self.store.get_package_deps(self.package.name) deps = list(set(deps) - set(self._empty_packages)) - def get_dep_name(package_name): - p = self.store.get_package(package_name) - package_prefix = '' - if self.config.packages_prefix is not None \ - and not p.ignore_package_prefix: - package_prefix = '%s-' % self.config.packages_prefix - return package_prefix + package_name - - details = {} - for x in deps: - details[x] = get_dep_name(x) + def dep_name(p): + name = '%s%s' % (self._package_prefix(p), p.name) + if package_type == PackageType.DEVEL: + name += devel_suffix + return name if package_type == PackageType.DEVEL: - deps = [x for x in deps \ - if hasattr(self.store.get_package(x), 'has_devel_package') and - self.store.get_package(x).has_devel_package] - deps = map(lambda x: details[x] + devel_suffix, deps) - else: - deps = map(lambda x: details[x], deps) + deps = [x for x in deps if self._has_devel_package(x)] + deps = [dep_name(x) for x in deps] deps.extend(self.package.get_sys_deps()) - return deps + return sorted(deps) def recipes_licenses(self): licenses = [] @@ -175,3 +157,23 @@ class LinuxPackager(PackagerBase): if isinstance(self.package, MetaPackage): return '' return PackagerBase.files_list(self, package_type, self.force) + + def _package_prefix(self, package): + if self.config.packages_prefix not in [None, '']: + if not package.ignore_package_prefix: + return '%s-' % self.config.packages_prefix + return '' + + def _full_package_name(self): + return '%s%s-%s' % (self.package_prefix, self.package.name, + self.package.version) + + def _check_packager(self): + if self.packager == DEFAULT_PACKAGER: + m.warning(_('No packager defined, using default ' + 'packager "%s"') % self.packager) + + def _has_devel_package(self, package): + if hasattr(package, 'has_devel_package'): + return package.has_devel_package + return False diff --git a/test/test_cerbero_packages_linux.py b/test/test_cerbero_packages_linux.py new file mode 100644 index 0000000..e1b99ca --- /dev/null +++ b/test/test_cerbero_packages_linux.py @@ -0,0 +1,179 @@ +# cerbero - a multi-platform build system for Open Source software +# Copyright (C) 2012 Andoni Morales Alastruey <ylatuya@gmail.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +import unittest +import os + +from cerbero.config import DEFAULT_PACKAGER +from cerbero.packages import PackageType +from cerbero.packages import linux, PackagerBase +from test.test_common import DummyConfig as Config +from test.test_packages_common import Package1, create_store + + +packed = [] + + +class LoggerPackager(linux.LinuxPackager): + + def pack(self, output_dir, devel, force, pack_deps, tmpdir): + packed.append(self.package.name) + + +class DummyPackager(linux.LinuxPackager): + + def build(self, output_dir, tarname, tmpdir, packagedir, srcdir): + linux.LinuxPackager.build(self, output_dir, tarname, tmpdir, + packagedir, srcdir) + return ['test'] + + def create_tree(self, tmpdir): + linux.LinuxPackager.create_tree(self, tmpdir) + return ('', '', '') + + +class DummyTarballPackager(PackagerBase): + + def pack(self, output_dir, devel=True, force=False, split=True, + package_prefix=''): + return ['test'] + + +linux.DistTarball = DummyTarballPackager + + +class LinuxPackagesTest(unittest.TestCase): + + def setUp(self): + self.config = Config() + self.store = create_store(self.config) + self.packager = linux.LinuxPackager(self.config, + self.store.get_package('gstreamer-runtime'), self.store) + + def testInit(self): + config = Config() + + # Test default values + package = Package1(config, None, None) + packager = linux.LinuxPackager(config, package, None) + self.assertEquals(packager.package_prefix, '') + self.assertEquals(packager.full_package_name, 'gstreamer-test1-1.0') + self.assertEquals(packager.packager, DEFAULT_PACKAGER) + + # Test packages_prefix and packager + config.packages_prefix = 'test' + config.packager = 'Pin <pan@p.un>' + packager = linux.LinuxPackager(config, package, None) + self.assertEquals(packager.package_prefix, 'test-') + self.assertEquals(packager.full_package_name, + 'test-gstreamer-test1-1.0') + self.assertEquals(packager.packager, 'Pin <pan@p.un>') + + # Test ignore package + package.ignore_package_prefix = True + packager = linux.LinuxPackager(config, package, None) + self.assertEquals(packager.package_prefix, '') + self.assertEquals(packager.full_package_name, 'gstreamer-test1-1.0') + + def testRequires(self): + self.packager._empty_packages = [] + expected = sorted(['gstreamer-test-bindings', + 'gstreamer-test2', + 'gstreamer-test3', + 'gstreamer-test1']) + + requires = self.packager.get_requires(PackageType.RUNTIME, '-dev') + self.assertEquals(expected, requires) + + # test devel packages + requires = self.packager.get_requires(PackageType.DEVEL, '-dev') + self.assertEquals([], requires) + self.store.get_package('gstreamer-test1').has_devel_package = True + requires = self.packager.get_requires(PackageType.DEVEL, '-dev') + self.assertEquals(['gstreamer-test1-dev'], requires) + for p in expected: + self.store.get_package(p).has_devel_package = True + requires = self.packager.get_requires(PackageType.DEVEL, '-dev') + self.assertEquals([x + '-dev' for x in expected], requires) + + # test empty packages + self.packager._empty_packages = \ + [self.store.get_package('gstreamer-test2')] + requires = self.packager.get_requires(PackageType.RUNTIME, '-dev') + expected.remove('gstreamer-test2') + self.assertEquals(expected, requires) + + def testMetaPackageRequires(self): + self.packager._empty_packages = [] + expected = (['gstreamer-test1'], + ['gstreamer-test3'], + ['gstreamer-test-bindings']) + requires = self.packager.get_meta_requires(PackageType.RUNTIME, '-dev') + self.assertEquals(expected, requires) + + # test devel packages + requires = self.packager.get_meta_requires(PackageType.DEVEL, '-dev') + self.assertEquals(([], [], []), requires) + + # test empty packages + self.store.get_package('gstreamer-test1').has_devel_package = True + requires = self.packager.get_meta_requires(PackageType.DEVEL, '-dev') + self.assertEquals((['gstreamer-test1-dev'], [], []), requires) + + for p in [self.store.get_package(x[0]) for x in expected]: + p.has_devel_package = True + requires = self.packager.get_meta_requires(PackageType.DEVEL, '-dev') + expected = (['gstreamer-test1-dev'], + ['gstreamer-test3-dev'], + ['gstreamer-test-bindings-dev']) + self.assertEquals(expected, requires) + + def testPackDeps(self): + expected = sorted(['gstreamer-test-bindings', + 'gstreamer-test2', + 'gstreamer-test3', + 'gstreamer-test1']) + self.packager = LoggerPackager(self.config, + self.store.get_package('gstreamer-runtime'), self.store) + self.packager.devel = False + self.packager.force = False + global packed + packed = [] + self.packager.pack_deps('', '', True) + self.assertEquals(sorted(packed), expected) + packed = [] + + self.packager.devel = False + self.packager.pack_deps('', '', True) + self.assertEquals(sorted(packed), expected) + packed = [] + + def testPack(self): + self.packager = DummyPackager(self.config, + self.store.get_package('gstreamer-runtime'), self.store) + paths = self.packager.pack('', False, True, False, None) + self.assertTrue(os.path.exists('gstreamer-runtime-stamp')) + os.remove('gstreamer-runtime-stamp') + self.assertEquals(paths, ['test']) + + self.packager = DummyPackager(self.config, + self.store.get_package('gstreamer-test1'), self.store) + paths = self.packager.pack('', False, True, False, None) + self.assertTrue(os.path.exists('gstreamer-test1-stamp')) + os.remove('gstreamer-test1-stamp') + self.assertEquals(paths, ['test']) diff --git a/test/test_common.py b/test/test_common.py index 2932be0..d03988d 100644 --- a/test/test_common.py +++ b/test/test_common.py @@ -16,12 +16,13 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -from cerbero.config import Platform +from cerbero.config import Platform, Distro, DEFAULT_PACKAGER class DummyConfig(object): prefix = '/test/' target_platform = Platform.WINDOWS + target_distro = Distro.WINDOWS platform = None sources = '' local_sources = '' @@ -33,6 +34,8 @@ class DummyConfig(object): target_version = None target_distro_version = None packages_prefix = '' + packager = DEFAULT_PACKAGER + install_dir = '' class XMLMixin(): |