[Piuparts-commits] [piuparts] 05/06: conf.py: Add get_std_distro()
Holger Levsen
holger at moszumanska.debian.org
Wed Apr 30 10:24:46 UTC 2014
This is an automated email from the git hooks/post-receive script.
holger pushed a commit to branch develop
in repository piuparts.
commit 2b777818dfcebc8467fd28e9adc1351a84ed11c3
Author: David Steele <dsteele at gmail.com>
Date: Sun Mar 9 21:11:30 2014 -0400
conf.py: Add get_std_distro()
Try to determine the right 'standard' distribution for the section,
either 'oldstable', 'stable', 'testing', 'unstable', or 'experimental',
based on the settings from get_distro() and get_distros().
Returns 'unknown' if undetermined.
The tests used for development are included as test-config.py
This adds a "Depends" for python-distro-info to piuparts-common, as a
new component in conf.py.
---
debian/changelog | 2 ++
debian/control | 1 +
piupartslib/conf.py | 38 +++++++++++++++++++++++
tests/test_config.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 126 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index 3c6a20f..816110d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -28,6 +28,8 @@ piuparts (0.58) UNRELEASED; urgency=low
[ David Steele ]
* piuparts-report.py: Store test summary.json output at the section
and global level, using a new piupartslib/pksummary.py module.
+ The new Config.get_std_distro() provides a standard default distro
+ name for summaries.
(Closes: #740386)
-- Holger Levsen <holger at debian.org> Fri, 14 Feb 2014 14:00:04 +0100
diff --git a/debian/control b/debian/control
index a01c6c7..97f3ee0 100644
--- a/debian/control
+++ b/debian/control
@@ -115,6 +115,7 @@ Package: piuparts-common
Architecture: all
Depends:
python-apt,
+ python-distro-info,
${misc:Depends},
${python:Depends}
Breaks:
diff --git a/piupartslib/conf.py b/piupartslib/conf.py
index 1b18b51..28a5d70 100644
--- a/piupartslib/conf.py
+++ b/piupartslib/conf.py
@@ -27,6 +27,9 @@
import ConfigParser
import UserDict
import subprocess
+import collections
+import re
+import distro_info
class MissingSection(Exception):
@@ -96,6 +99,41 @@ class Config(UserDict.UserDict):
return distros[-1]
return self["distro"]
+ def _get_distmap(self):
+ debdist = distro_info.DebianDistroInfo()
+
+ # start with e.g. "sid" -> "unstable"
+ distmap = collections.defaultdict( lambda : "unknown", [
+ (debdist.old(), "oldstable"),
+ (debdist.devel(), "unstable"),
+ (debdist.stable(), "stable"),
+ (debdist.testing(), "testing"),
+ ("experimental", "experimental"),
+ ("rc", "experimental"),
+ ])
+
+ # add mappings for e.g. "oldstable" -> "oldstable"
+ distmap.update(dict([(val, val) for key, val in distmap.iteritems()]))
+
+ # map e.g. "Debian6" -> "oldstable" where debdist.old(result="fullname")
+ # currently returns 'Debian 6.0 "Squeeze"'
+ dkey = lambda x: "Debian" + re.split('[ \.]', x(result="fullname"))[1]
+ dfuncs = [debdist.old, debdist.stable, debdist.testing]
+ distmap.update(dict([(dkey(x),distmap[x()]) for x in dfuncs]))
+
+ return distmap
+
+ def _map_distro(self, distro):
+ distro_root = re.split("[\-\.]", distro)[0]
+ distmap = self._get_distmap()
+ return distmap[distro_root]
+
+ def get_std_distro(self, distrolist=[]):
+ if not distrolist:
+ distrolist = [self.get_distro()] + self.get_distros()
+ mappedlist = [self._map_distro(x) for x in distrolist]
+ return reduce(lambda x,y: y if y != "unknown" else x, mappedlist)
+
def get_area(self):
if self["area"] is not None:
return self["area"]
diff --git a/tests/test_config.py b/tests/test_config.py
new file mode 100644
index 0000000..e68d8ea
--- /dev/null
+++ b/tests/test_config.py
@@ -0,0 +1,85 @@
+import unittest
+
+import piupartslib.conf as conf
+import distro_info
+
+class ConfStdDistroTests(unittest.TestCase):
+
+ def setUp(self):
+ self.cobj = conf.Config('notimportant', {})
+
+ debdist = distro_info.DebianDistroInfo()
+ self.stable = debdist.stable()
+ self.unstable = debdist.devel()
+ self.oldstable = debdist.old()
+ self.testing = debdist.testing()
+ self.experimental = 'experimental'
+
+
+ def testConfStdDistroNames(self):
+ self.assertEqual(self.oldstable, 'squeeze')
+ self.assertEqual(self.stable, 'wheezy')
+ self.assertEqual(self.testing, 'jessie')
+ self.assertEqual(self.unstable, 'sid')
+ self.assertEqual(self.experimental, 'experimental')
+
+ def testConfMapDistro(self):
+
+ self.assertEqual(self.cobj._map_distro('bogus'), 'unknown')
+
+ self.assertEqual(self.cobj._map_distro(self.oldstable), 'oldstable')
+ self.assertEqual(self.cobj._map_distro(self.stable), 'stable')
+ self.assertEqual(self.cobj._map_distro(self.testing), 'testing')
+ self.assertEqual(self.cobj._map_distro(self.unstable), 'unstable')
+ self.assertEqual(self.cobj._map_distro(self.experimental), 'experimental')
+
+ self.assertEqual(self.cobj._map_distro('oldstable'), 'oldstable')
+ self.assertEqual(self.cobj._map_distro('stable'), 'stable')
+ self.assertEqual(self.cobj._map_distro('testing'), 'testing')
+ self.assertEqual(self.cobj._map_distro('unstable'), 'unstable')
+ self.assertEqual(self.cobj._map_distro('experimental'), 'experimental')
+
+ def testConfMapProposedDistro(self):
+
+ self.assertEqual(
+ self.cobj._map_distro('stable-proposed'), 'stable')
+ self.assertEqual(
+ self.cobj._map_distro(self.stable + '-proposed'), 'stable')
+
+ def testConfMapRemainingDistros(self):
+
+ self.assertEqual(self.cobj._map_distro('rc-buggy'), 'experimental')
+
+ self.assertEqual(
+ self.cobj._map_distro('Debian6.0.9'),
+ self.cobj._map_distro('squeeze'))
+ self.assertEqual(
+ self.cobj._map_distro('Debian7.4'),
+ self.cobj._map_distro('wheezy'))
+ self.assertEqual(
+ self.cobj._map_distro('Debian8'),
+ self.cobj._map_distro('jessie'))
+ self.assertEqual(
+ self.cobj._map_distro('Debian8.1'),
+ self.cobj._map_distro('jessie'))
+
+ def testConfGetStdDistro(self):
+
+ for std in [
+ 'oldstable', 'stable', 'testing', 'unstable', 'experimental']:
+ self.assertEqual(
+ self.cobj.get_std_distro([self.__dict__[std]]), std)
+ self.assertEqual(
+ self.cobj.get_std_distro([self.__dict__[std], 'unknown']), std)
+ self.assertEqual(
+ self.cobj.get_std_distro(['unknown', self.__dict__[std]]), std)
+ self.assertEqual(
+ self.cobj.get_std_distro(
+ ['unknown', 'unknown', self.__dict__[std]]), std)
+ self.assertEqual(
+ self.cobj.get_std_distro(
+ [self.__dict__[std], 'unknown', 'unknown']), std)
+
+ self.assertEqual(self.cobj.get_std_distro(['unknown']), 'unknown')
+ self.assertEqual(
+ self.cobj.get_std_distro(['unknown', 'unknown']), 'unknown')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git
More information about the Piuparts-commits
mailing list