From b347dded12e60c3a1d72ba1389333150d0c6b620 Mon Sep 17 00:00:00 2001
From: Yann Rouillard <yann@pleiades.fr.eu.org>
Date: Fri, 3 May 2013 00:38:29 +0200
Subject: [PATCH] use list instead of dict to store symbols information


Signed-off-by: Yann Rouillard <yann@pleiades.fr.eu.org>
---
 lib/python/common_constants.py   |  9 +++++++++
 lib/python/dependency_checks.py  |  7 ++++---
 lib/python/inspective_package.py | 31 ++++++++++++++++++++-----------
 lib/python/models.py             |  4 ++--
 lib/python/package_stats.py      |  4 +---
 5 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/lib/python/common_constants.py b/lib/python/common_constants.py
index a81551d..c837db3 100644
--- a/lib/python/common_constants.py
+++ b/lib/python/common_constants.py
@@ -197,3 +197,12 @@ MACHINE_ID_METADATA = {
                        SPARCV9_PATHS,
         },
 }
+
+
+class SYMBOL_INFO(object):
+  BIND=0
+  FLAGS=1
+  SHNDX=2
+  SONAME=3
+  SYMBOL=4
+  VERSION=5
diff --git a/lib/python/dependency_checks.py b/lib/python/dependency_checks.py
index 0e71ed4..4dd39d3 100644
--- a/lib/python/dependency_checks.py
+++ b/lib/python/dependency_checks.py
@@ -6,6 +6,7 @@ import re
 import ldd_emul
 import sharedlib_utils
 import common_constants
+from common_constants import SYMBOL_INFO
 import operator
 import logging
 
@@ -209,9 +210,9 @@ def Libraries(pkg_data, error_mgr, logger, messenger, path_and_pkg_by_basename,
 
     db_libs = set()
     for syminfo in binary_elf_info['symbol table']:
-      if (syminfo['shndx'] == 'UNDEF' and syminfo['flags']
-          and 'D' in syminfo['flags'] and 'B' in syminfo['flags']):
-          db_libs.add(syminfo['soname'])
+      if (syminfo[SYMBOL_INFO.SHNDX] == 'UNDEF' and syminfo[SYMBOL_INFO.FLAGS]
+          and 'D' in syminfo[SYMBOL_INFO.FLAGS] and 'B' in syminfo[SYMBOL_INFO.FLAGS]):
+          db_libs.add(syminfo[SYMBOL_INFO.SONAME])
     no_db_libs = libs.difference(db_libs)
 
     # no symbol used means no way to detect if direct binding was
diff --git a/lib/python/inspective_package.py b/lib/python/inspective_package.py
index 1af9892..c8e78ad 100644
--- a/lib/python/inspective_package.py
+++ b/lib/python/inspective_package.py
@@ -10,6 +10,7 @@ import sys
 import time
 
 import common_constants
+from common_constants import SYMBOL_INFO
 import configuration as c
 import ldd_emul
 import package
@@ -21,6 +22,14 @@ from elftools.elf.enums import ENUM_E_MACHINE
 
 ROOT_RE = re.compile(r"^(reloc|root)/")
 
+SYMBOL_INFO_INDEX = {
+ 'bind': SYMBOL_INFO.BIND,
+ 'flags': SYMBOL_INFO.FLAGS,
+ 'shndx': SYMBOL_INFO.SHNDX,
+ 'soname': SYMBOL_INFO.SONAME,
+ 'symbol': SYMBOL_INFO.SYMBOL,
+ 'version': SYMBOL_INFO.VERSION,
+}
 
 def StripRe(x, strip_re):
   return re.sub(strip_re, "", x)
@@ -303,10 +312,15 @@ class InspectivePackage(package.DirectoryFormatPackage):
       # symbol table and syminfo section store various informations
       # about the same symbols, so we merge them in a dict
       if cur_section in ('symbol table', 'syminfo'):
-        symbols.setdefault(elf_info['symbol'], {}).update(elf_info)
+        symbol = symbols.setdefault(elf_info['symbol'], [None]*6)
+        for info in elf_info:
+          if info in SYMBOL_INFO_INDEX:
+            symbol[SYMBOL_INFO_INDEX[info]] = elf_info[info]
       else:
         binary_info[cur_section].append(elf_info)
 
+
+
     # elfdump doesn't repeat the name of the soname in the version section
     # if it's the same on two contiguous line, e.g.:
     #         libc.so.1            SUNW_1.1
@@ -330,7 +344,7 @@ class InspectivePackage(package.DirectoryFormatPackage):
       binary_info['version definition'].pop(0)
 
     binary_info['symbol table'] = symbols.values()
-    binary_info['symbol table'].sort(key=lambda m: m['symbol'])
+    binary_info['symbol table'].sort(key=lambda m: m[SYMBOL_INFO.SYMBOL])
     # To not rely of the section order output of elfdump, we resolve
     # symbol version informations here after having parsed all output
     self._ResolveSymbolsVersionInfo(binary_info)
@@ -417,19 +431,14 @@ class InspectivePackage(package.DirectoryFormatPackage):
       #  0 is for external symbol with no version information available
       #  1 is for a symbol defined by the binary and not binded
       #    to a version interface
-      version_index = int(sym_info['version']) - 2
+      version_index = int(sym_info[SYMBOL_INFO.VERSION]) - 2
       if version_index >= 0:
         version = version_info[version_index]
-        sym_info['version'] = version['version']
+        sym_info[SYMBOL_INFO.VERSION] = version['version']
         if 'soname' in version:
-          sym_info['soname'] = version['soname']
+          sym_info[SYMBOL_INFO.SONAME] = version['soname']
       else:
-        sym_info['version'] = None
-
-      # we make sure these fields are present
-      # even if the syminfo section is not
-      sym_info.setdefault('soname')
-      sym_info.setdefault('flags')
+        sym_info[SYMBOL_INFO.VERSION] = None
 
   elfdump_headers_re = (
       r"""
diff --git a/lib/python/models.py b/lib/python/models.py
index 34db595..ddb4fc2 100644
--- a/lib/python/models.py
+++ b/lib/python/models.py
@@ -104,8 +104,8 @@ class CswConfig(sqlobject.SQLObject):
 
 
 class Pkginst(sqlobject.SQLObject):
-  pkgname = sqlobject.UnicodeCol(length=50, unique=True, notNone=True)
-  catalogname = sqlobject.UnicodeCol(default=None, length=50)
+  pkgname = sqlobject.UnicodeCol(length=250, unique=True, notNone=True)
+  catalogname = sqlobject.UnicodeCol(default=None, length=250)
   pkg_desc = sqlobject.UnicodeCol(default=None, length=250)
   srv4_files = sqlobject.MultipleJoin('Srv4FileStats')
 
diff --git a/lib/python/package_stats.py b/lib/python/package_stats.py
index 9d06493..c74c25c 100644
--- a/lib/python/package_stats.py
+++ b/lib/python/package_stats.py
@@ -230,9 +230,7 @@ class PackageStats(object):
     }
 
     # TODO(maciej): ldd info is too big, it needs to be split up.
-    if False:
-      self.rest_client.SaveBlob('ldd', basic_stats['md5_sum'],
-                                dir_pkg.GetLddMinusRlines())
+    if True:
       # Saving of the elfdump data takes place inside the dir_pkg class.
       bins_and_md5_sums = dir_pkg.CollectAndSavePackageElfinfo(self.rest_client)
       pkg_stats["binaries_md5_sums"] = bins_and_md5_sums
-- 
1.8.1.4

