[csw-devel] SF.net SVN: gar:[18221] csw/mgar/gar/v2-solaris11/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue Jun 5 10:15:42 CEST 2012


Revision: 18221
          http://gar.svn.sourceforge.net/gar/?rev=18221&view=rev
Author:   wahwah
Date:     2012-06-05 08:15:42 +0000 (Tue, 05 Jun 2012)
Log Message:
-----------
checkpkg: Solaris 11 support, unit tests and style

No functional changes or refactoring.

Modified Paths:
--------------
    csw/mgar/gar/v2-solaris11/lib/python/common_constants.py
    csw/mgar/gar/v2-solaris11/lib/python/system_pkgmap.py
    csw/mgar/gar/v2-solaris11/lib/python/system_pkgmap_test.py

Modified: csw/mgar/gar/v2-solaris11/lib/python/common_constants.py
===================================================================
--- csw/mgar/gar/v2-solaris11/lib/python/common_constants.py	2012-06-05 08:13:45 UTC (rev 18220)
+++ csw/mgar/gar/v2-solaris11/lib/python/common_constants.py	2012-06-05 08:15:42 UTC (rev 18221)
@@ -14,8 +14,16 @@
     OS_REL_511,
 )
 OBSOLETE_OS_RELS = (
-    u"SunOS5.8",
+    OS_REL_58,
 )
+SVR4_OS_RELS = (
+    OS_REL_58,
+    OS_REL_59,
+    OS_REL_510,
+)
+IPS_OS_RELS = (
+    OS_REL_511,
+)
 
 SYSTEM_SYMLINKS = (
     ("/opt/csw/bdb4",     ("/opt/csw/bdb42",)),

Modified: csw/mgar/gar/v2-solaris11/lib/python/system_pkgmap.py
===================================================================
--- csw/mgar/gar/v2-solaris11/lib/python/system_pkgmap.py	2012-06-05 08:13:45 UTC (rev 18220)
+++ csw/mgar/gar/v2-solaris11/lib/python/system_pkgmap.py	2012-06-05 08:15:42 UTC (rev 18221)
@@ -123,11 +123,11 @@
 
   def _ParsePkgContentsLine(self, line):
     """Parses one line of "pkg contents" output
-    
-    Returns: A dictionary of fields, or none.
+
+    Returns: A dictionary of fields, or None.
     """
     # we will map from IPS type to SVR4 type
-    type_mapping  = { 'link': 's', 'hardlink': 'l', 'file': 'f', 'dir': 'd' }
+    type_mapping  = { "link": "s", "hardlink": "l", "file": "f", "dir": "d" }
 
     parts = re.split(c.WS_RE, line.strip())
     if len(parts) < 4:
@@ -146,11 +146,11 @@
     f_group = None
     f_pkgname = None
     pkgnames = [ self._IpsNameToSrv4Name(parts[2]) ]
-    if f_type == 's' or f_type == 'l':
+    if f_type in ("s", "l"):
       f_target = parts[3]
     else:
       (f_mode, f_owner, f_group) = parts[3:6]
-    
+
     d = {
         "path": f_path,
         "target": f_target,
@@ -162,11 +162,11 @@
         "line": line,
     }
     return d
-    
+
   def _ParsePkgmapLine(self, line):
     """Parses one line of /var/sadm/install/contents.
 
-    Returns: A dictionary of fields, or none.
+    Returns: A dictionary of fields, or None.
     """
     if line.startswith("#"):
       return None
@@ -267,16 +267,15 @@
     c = itertools.count()
     # Progressbar stuff can go here.
     streams_and_parsers = zip(streams, (self._ParsePkgmapLine, self._ParsePkgContentsLine))
-    for stream_info in streams_and_parsers:
-      parseMethod = stream_info[1]
-      if stream_info[0] == None:
+    for stream_data, ParseMethod in streams_and_parsers:
+      if stream_data is None:
         continue
-      for line in stream_info[0]:
+      for line in stream_data:
         if show_progress:
           if not c.next() % 1000:
             sys.stdout.write(".")
             sys.stdout.flush()
-        d = parseMethod(line)
+        d = ParseMethod(line)
         # d might be None if line was a comment
         if d:
           parsed_lines.append(d)
@@ -305,7 +304,7 @@
 
   def _GetArch(self):
     return self._GetUname("-p")
-  
+
   def GetDataStructure(self, contents_streams, pkginfo_streams, osrel, arch,
                        show_progress=False):
     """Gets the data structure to be pickled.
@@ -338,10 +337,9 @@
 
   def _GetPkgcontentsStreams(self):
     contents_stream = open(self.infile_contents, "r")
-    
-    if self.osrel in ["SunOS5.9", "SunOS5.10"]:
-      pkgcontents_stream = None
-    else: 
+
+    pkgcontents_stream = None
+    if self.osrel in common_constants.IPS_OS_RELS:
       args = ["pkg", "contents", "-H", "-o",
               "path,action.name,pkg.name,target,mode,owner,group",
               "-t", "dir,file,hardlink,link"]
@@ -349,7 +347,7 @@
       stdout, stderr = pkg_proc.communicate()
       ret = pkg_proc.wait()
       pkgcontents_stream = stdout.splitlines()
-    
+
     return (contents_stream, pkgcontents_stream)
 
   def _GetPkginfoStreams(self):
@@ -363,32 +361,40 @@
       ret = pkginfo_proc.wait()
       pkginfo_stream = stdout.splitlines()
 
-    if self.osrel in ["SunOS5.9", "SunOS5.10"]:
-      pkglist_stream = None  
-    else:
+    pkglist_stream = None
+    if self.osrel in common_constants.IPS_OS_RELS:
       args = ["pkg", "list", "-H", "-s"]
       pkg_proc = subprocess.Popen(args, stdout=subprocess.PIPE)
       stdout, stderr = pkg_proc.communicate()
       ret = pkg_proc.wait()
       pkglist_stream = stdout.splitlines()
-     
+
     return (pkginfo_stream, pkglist_stream)
 
   def _ParsePkginfoOutput(self, streams, unused_show_progress):
+    """Parses output from pkginfo.
+
+    Args:
+      streams: A list of two streams of strings, the first one from SVR4
+          pkginfo, the second from IPS
+      unused_show_progress: Used to display a progress bar, which was removed.
+    Returns:
+      A dictionary from pkgnames to descriptions.
+    """
     logging.debug("-> _ParsePkginfoOutput()")
     packages_by_pkgname = {}
     for line in streams[0]:
       pkgname, pkg_desc = self._ParsePkginfoLine(line)
       packages_by_pkgname.setdefault(pkgname, pkg_desc)
-    if streams[1] != None:
+    if streams[1]:
       for line in streams[1]:
         pkgname, pkg_desc = self._ParsePkgListLine(line)
         packages_by_pkgname.setdefault(pkgname, pkg_desc)
     logging.debug("<- _ParsePkginfoOutput()")
     return packages_by_pkgname
-  
+
   def _IpsNameToSrv4Name(self, ips_name):
-    """Create a fake Svr4 pkgname from an ips pkgname"""
+    """Create a fake Svr4 pkgname from an ips pkgname."""
     return "SUNW" + "-".join(re.findall (ALPHANUMERIC_RE, ips_name))
 
 class InstallContentsImporter(object):
@@ -519,6 +525,7 @@
     pbar.maxval = len(contents) / progressbar_divisor
     pbar.start()
     cleaned_pkgs = set()
+    logging.debug("Content leghts: %s", len(contents))
     for d in contents:
       i = count.next()
       if not i % update_period and (i / progressbar_divisor) <= pbar.maxval:
@@ -573,7 +580,7 @@
 
   def ComposeFakeSrv4Md5(self, pkgname, osrel, arch):
     """Returns a fake md5 sum of a fake srv4 package.
- 
+
     For the purposes of fake srv4 packages for SUNW stuff.
     """
     key = pkgname + osrel + arch

Modified: csw/mgar/gar/v2-solaris11/lib/python/system_pkgmap_test.py
===================================================================
--- csw/mgar/gar/v2-solaris11/lib/python/system_pkgmap_test.py	2012-06-05 08:13:45 UTC (rev 18220)
+++ csw/mgar/gar/v2-solaris11/lib/python/system_pkgmap_test.py	2012-06-05 08:15:42 UTC (rev 18221)
@@ -140,14 +140,96 @@
         system_pkgmap.ParsingError,
         spi._ParsePkgmapLine, "/")
 
+  def test_ParsePkgContentsLineLink(self):
+    spi = system_pkgmap.Indexer()
+    line = "bin\tlink\tsystem/core-os\t./usr/bin"
+    expected = {
+        'pkgnames': ['SUNWsystem-core-os'],
+        'group': None,
+        'target': './usr/bin',
+        'owner': None,
+        'path': '/bin',
+        'line': 'bin\tlink\tsystem/core-os\t./usr/bin',
+        'type': 's',
+        'mode': None,
+    }
+    self.assertEquals(
+        expected,
+        spi._ParsePkgContentsLine(line))
+
+  def test_ParsePkgContentsLineDir(self):
+    spi = system_pkgmap.Indexer()
+    line = "dev\tdir\tsystem/core-os\t\t0755\troot\tsys"
+    expected = {
+        'pkgnames': ['SUNWsystem-core-os'],
+        'group': 'sys',
+        'target': None,
+        'owner': 'root',
+        'path': '/dev',
+        'line': 'dev\tdir\tsystem/core-os\t\t0755\troot\tsys',
+        'type': 'd',
+        'mode': '0755',
+    }
+    self.assertEquals(
+        expected,
+        spi._ParsePkgContentsLine(line))
+
+  def test_ParsePkgContentsLineHardlink(self):
+    spi = system_pkgmap.Indexer()
+    line = ("etc/svc/profile/platform_SUNW,UltraSPARC-IIe-NetraCT-40.xml\thardlink\t"
+            "system/core-os\t./platform_SUNW,UltraSPARC-IIi-Netract.xml")
+    expected = {
+        'pkgnames': ['SUNWsystem-core-os'],
+        'group': None,
+        'target': './platform_SUNW,UltraSPARC-IIi-Netract.xml',
+        'owner': None,
+        'path': '/etc/svc/profile/platform_SUNW,UltraSPARC-IIe-NetraCT-40.xml',
+        'line': ('etc/svc/profile/platform_SUNW,UltraSPARC-IIe-NetraCT-40.xml\t'
+                 'hardlink\tsystem/core-os\t'
+                 './platform_SUNW,UltraSPARC-IIi-Netract.xml'),
+        'type': 'l',
+        'mode': None,
+    }
+    self.assertEquals(
+        expected,
+        spi._ParsePkgContentsLine(line))
+
+  def test_ParsePkgContentsLineFile(self):
+    spi = system_pkgmap.Indexer()
+    line = ("lib/libc.so.1\tfile\tsystem/library\t\t0755\troot\tbin")
+    expected = {
+        'pkgnames': ['SUNWsystem-library'],
+        'group': 'bin',
+        'target': None,
+        'owner': 'root',
+        'path': '/lib/libc.so.1',
+        'line': 'lib/libc.so.1\tfile\tsystem/library\t\t0755\troot\tbin',
+        'type': 'f',
+        'mode': '0755',
+    }
+    self.assertEquals(
+        expected,
+        spi._ParsePkgContentsLine(line))
+
+  def test_IpsNameToSrv4Name(self):
+    spi = system_pkgmap.Indexer()
+    self.assertEquals(
+        'SUNWsystem-core-os',
+        spi._IpsNameToSrv4Name("system/core-os"))
+
+
   def test_ParseInstallContents(self):
     spi = system_pkgmap.Indexer()
-    data = (
-        PKGMAP_LINE_1,
-        PKGMAP_LINE_2,
-        PKGMAP_LINE_3,
-        PKGMAP_LINE_4)
-    self.assertEqual(4, len(spi._ParseInstallContents(data, False)))
+    streams = (
+        (
+          PKGMAP_LINE_1,
+          PKGMAP_LINE_2,
+          PKGMAP_LINE_3,
+          PKGMAP_LINE_4
+        ),
+        None
+    )
+    self.assertEqual(4, len(spi._ParseInstallContents(streams, False)))
 
 
 class InstallContentsImporterUnitTest(test_base.SqlObjectTestMixin,

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