From d519b79d61b69591412efd8f2f294944ea7f552c Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Sat, 06 Jun 2009 15:32:08 +0000 Subject: Partial rewrite of the sysdeps code: * added support for reading multiple sysdeps files (so they can be split and thus the redundancy reduced) * fallback to unstable distro version if current version is unknown (so it won't stop working when Fedora switches versions) * abort if no sysdeps are available (since sugar-jhbuild will break in unexpected ways otherwise) * cache distribution information and dependency list to speed up execution --- diff --git a/sjhbuild/config.py b/sjhbuild/config.py index 321669c..d209a29 100644 --- a/sjhbuild/config.py +++ b/sjhbuild/config.py @@ -17,8 +17,13 @@ class Config(jhbuild.config.Config): self.checkoutroot = os.path.join(self.base_dir, 'source') self.tarballdir = os.path.join(self.base_dir, 'source') - - for package, source in sysdeps.get_packages(): + + deps = sysdeps.get_packages() + if not deps: + sys.stderr.write("ERROR: Dependencies information is missing (unknown distribution/version).\n") + sys.exit(126) + + for package, source in deps : if source and source not in self.skip: self.skip.append(source) diff --git a/sjhbuild/depscheck.py b/sjhbuild/depscheck.py index f55f19e..f68a31a 100644 --- a/sjhbuild/depscheck.py +++ b/sjhbuild/depscheck.py @@ -20,10 +20,6 @@ class cmd_depscheck(Command): def run(self, config, options, args): deps = sysdeps.get_packages() - if not options.script and not deps: - print 'Dependencies information is missing, skip sanity check.' - return - missing_deps = [] for package, source in deps: if not sysdeps.check_package(package): diff --git a/sjhbuild/sysdeps.py b/sjhbuild/sysdeps.py index cd92253..bd10b73 100644 --- a/sjhbuild/sysdeps.py +++ b/sjhbuild/sysdeps.py @@ -1,48 +1,38 @@ +import operator import os import subprocess +import sys from xml.dom import minidom scripts_dir = os.path.dirname(__file__) base_dir = os.path.dirname(scripts_dir) -def get_distribution(): - if 'SJH_DISTRIBUTION' in os.environ: - return os.environ['SJH_DISTRIBUTION'].split('-') +_cached_dname, _cached_dversion = None, None - # Fedora - if os.path.exists('/etc/fedora-release'): - name = 'fedora' +def _pipe_lower(args) : + out, err = subprocess.Popen(args, + stdout=subprocess.PIPE).communicate() + return out.strip().lower() - f = open('/etc/fedora-release') - full_name = f.read() - f.close() +def get_distribution(): + global _cached_dname, _cached_dversion - if 'Rawhide' in full_name: - version = 'rawhide' - else: - version = full_name.split(' ')[2] + if _cached_dname : + return _cached_dname, _cached_dversion - return name, version + if 'SJH_DISTRIBUTION' in os.environ: + _cached_dname, _cached_dversion = os.environ['SJH_DISTRIBUTION'].split('-') + return _cached_dname, _cached_dversion - # Debian and Ubuntu try: - out, err = subprocess.Popen(['lsb_release', '-is'], - stdout=subprocess.PIPE).communicate() - name = out.strip().lower() + _cached_dname = _pipe_lower(['lsb_release', '-is']) + _cached_dversion = _pipe_lower(['lsb_release', '-rs']) - out, err = subprocess.Popen(['lsb_release', '-rs'], - stdout=subprocess.PIPE).communicate() - version = out.strip() - - if name == 'debian' and version == 'testing': - version = 'unstable' - - return name, version except OSError: pass - return None, None + return _cached_dname, _cached_dversion def check_package(package): name, version = get_distribution() @@ -56,28 +46,60 @@ def check_package(package): return None -def parse_dependencies(): - name, version = get_distribution() - if name is None or version is None: - return None +def _check_prefix(name, prefixes, suffix="") : + return [name for p in prefixes if name.startswith(p) and name.endswith(suffix)] + +_unstable_names = { + 'debian': 'unstable', + 'fedora': 'rawhide', + 'mandrivalinux': 'cooker', + 'ubuntu': 'unstable', +} +def _parse_dependencies(dname, dversion): + if not (dname and dversion): + return [] - filename = os.path.join(base_dir, 'config', 'sysdeps', - '%s-%s.xml' % (name, version)) + prefixes = ['alldistros', '%s-allversions' % (dname,), + '%s-%s' % (dname, dversion)] - if not os.path.exists(filename): - return None + dirname = os.path.join(base_dir, 'config', 'sysdeps') + filenames = [os.path.join(dirname, fname) + for fname in os.listdir(dirname) + if _check_prefix(fname, prefixes, ".xml")] - return minidom.parse(filename) + # check whether we have a file matching the exact distro version + if not [name for name in filenames if prefixes[-1] in name] : + # will break for unknown distros, but that's fine + # (=> bug report => add support for distro) + uversion = _unstable_names[dname] + if (dversion == uversion) : + # no config for unstable + return [] + sys.stderr.write("Warning: unknown distro version, automatic fallback to %s.\n" % (uversion,)) + return _parse_dependencies(dname, uversion) + + + return [minidom.parse(fname) + for fname in filenames if os.path.exists(fname)] + +_cached_packages = None def get_packages(): - document = parse_dependencies() - if document is None: - return [] + global _cached_packages + + if _cached_packages is not None : + return _cached_packages + + dname, dversion = get_distribution() + documents = _parse_dependencies(dname, dversion) + _cached_packages = [] + + if not documents : + return _cached_packages - packages = [] - root = document.childNodes[0] + roots = [doc.childNodes[0] for doc in documents] - for node in root.childNodes: + for node in reduce(operator.add, [root.childNodes for root in roots]) : if node.nodeType == node.ELEMENT_NODE: if node.nodeName == 'package': name = node.getAttribute('name') @@ -86,6 +108,6 @@ def get_packages(): else: source = None - packages.append((name, source)) + _cached_packages.append((name, source)) - return packages + return _cached_packages -- cgit v0.9.1