[csw-devel] SF.net SVN: gar:[8218] csw/mgar/gar/v2/lib/python
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Fri Jan 29 12:01:35 CET 2010
Revision: 8218
http://gar.svn.sourceforge.net/gar/?rev=8218&view=rev
Author: wahwah
Date: 2010-01-29 11:01:35 +0000 (Fri, 29 Jan 2010)
Log Message:
-----------
mGAR v2: Enhancements for the Pkgmap class; added more fields and indexes.
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/opencsw.py
csw/mgar/gar/v2/lib/python/opencsw_test.py
Modified: csw/mgar/gar/v2/lib/python/opencsw.py
===================================================================
--- csw/mgar/gar/v2/lib/python/opencsw.py 2010-01-29 09:18:43 UTC (rev 8217)
+++ csw/mgar/gar/v2/lib/python/opencsw.py 2010-01-29 11:01:35 UTC (rev 8218)
@@ -112,6 +112,19 @@
return version_str, version_info, revision_info
+def IndexDictsBy(list_of_dicts, field_key):
+ """Creates an index of list of dictionaries by a field name.
+
+ Returns a dictionary of lists.
+ """
+ index = {}
+ for d in list_of_dicts:
+ if d[field_key] not in index:
+ index[d[field_key]] = []
+ index[d[field_key]].append(d)
+ return index
+
+
class CatalogBasedOpencswPackage(object):
catalog_downloaded = False
@@ -643,7 +656,17 @@
(more fields?)
}, ...
]
+
+ + indexes
"""
+ ENTRY_TYPES = {
+ "1": "header (?)",
+ "d": "directory",
+ "f": "file",
+ "s": "symlink",
+ "l": "link",
+ "i": "script",
+ }
def __init__(self, input, permissions=False,
strip=None):
@@ -660,15 +683,22 @@
line_to_add = None
installed_path = None
prototype_class = None
+ line_type = fields[1]
+ mode = None
+ user = None
+ group = None
if len(fields) < 2:
continue
- elif fields[1] in ('f', 'd'):
+ elif line_type in ('f', 'd'):
+ # Files and directories
line_to_add = fields[3]
installed_path = fields[3]
prototype_class = fields[2]
if self.analyze_permissions:
line_to_add += " %s" % fields[4]
- elif fields[1] in ('s', 'l'):
+ mode, user, group = fields[4:7]
+ elif line_type in ('s', 'l'):
+ # soft- and hardlinks
link_from, link_to = fields[3].split("=")
installed_path = link_from
line_to_add = "%s --> %s" % (link_from, link_to)
@@ -677,18 +707,25 @@
self.paths.add(line_to_add)
entry = {
"line": line,
+ "type": line_type,
}
- if installed_path:
- entry["path"] = installed_path
+ entry["path"] = installed_path
entry["class"] = prototype_class
+ entry["mode"] = mode
+ entry["user"] = user
+ entry["group"] = group
self.entries.append(entry)
+ self.entries_by_line = IndexDictsBy(self.entries, "line")
+ self.entries_by_type = IndexDictsBy(self.entries, "type")
+ self.entries_by_class = IndexDictsBy(self.entries, "class")
+ self.entries_by_path = IndexDictsBy(self.entries, "path")
def GetClasses(self):
"""The assumtion is that the set of classes never changes."""
if not self.classes:
self.classes = set()
for entry in self.entries:
- if entry["class"]:
+ if entry["class"]: # might be None
self.classes.add(entry["class"])
return self.classes
Modified: csw/mgar/gar/v2/lib/python/opencsw_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/opencsw_test.py 2010-01-29 09:18:43 UTC (rev 8217)
+++ csw/mgar/gar/v2/lib/python/opencsw_test.py 2010-01-29 11:01:35 UTC (rev 8218)
@@ -18,6 +18,7 @@
foodoc 1.7.1,REV=2008.10.29 CSWfoodoc foodoc-1.7.1,REV=2008.10.29-SunOS5.8-all-CSW.pkg.gz 0945884a52a3b43b743650c60ac21236 2055045 CSWcommon|CSWxercesj|CSWxmlcommonsext none
bar 1.7.1,REV=2008.10.29 CSWbar bar-1.7.1,REV=2008.10.29-SunOS5.8-all-CSW.pkg.gz 0945884a52a3b43b743650c60ac21236 2055045 CSWcommon|CSWxercesj|CSWxmlcommonsext none
antdoc 1.7.1,REV=2008.10.29 CSWantdoc antdoc-1.7.1,REV=2008.10.29-SunOS5.8-all-CSW.pkg.gz e6555e61e7e7f1740935d970e5efad57 5851724 CSWcommon none"""
+
TEST_PKGINFO="""ARCH=i386
BASEDIR=/
CATEGORY=system
@@ -43,7 +44,23 @@
#FASPACD= none
"""
+PKGMAP_1 = """1 f cswcpsampleconf /etc/opt/csw/cups/cupsd.conf.CSW 0644 root bin 4053 20987 1264420689
+"""
+PKGMAP_2 = """: 1 18128
+1 d none /etc/opt/csw/cups 0755 root bin
+1 f cswcpsampleconf /etc/opt/csw/cups/cupsd.conf.CSW 0644 root bin 4053 20987 1264420689
+1 f none /etc/opt/csw/cups/cupsd.conf.default 0640 root bin 4053 20987 1264420689
+1 d none /etc/opt/csw/cups/interfaces 0755 root bin
+1 d none /etc/opt/csw/cups/ppd 0755 root bin
+1 f cswinitsmf /etc/opt/csw/init.d/cswcups 0555 root bin 4547 14118 1264420798
+1 i depend 122 11155 1264524848
+1 i pkginfo 489 41685 1264524852
+1 i postremove 151 12419 1256302505
+1 i preinstall 1488 45678 125630250
+"""
+
+
class ParsePackageFileNameTest(unittest.TestCase):
def testParsePackageFileName1(self):
@@ -229,5 +246,63 @@
self.assertEqual(set(['bcd', 'hij']), opencsw.LongestCommonSubstring("abcdefghijk", "bcdhij"))
+class PkgmapUnitTest(unittest.TestCase):
+
+ def test_1(self):
+ pkgmap = opencsw.Pkgmap(PKGMAP_1.splitlines())
+ expected = [
+ {
+ 'group': 'bin',
+ 'user': 'root',
+ 'path': '/etc/opt/csw/cups/cupsd.conf.CSW',
+ 'line': '1 f cswcpsampleconf /etc/opt/csw/cups/cupsd.conf.CSW 0644 root bin 4053 20987 1264420689',
+ 'type': 'f',
+ 'class': 'cswcpsampleconf',
+ 'mode': '0644'
+ }
+ ]
+ self.assertEqual(expected, pkgmap.entries)
+
+ def test_2(self):
+ pkgmap = opencsw.Pkgmap(PKGMAP_2.splitlines())
+ line = ": 1 18128"
+ self.assertTrue(line in pkgmap.entries_by_line)
+
+ def test_3(self):
+ pkgmap = opencsw.Pkgmap(PKGMAP_2.splitlines())
+ self.assertTrue("cswcpsampleconf" in pkgmap.entries_by_class)
+
+
+class IndexByUnitTest(unittest.TestCase):
+
+ def testIndexDictsBy_1(self):
+ list_of_dicts = [
+ {"a": 1},
+ {"a": 2},
+ {"a": 3},
+ ]
+ expected = {
+ 1: [{'a': 1}],
+ 2: [{'a': 2}],
+ 3: [{'a': 3}],
+ }
+ self.assertEquals(expected, opencsw.IndexDictsBy(list_of_dicts, "a"))
+
+ def testIndexDictsBy_2(self):
+ list_of_dicts = [
+ {"a": 1, "b": 1},
+ {"a": 1, "b": 2},
+ {"a": 1, "b": 3},
+ ]
+ expected = {
+ 1: [
+ {'a': 1, 'b': 1},
+ {'a': 1, 'b': 2},
+ {'a': 1, 'b': 3},
+ ]
+ }
+ self.assertEquals(expected, opencsw.IndexDictsBy(list_of_dicts, "a"))
+
+
if __name__ == '__main__':
unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list