[Piuparts-commits] [SCM] piuparts git repository branch, piatti, updated. 0.49-113-g2c98b1d
Andreas Beckmann
anbe at debian.org
Sun Mar 3 09:14:06 UTC 2013
The following commit has been merged in the piatti branch:
commit 4f8739a89a1b186464756c3654e01dfbd349bc41
Author: Andreas Beckmann <anbe at debian.org>
Date: Sat Mar 2 12:43:57 2013 +0100
lib/conf: add class DistroConfig
for reading distros.conf
Signed-off-by: Andreas Beckmann <anbe at debian.org>
diff --git a/debian/changelog b/debian/changelog
index 0a8ee53..6441ff6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -26,6 +26,7 @@ piuparts (0.50) UNRELEASED; urgency=low
squeeze-backports, experimental) along with their dependencies (e.g. base
distribution) and non-default mirrors. Shipped in package piuparts-common.
* piupartslib/conf.py:
+ - Add class DistroConfig for reading distros.conf.
* piupartslib/packagesdb.py:
- Add Package.waiting_count() and friends, populated in calc_rrdep_count.
- Optimize reserve() and skip unavailable candidates.
diff --git a/piupartslib/conf.py b/piupartslib/conf.py
index cbf92c8..0bdd1ec 100644
--- a/piupartslib/conf.py
+++ b/piupartslib/conf.py
@@ -98,4 +98,78 @@ class Config(UserDict.UserDict):
return "%s/dists/%s/%s/source/Sources.bz2" % \
(self.get_mirror(self.get_distro()), self.get_distro(), self.get_area())
+
+class DistroConfig(UserDict.UserDict):
+
+ def __init__(self, filename, mirror):
+ UserDict.UserDict.__init__(self)
+ self._mirror = mirror
+ self._defaults = {
+ "uri": None,
+ "distribution": None,
+ "components": None,
+ "depends": None,
+ }
+ cp = ConfigParser.SafeConfigParser()
+ cp.read(filename)
+ for section in cp.sections():
+ self[section] = dict(self._defaults)
+ for key in self._defaults.keys():
+ if cp.has_option(section, key):
+ self[section][key] = cp.get(section, key)
+
+ def get(self, section, key=None):
+ if not section in self.keys():
+ self[section] = dict(self._defaults, distribution=section)
+ if not key is None:
+ return self[section][key]
+ return self[section]
+
+ def get_mirror(self, distro):
+ return self.get(distro, "uri") or self._mirror
+
+ def get_distribution(self, distro):
+ return self.get(distro, "distribution") or distro
+
+ def get_packages_url(self, distro, area, arch):
+ return "%s/dists/%s/%s/binary-%s/Packages.bz2" % (
+ self.get_mirror(distro),
+ self.get_distribution(distro),
+ area, arch)
+
+ def get_sources_url(self, distro, area):
+ return "%s/dists/%s/%s/source/Sources.bz2" % (
+ self.get_mirror(distro),
+ self.get_distribution(distro),
+ area)
+
+ def _expand_depends(self, distro):
+ todo = [distro]
+ done = []
+ seen = []
+ while todo:
+ curr = todo[0]
+ todo = todo[1:]
+ if not curr in seen:
+ seen.append(curr)
+ todo = done + (self.get(curr, "depends") or "").split() + [ curr ] + todo
+ done = []
+ elif not curr in done:
+ done.append(curr)
+ return done
+
+ def get_deb_lines(self, distro, components):
+ lines = []
+ for d in self._expand_depends(distro):
+ if not self[d]["uri"] is None and self[d]["uri"] == "None":
+ next # skip virtual section
+ for c in components:
+ if self[d]["components"] is None or c in self[d]["components"].split():
+ lines.append("deb %s %s %s" % (
+ self.get_mirror(d),
+ self.get_distribution(d),
+ c))
+ return lines
+
+
# vi:set et ts=4 sw=4 :
--
piuparts git repository
More information about the Piuparts-commits
mailing list