gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r18239 - in gnunet-update: gnunet_update test


From: gnunet
Subject: [GNUnet-SVN] r18239 - in gnunet-update: gnunet_update test
Date: Mon, 21 Nov 2011 18:19:28 +0100

Author: harsha
Date: 2011-11-21 18:19:28 +0100 (Mon, 21 Nov 2011)
New Revision: 18239

Modified:
   gnunet-update/gnunet_update/dependency.py
   gnunet-update/gnunet_update/install.py
   gnunet-update/gnunet_update/metadata.py
   gnunet-update/gnunet_update/package.py
   gnunet-update/gnunet_update/util.py
   gnunet-update/test/test_util.py
Log:
filter needed deps in util

Modified: gnunet-update/gnunet_update/dependency.py
===================================================================
--- gnunet-update/gnunet_update/dependency.py   2011-11-21 16:12:58 UTC (rev 
18238)
+++ gnunet-update/gnunet_update/dependency.py   2011-11-21 17:19:28 UTC (rev 
18239)
@@ -27,6 +27,7 @@
 
 import os
 from operator import xor
+import re
 
 import util
 
@@ -46,10 +47,21 @@
             self.hash = util.sha512_hexdigest(path)
 
     def set_path(self, path):
-        """Setter for path."""
-        self.path = path
-        self.realname = os.path.basename(os.path.realpath(path))
+        """Setter for path and realname which is determined from the path"""
+        self.path = os.path.realpath(path)
+        self.set_realname(os.path.basename(self.path))
     
+    def set_realname(self, realname):
+        """Sets the realname for the dependency and calculates the version."""
+        self.realname = realname
+        regex = 
re.compile(".*\.so\.(?P<major>\d+)(?:\.(?P<minor>\d+))?(?:\.(?P<rev>\d+))?$")
+        #Retrieve major number of the dependency
+        match = regex.match(realname)
+        if match:
+            (self.major, self.minor, self.rel) = match.groups()
+        else:
+            self.major = self.minor = self.rel = 0
+    
     def __eq__(self, other):
         """Compares two dependency objects. Returns True if both have same name
         and path, false otherwise.

Modified: gnunet-update/gnunet_update/install.py
===================================================================
--- gnunet-update/gnunet_update/install.py      2011-11-21 16:12:58 UTC (rev 
18238)
+++ gnunet-update/gnunet_update/install.py      2011-11-21 17:19:28 UTC (rev 
18239)
@@ -100,17 +100,12 @@
     except OSError:             # Given directory not present 
         os.mkdir(install_dir, 0755)
     
-    available_libs = get_available_libs()    # already available dependencies
-    available_libs.sort(key=(lambda dep: dep.name))
+    available_libs = util.get_available_libs()    # already available 
dependencies
     installed_files = list()    # List of files that are installed from package
-    needed_deps = metadata.dependencies # Required dependencies
+    needed_deps = metadata.dependencies.keys() # Required dependencies
+    to_be_installed_deps = util.filter_needed_deps(needed_deps,
+                                                   available_libs)
 
-    # FIXME: Add filtering in config
-    dep_filter = ["/lib/ld-linux.so.2"]
-    to_be_installed_deps = [(dep) for dep in needed_deps 
-                            if dep not in available_libs and 
-                            dep.name not in dep_filter]
-
     #FIXME: Security warning! Perhaps we should examin the contents of tarfile
     #before extracting
     for member in package_tarfile.getmembers():
@@ -129,6 +124,7 @@
     dep_dir = os.path.join(install_dir, "lib/gnunet-deps")
     if not os.path.exists(dep_dir):
         os.makedirs(dep_dir)
+    installed_files.append(dep_dir)
     orig_working_dir = os.getcwd()
     # Change to dep install dir
     os.chdir(dep_dir)
@@ -138,9 +134,9 @@
         # Remove the `dependencies/' in member.name
         dep_tarinfo.name = dep_tarinfo.name.replace("dependencies/","",1)
         package_tarfile.extract(dep_tarinfo, "./")
-        installed_files.append(os.path.join(dep_dir, dep_tarinfor.name))
+        installed_files.append(os.path.join(dep_dir, dep_tarinfo.name))
         # Check the hash of the extracted file
-        if sha512_hexdigest(dep_tarinfo.name) != dep.hash:
+        if util.sha512_hexdigest(dep_tarinfo.name) != dep.hash:
             print (dep_tarinfo.name + 
                    " not matched with the expected hash " + dep.hash)
             print "Given package contains code not signed by trusted packager"
@@ -161,10 +157,16 @@
     # run ldconfig -n in the dep_dir
     proc = subprocess.Popen(["ldconfig", "-n"])
     proc.wait()
+    os.chdir(orig_working_dir)
 
     # Write install manifest file
-    util.write_install_manifest(install_dir, installed_files)
-    os.chdir(orig_working_dir)
+    if not os.path.exists(os.path.join(install_dir, "share/gnunet-update/")):
+        os.makedirs(os.path.join(install_dir, "share/gnunet-update/"))
+    install_manifest_fd = open(os.path.join(install_dir,
+                                            
"share/gnunet-update/install-manifest"),
+                               "wb") 
+    map((lambda name: install_manifest_fd.write(name + '\n')), installed_files)
+    install_manifest_fd.close()
     print "Installation Successful!"
     print "GNUNET has been installed at: " + install_dir
     shared_library_setup(dep_dir)

Modified: gnunet-update/gnunet_update/metadata.py
===================================================================
--- gnunet-update/gnunet_update/metadata.py     2011-11-21 16:12:58 UTC (rev 
18238)
+++ gnunet-update/gnunet_update/metadata.py     2011-11-21 17:19:28 UTC (rev 
18239)
@@ -179,7 +179,7 @@
             # if we get a keyerror here, then something went wrong
             dep = self.dependencies[dep] # gets the correct object
             dep.name = dep_name
-            dep.realname = dep_realname
+            dep.set_realname(dep_realname)
             dep.hash = dep_hash
 
         f.close()

Modified: gnunet-update/gnunet_update/package.py
===================================================================
--- gnunet-update/gnunet_update/package.py      2011-11-21 16:12:58 UTC (rev 
18238)
+++ gnunet-update/gnunet_update/package.py      2011-11-21 17:19:28 UTC (rev 
18239)
@@ -116,7 +116,6 @@
     
 def get_deps(install_dir):
     """Extract dependencies from ldd output."""
-#    regex = 
re.compile(".*\.so\.(?P<major>\d+)(?:\.(?P<minor>\d+))?(?:\.(?P<rev>\d+))?$")
     for root, dirs, files in os.walk(install_dir):
         for file in files:
             file_path = os.path.join(root, file)
@@ -144,23 +143,9 @@
                 if dep_data[-1].startswith(os.path.abspath(install_dir)):
                     continue
                 #create a new dependency object and add it to the set
-                dep = Dependency(dep_data[0], dep_data[-1])
+                dep = Dependency(os.path.basename(dep_data[0]), dep_data[-1])
                 #check in cache if we already saw this dependency
                 if dep not in dependencies:
-                    #Retrieve major number of the dependency
-                    # match = regex.match(dep_data[-1])
-                    # if match:
-                    #     match2 = None
-                    #     if os.path.islink(dep_data[-1]):
-                    #         match2 = 
regex.match(os.path.realpath(dep_data[-1]))
-                            
-                    #     (dep.major, 
-                    #      dep.minor, 
-                    #      dep.rel) = match2.groups() if match2 \
-                    #                                 else match.groups()
-                    # else:
-                    #     raise Exception('Unhandled discrepancy.')
-                    
                     dependencies[dep] = dep
                 else:
                     dep = dependencies[dep]
@@ -232,11 +217,9 @@
     print "Here are the dependencies:"
     for dep in dependencies:
         print dep.name
-        if os.path.islink(dep.path):
-            dep_realpath = os.path.realpath(dep.path)
-            print "|--" + dep_realpath
-            tar_file.add(dep_realpath, 
-                         "dependencies/" + os.path.basename(dep_realpath))
+        print "|--" + dep.realname
+        tar_file.add(dep.path, 
+                     "dependencies/" + dep.realname)
         
     if (not prefix_given) and "build" == action:
         #FIXME: May be delete the temporary directory after packing?

Modified: gnunet-update/gnunet_update/util.py
===================================================================
--- gnunet-update/gnunet_update/util.py 2011-11-21 16:12:58 UTC (rev 18238)
+++ gnunet-update/gnunet_update/util.py 2011-11-21 17:19:28 UTC (rev 18239)
@@ -28,6 +28,7 @@
 import tarfile
 import shutil
 import platform
+import subprocess
 
 from metadata import Metadata
 from dependency import Dependency
@@ -189,27 +190,63 @@
     
     return metadata
 
-def write_install_manifest(install_dir, filenames):
-    """Writes install manifest data into the given directory.
+def get_available_libs(_test_input=None):
+    """Finds from `ldconfig -v' the installed dependencies.
 
-    install_dir: The directory where the manifest file is created
-    filenames: Filenames that are to be included in the manifest file
+    _test_input: This parameter is only for testing. This parameter is supposed
+         to provide a sample ldconfig output
+    return: List of dependency objects existing on the system
     """
-    if not os.path.exists(os.path.join(install_dir, "share/gnunet-update/")):
-        os.makedirs(os.path.join(install_dir, "share/gnunet-update/"))
-    install_manifest_fd = open(os.path.join(install_dir,
-                                            
"share/gnunet-update/install-manifest"),
-                               "wb") 
-    map((lambda name: install_manifest_fd.write(name + '\n')), filenames)
-    install_manifest_fd.close()
-
-def get_available_libs():
-    """Finds from `ldconfig -v' the installed libraries."""
-    proc = subprocess.Popen(["ldconfig", "-p"], stdout=subprocess.PIPE)
-    (ldconfig_output, ldconfig_err) = proc.communicate()
-    proc.stdout.close()
-    parsed_dep_list = parse_ldconfig_output(ldconfig_output)
+    if _test_input is None: # This block is not tested in unit test cases
+        proc = subprocess.Popen(["ldconfig", "-p"], stdout=subprocess.PIPE)
+        (ldconfig_output, ldconfig_err) = proc.communicate()
+        proc.stdout.close()
+        parsed_dep_list = parse_ldconfig_output(ldconfig_output)
+    else:
+        parsed_dep_list = parse_ldconfig_output(_test_input)
     def create_dependency(parsed_dep_line):
-        return Dependency(parsed_dep_line[0])
+        dep = Dependency(parsed_dep_line[0])
+        dep.set_path(parsed_dep_line[-1]) # sets path and realname
+        return dep
     return map(create_dependency, parsed_dep_list)
 
+def filter_needed_deps(needed_deps, available_deps):
+    """
+    Returns the list of needed_deps which are not satisfied by the available
+    libraries 
+
+    needed_deps: The list of dependencies that are needed by the binary objects
+    available_deps: The list of dependencies that are already
+        available/installed in the system
+    """
+    # FIXME: Add filtering in config
+    dep_filter = ["/lib/ld-linux.so.2"]
+    adep_cnt = 0                # Counter for accessing available deps
+    ndep_cnt = 0                # Counter for accessing needed deps
+    to_be_installed_deps = list() # Must be installed dependencies
+    available_deps.sort(key=(lambda dep: dep.name))
+    needed_deps.sort(key=(lambda dep: dep.name))
+    while True:
+        if ndep_cnt == len(needed_deps):
+            break
+        if adep_cnt == len(available_deps): 
+            # we ran out of available dependencies
+            to_be_installed_deps.append(needed_deps[ndep_cnt])
+            ndep_cnt += 1; continue
+        if (needed_deps[ndep_cnt].name == available_deps[adep_cnt].name and 
+            # redundant? major is always included in the name
+            needed_deps[ndep_cnt].major == available_deps[adep_cnt].major and 
+            needed_deps[ndep_cnt].minor <= available_deps[adep_cnt].minor):
+            # The current dependency is satisfied hence we don't install it
+            # FIXME: Add configurable option through which user can override
+            # this beharivour. Also add whether new libraries with greater
+            # revision numbers are to be preferred
+            ndep_cnt += 1; continue
+        elif needed_deps[ndep_cnt].name < available_deps[adep_cnt].name: 
+            # There is no installed dep matching this dep hence we have to
+            # install it
+            to_be_installed_deps.append(needed_deps[ndep_cnt])
+            ndep_cnt += 1; continue
+        elif needed_deps[ndep_cnt].name > available_deps[adep_cnt].name:
+            adep_cnt += 1; continue
+    return to_be_installed_deps;

Modified: gnunet-update/test/test_util.py
===================================================================
--- gnunet-update/test/test_util.py     2011-11-21 16:12:58 UTC (rev 18238)
+++ gnunet-update/test/test_util.py     2011-11-21 17:19:28 UTC (rev 18239)
@@ -116,7 +116,7 @@
         self.assertEqual(tmp_file.file.closed, True)
         os.remove(tmp_file.name)
         
-    def test_gpg_sign_file(self):
+    def test_gpg_sign_verify_file(self):
         """Test gpg file signing."""
                         
         # Modify HOME to point to testing home




reply via email to

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