[csw-devel] SF.net SVN: gar:[20798] csw/mgar/gar/v2

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Thu Apr 18 17:17:52 CEST 2013


Revision: 20798
          http://gar.svn.sourceforge.net/gar/?rev=20798&view=rev
Author:   wahwah
Date:     2013-04-18 15:17:52 +0000 (Thu, 18 Apr 2013)
Log Message:
-----------
checkpkg: Switch from hachoir_parser to pyelftools

It's a more lightweight library. It turns out that we only need to identify
architectures of binary files.

Modified Paths:
--------------
    csw/mgar/gar/v2/gar.conf.mk
    csw/mgar/gar/v2/lib/python/README
    csw/mgar/gar/v2/lib/python/inspective_package.py

Modified: csw/mgar/gar/v2/gar.conf.mk
===================================================================
--- csw/mgar/gar/v2/gar.conf.mk	2013-04-18 15:17:33 UTC (rev 20797)
+++ csw/mgar/gar/v2/gar.conf.mk	2013-04-18 15:17:52 UTC (rev 20798)
@@ -201,10 +201,9 @@
 DEF_BASE_PKGS += CSWpy-cheetah
 DEF_BASE_PKGS += CSWpy-cjson
 DEF_BASE_PKGS += CSWpy-dateutil
-DEF_BASE_PKGS += CSWpy-hachoir-core
-DEF_BASE_PKGS += CSWpy-hachoir-parser
 DEF_BASE_PKGS += CSWpy-libmagic
 DEF_BASE_PKGS += CSWpy-progressbar
+DEF_BASE_PKGS += CSWpy-pyelftools
 DEF_BASE_PKGS += CSWpy-sqlobject
 DEF_BASE_PKGS += CSWpy-yaml
 DEF_BASE_PKGS += CSWpython

Modified: csw/mgar/gar/v2/lib/python/README
===================================================================
--- csw/mgar/gar/v2/lib/python/README	2013-04-18 15:17:33 UTC (rev 20797)
+++ csw/mgar/gar/v2/lib/python/README	2013-04-18 15:17:52 UTC (rev 20798)
@@ -65,7 +65,6 @@
 
 Known problems:
 - libmagic fails sometimes when processing the whole catalog
-- hachoir_parser fails sometimes on i386 packages when examining them on sparc
 
 Package dependencies:
 
@@ -76,7 +75,6 @@
 sudo aptitude install \
   python-mysql \
   python-cheetah \
-  python-hachoir-parser \
   python-magic \
   python-mox \
   python-progressbar \
@@ -85,24 +83,26 @@
   python-unittest2 \
   python-yaml
 
+Seem unpackaged: elftools from
+http://eli.thegreenplace.net/2012/01/06/pyelftools-python-library-for-parsing-elf-and-dwarf/
+
 Solaris package dependencies.
 
-CSWpy-unittest2
+CSWpy-cheetah
 CSWpy-curl
 CSWpy-libmagic
-CSWpy-sqlobject
-CSWpy-cheetah
 CSWpy-mox
 CSWpy-mysql
 CSWpy-progressbar
+CSWpy-pyelftools
+CSWpy-sqlobject
+CSWpy-unittest2
 
 For pkgdb-web
 
 CSWapache2
-CSWap2modpython
-modpython_gateway (together with pkgdb_web.py in the same dir)
+CSWap2-modwsgi
 
-
 ===Checkpkg database===
 
 Additional database indexes:

Modified: csw/mgar/gar/v2/lib/python/inspective_package.py
===================================================================
--- csw/mgar/gar/v2/lib/python/inspective_package.py	2013-04-18 15:17:33 UTC (rev 20797)
+++ csw/mgar/gar/v2/lib/python/inspective_package.py	2013-04-18 15:17:52 UTC (rev 20798)
@@ -1,3 +1,5 @@
+"""This file isolates code dependent on elftools."""
+
 import package
 import os
 import re
@@ -3,5 +5,4 @@
 import sys
 import logging
-import hachoir_parser
 import sharedlib_utils
 import magic
@@ -13,17 +14,9 @@
 import time
 import shell
 
-"""This file isolates code dependent on hachoir parser.
+from elftools.elf.elffile import ELFFile
+from elftools.elf.enums import ENUM_E_MACHINE
 
-hachoir parser takes quite a while to import.
-"""
-
-# Suppress unhelpful warnings
-# http://bitbucket.org/haypo/hachoir/issue/23
-import hachoir_core.config
-hachoir_core.config.quiet = True
-
-
 ROOT_RE = re.compile(r"^(reloc|root)/")
 
 
@@ -61,26 +54,9 @@
     else:
       raise package.PackageError(msg)
   if sharedlib_utils.IsBinary(file_info, check_consistency=False):
-    parser_tag = ('class', hachoir_parser.program.elf.ElfFile)
-    parser = hachoir_parser.createParser(full_path, tags=[parser_tag])
-    if not parser:
-      logging.warning("Can't parse file %s", file_path)
-    else:
-      try:
-        machine_id = parser["/header/machine"].value
-      except hachoir_core.field.field.MissingField, e:
-        logging.fatal(
-            "hachoir_parser failed to retrieve machine_id for %r. "
-            "checkpkg cannot continue.",
-            file_info)
-        raise
-      try:
-        file_info["mime_type_by_hachoir"] = parser.mime_type
-        file_info["machine_id"] = machine_id
-        file_info["endian"] = parser["/header/endian"].display
-      except hachoir_core.field.field.MissingField, e:
-        logging.warning(
-            "Error in hachoir_parser processing %s: %r", file_path, e)
+    with open(full_path, 'rb') as elf_fd:
+      elffile = ELFFile(elf_fd)
+      file_info["machine_id"] = ENUM_E_MACHINE[elffile.header['e_machine']]
   return file_info
 
 class InspectivePackage(package.DirectoryFormatPackage):

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