gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r17895 - in gnunet-update: doc gnunet_update


From: gnunet
Subject: [GNUnet-SVN] r17895 - in gnunet-update: doc gnunet_update
Date: Tue, 1 Nov 2011 22:19:52 +0100

Author: harsha
Date: 2011-11-01 22:19:52 +0100 (Tue, 01 Nov 2011)
New Revision: 17895

Added:
   gnunet-update/gnunet_update/util.py
Modified:
   gnunet-update/doc/metadata.txt
   gnunet-update/gnunet_update/install.py
   gnunet-update/gnunet_update/metadata.py
   gnunet-update/gnunet_update/package.py
Log:
ldconfig output parsing

Modified: gnunet-update/doc/metadata.txt
===================================================================
--- gnunet-update/doc/metadata.txt      2011-11-01 18:30:36 UTC (rev 17894)
+++ gnunet-update/doc/metadata.txt      2011-11-01 21:19:52 UTC (rev 17895)
@@ -2,52 +2,54 @@
 Author:   Sree Harsha Totakura
 
 * Metadata file:
-  The metadata file consists of sections seperated by a line
-  containing `%%'. Currently there are 3 sections:
-  1. The metadata header which consists of information about the host
-     (the machine on which the package was built)
+
+  The metadata file consists of sections seperated by a line containing
+  `%%'. Currently there are 3 sections:
+
+  1. The metadata header which consists of information about the host (the
+     machine on which the package was built)
   2. The metadata body which is a list of the dependencies of binary objects in
-     the package 
+     the package
   3. A list of signatures of the binary objects to verify the authenticity of
-     each binary object in the package 
+     each binary object in the package
 
-  IMPORTANT: The lists in  metadata body and signatures should correspond to
+  IMPORTANT: The lists in metadata body and signatures should correspond to
   each other. For every object listed in metadata body, there should be a
   signature associated with that file in signature list
 
-** Metadata header
-   It consists of information about the host system. This is needed to
-   identify the subset of machine which have the capability to execute
-   the binary objects in the package.
+** Metadata header 
 
-   The header consists of KEY:VALUE pairs with one such pair in each
-   line.
+   It consists of information about the host system. This is needed to identify
+   the subset of machin e which have the capability to execute the binary
+   objects in the package.
 
+   The header consists of KEY:VALUE pairs with one such pair in each line.
+
    The valid KEYs are:
-    * MACHINE: 
-      Host machine type. e.g: i386
-    * OS: 
-      Host operating system. e.g: Linux
-    * PKEY: 
-      Public key of the host in hexadecimal digits
-    * RELEASE: 
-      Release number for the package. This is independent of
-      Gnunet release and is intended for packagers and maintainers to
-      identify their own release information
+    * MACHINE: Host machine type. e.g: i386
+    * OS: Host operating system. e.g: Linux
+    * PKEY: Public key of the host in hexadecimal digits
+    * RELEASE: Release number for the package. This is independent of Gnunet
+      release and is intended for packagers and maintainers to identify their
+      own release information
 
 ** Metadata body
+
    This is a list of dependencies for each binary object. 
 
-   If a binary object foo needs a shared library libbar.so.X where X
-   is the major number for libbar, the dependency information for A is
-   stored as follows:
+   If a binary object foo needs a shared library libbar.so.X where X is the
+   major number for libbar, the dependency information for A is stored as
+   follows:
+
       A;libbar.so.X;X;Y;Z
-   where Y, Z are the minor and revision numbers of libbar.so.X. In
-   case minor and revision numbers for libbar cannot be determined,
-   they are set to -1
 
+   where Y, Z are the minor and revision numbers of libbar.so.X. In case minor
+   and revision numbers for libbar cannot be determined, they are set to -1
+
 ** List of signatures
-   This is a list of sha512 digest of each file in the package
-   expressed in hexadecimal format. For each file an entry begins with
-   its file name followed by a `:' and then the sha512 digest.
+
+   This is a list of sha512 digest of each file in the package expressed in
+   hexadecimal format. For each file an entry begins with its file name
+   followed by a `:' and then the sha512 digest.
+
       file_name: sha512 digest of the file

Modified: gnunet-update/gnunet_update/install.py
===================================================================
--- gnunet-update/gnunet_update/install.py      2011-11-01 18:30:36 UTC (rev 
17894)
+++ gnunet-update/gnunet_update/install.py      2011-11-01 21:19:52 UTC (rev 
17895)
@@ -32,8 +32,13 @@
 import os
 import getopt
 import platform
+import subprocess
+
+import util
 from metadata import Metadata
+from dependency import Dependency
 
+
 def usage():
     """Print helpful usage information."""    
     print """
@@ -45,6 +50,17 @@
     -h, --help        : prints this message
 """
 
+def get_installed_deps():
+    """Finds from `ldconfig -v' the installed deps."""
+    global installed_deps
+    proc = subprocess.Popen(["ldconfig", "-p"], stdout=subprocess.PIPE)
+    (ldconfig_output, ldconfig_err) = proc.communicate()
+    proc.stdout.close()
+    parsed_dep_list = util.parse_ldconfig_output(ldconfig_output)
+    def create_dependency(parsed_dep_line):
+        return Dependency(parsed_dep_line[0], parsed_dep_line[-1])
+    return map(create_dependency, parsed_dep_list)
+
 def main():
     """Execution start point."""
     try:
@@ -66,7 +82,7 @@
         sys.exit(1)
     
     metadata = Metadata()
-    metadata.readfromfile(args[0])
+    metadata.read_from_file(args[0])
     package_tarfile = tarfile.open(args[1],'r')
     install_dir = args[2]
     
@@ -92,11 +108,29 @@
     except OSError:             # Given directory not present 
         os.mkdir(install_dir, 0755)
     
+    installed_deps = get_installed_deps()    # already available dependencies
+    new_binary_objects = metadata.get_binary_objects() # To be installed 
objects
+    installed_deps.sort(key=(lambda dep: dep.name))
+
+    needed_deps = list()
+    for binary_object in new_binary_objects:
+        for dep in binary_object.get_dependencies():
+            if dep not in needed_deps:
+                needed_deps.append(dep)
+    # TODO: Find the dependencies to be installed
+
+    for dep in installed_deps:
+        print "%s -- %s" % (dep.name, dep.path)
+
     #FIXME: Security warning! Perhaps we should examin the contents of tarfile
     #before extracting
     for member in package_tarfile.getmembers():
-        if "metadata.dat" == member.name:
+        if ("metadata.dat" == member.name or "install-prefix" == member.name 
or 
+                 member.name.startswith("dependencies/")):
             continue
+        elif member.name.startswith("install-prefix"):
+            # Remove the `install-prefix' directory
+            member.name = member.name.replace("install-prefix/","",1)
         package_tarfile.extract(member, install_dir)
         
     package_tarfile.close()

Modified: gnunet-update/gnunet_update/metadata.py
===================================================================
--- gnunet-update/gnunet_update/metadata.py     2011-11-01 18:30:36 UTC (rev 
17894)
+++ gnunet-update/gnunet_update/metadata.py     2011-11-01 21:19:52 UTC (rev 
17895)
@@ -39,15 +39,15 @@
         self.pkey = pkey
         self.release = release
 
-    def setbinaryobjects(self, binary_objects):
+    def set_binary_objects(self, binary_objects):
         """Setter for _binary_objects."""
         self._binary_objects = binary_objects
 
-    def getbinaryobjects(self):
+    def get_binary_objects(self):
         """Getter for binary_objects."""
         return self._binary_objects
 
-    def writetofile(self, path=None):
+    def write_to_file(self, path=None):
         """Saves metadata to a file and returns the path of that file.
         
         path is a string representing the path of the file to be
@@ -93,7 +93,7 @@
 
         return file_name
         
-    def readfromfile(self, path):
+    def read_from_file(self, path):
         """Reads metadata from the file at path."""
         f = open(path, "rb") # binary for compatibility
 

Modified: gnunet-update/gnunet_update/package.py
===================================================================
--- gnunet-update/gnunet_update/package.py      2011-11-01 18:30:36 UTC (rev 
17894)
+++ gnunet-update/gnunet_update/package.py      2011-11-01 21:19:52 UTC (rev 
17895)
@@ -36,6 +36,8 @@
 import tempfile
 import tarfile
 import platform
+
+import util
 from dependency import Dependency, BinaryObject
 from metadata import Metadata
 
@@ -110,16 +112,6 @@
     if 0 != proc.wait():
         print "Failed while installing the compiled binaries."
         sys.exit(1)
-        
-def strip(str):
-    """ helper function to strip any trailing characters."""
-    return str.strip()
-
-def extract_deps(ldd_line):
-    """ extracts the path of the dependency from ldd's output line."""
-    tokens = map (strip, ldd_line.split(' => '))
-    tokens[-1] = tokens[-1].rsplit(' ', 1)[0]
-    return tokens
     
 def get_deps(install_dir):
     """Extract dependencies from ldd output."""
@@ -134,7 +126,7 @@
                 continue
             
             proc = subprocess.Popen(["ldd", file_path],
-                                    bufsize = -1, stdout = subprocess.PIPE)
+                                    bufsize=-1, stdout=subprocess.PIPE)
             (proc_stdout, proc_stderr) = proc.communicate()
             proc.stdout.close()
             if 0 != proc.returncode:
@@ -143,7 +135,7 @@
             bin_object = BinaryObject(file_path, 
                                       root[len(install_dir) + 1:] + '/' + file 
)
             
-            for dep_data in map (extract_deps, proc_stdout.splitlines()):
+            for dep_data in util.parse_ldd_output(proc_stdout):
                 #we cannot find a library without its location
                 if dep_data[-1][0] == '(':
                     continue
@@ -198,14 +190,14 @@
     metadata = Metadata(machine=platform.machine(),
                         os=platform.system(),
                         release="0")                       
-    metadata.setbinaryobjects(binary_objects)
+    metadata.set_binary_objects(binary_objects)
 
     #package the installed files
     tar_file = tarfile.open(package_file + ".tgz", 'w:gz')
     tar_file.add(install_prefix, "install-prefix")
     
     #generate the metadata file and add it to tar
-    metadata_file = metadata.writetofile(package_file + ".meta")
+    metadata_file = metadata.write_to_file(package_file + ".meta")
     tar_file.add(metadata_file, "metadata.dat")
     
     print "Here are the dependencies:"

Added: gnunet-update/gnunet_update/util.py
===================================================================
--- gnunet-update/gnunet_update/util.py                         (rev 0)
+++ gnunet-update/gnunet_update/util.py 2011-11-01 21:19:52 UTC (rev 17895)
@@ -0,0 +1,59 @@
+# This file is part of GNUnet.
+# (C) 2001--2011 Christian Grothoff (and other contributing authors)
+#
+# GNUnet is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+#
+# GNUnet is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNUnet; see the file COPYING.  If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+# 
+# File:    gnunet_update/util.py
+# Author:  Sree Harsha Totakura
+# 
+# Utility function library
+
+def parse_ldd_output(ldd_output):
+    """Parses ldd output.
+
+    ldd_ouput : Output of `ldd <program>' to identify dependencies
+
+    Returns a list of 2 element lists having the dependency name as the first
+    element and the path of the dependency as the second one
+    """
+    def strip(str):            # helper function for stripping white spaces
+        return str.strip()
+
+    # extracts the path of the dependency from ldd's output line
+    def extract_deps(ldd_line):
+        tokens = map (strip, ldd_line.split(' => '))
+        tokens[-1] = tokens[-1].rsplit(' ', 1)[0]
+        return tokens
+
+    return map(extract_deps, ldd_output.splitlines())
+
+def parse_ldconfig_output(ldconfig_output):
+    """Parses ldconfig output.
+
+    ldconfig_output : Output of `ldconfig -p' to indentify installed/existing
+                      dependencies 
+
+    Returns a list of 2 element lists having the dependency name as the first
+    element and the path of the dependency as the second 
+    """
+    # Parsing is allmost similar to parsing of ldd output except that we have
+    # something extra associated with the name of the dependency. Here we just
+    # need to clean that off 
+    def massage_head(dep_data):
+        dep_data[0] = dep_data[0].split(' ')[0] # take the first part
+        return dep_data
+
+    return map(massage_head, parse_ldd_output(ldconfig_output))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]