gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r18695 - gnunet-update/gnunet_update


From: gnunet
Subject: [GNUnet-SVN] r18695 - gnunet-update/gnunet_update
Date: Mon, 19 Dec 2011 17:22:12 +0100

Author: harsha
Date: 2011-12-19 17:22:12 +0100 (Mon, 19 Dec 2011)
New Revision: 18695

Removed:
   gnunet-update/gnunet_update/dependency.py
Modified:
   gnunet-update/gnunet_update/file.py
   gnunet-update/gnunet_update/install.py
   gnunet-update/gnunet_update/install_manifest.py
   gnunet-update/gnunet_update/metadata.py
   gnunet-update/gnunet_update/package.py
   gnunet-update/gnunet_update/update.py
Log:
-cleanup

Deleted: gnunet-update/gnunet_update/dependency.py
===================================================================
--- gnunet-update/gnunet_update/dependency.py   2011-12-19 16:08:07 UTC (rev 
18694)
+++ gnunet-update/gnunet_update/dependency.py   2011-12-19 16:22:12 UTC (rev 
18695)
@@ -1,113 +0,0 @@
-#!/usr/bin/python
-# 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/dependency.py
-#Author:   Sree Harsha Totakura
-#                                     
-#                                                                   
-#File for holding the Dependency and BinaryObject classes
-#
-#FIXME: No convention being followed for private members!!
-
-import os
-from operator import xor
-import re
-
-import util
-
-class Dependency:
-    """Class for holding data for a dependency"""
-    major = minor = rel = None
-    name = None
-    path = None
-    realname = None
-
-    def __init__(self, name, path=None):
-        """Creates a new dependency object with name and path."""
-        self.name = name
-        self.path = path
-        if path is not None:
-            self.set_path(path)
-            self.hash = util.sha512_hexdigest(path)
-
-    def set_path(self, 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.
-        """
-        return (self.name == other.name)       
-        
-    def __hash__(self):
-        """Calculates the hash of dependency name."""
-        return hash(self.name)
-
-
-class BinaryObject:
-    """Class representing executable code."""
-    
-    def __init__(self, name=None, path=None):
-        """Returns am instance of BinaryObject."""
-        self.name = name
-        self.path = path
-        self._deps = list()
-        
-        if path is not None:
-           self.hash = util.sha512_hexdigest(path)
-        
-    def add_dependency(self, dep):
-        """Adds dep object to the list of dependencies."""
-        self._deps.append(dep)
-        
-    def get_dependencies(self):
-        """Return the list of dependencies."""
-        return self._deps
-    
-    def _dependency_ascii(self, dep):
-        """Given a dependency, returns an ascii line describing it."""
-        dep_str = self.name + ";" + dep.name
-        return dep_str + "\n"
-    
-    def dependency_listlines(self):
-        """Return list of lines which describe all dependencies."""
-        return map(self._dependency_ascii, self._deps)
-
-    def __eq__(self, other):
-        """The equality relation."""
-        if not (self.name == other.name and self.path == other.path):
-            return False
-        
-        for dep in other.get_dependencies():
-            if dep not in self._deps:
-                return False
-        return True

Modified: gnunet-update/gnunet_update/file.py
===================================================================
--- gnunet-update/gnunet_update/file.py 2011-12-19 16:08:07 UTC (rev 18694)
+++ gnunet-update/gnunet_update/file.py 2011-12-19 16:22:12 UTC (rev 18695)
@@ -28,24 +28,21 @@
 class FileObject(object):
     """Class for holding data for a file entity"""
     name = None
-    path = None
     hash = None
 
-    def __init__(self, name, path=None, hash=None):
+    def __init__(self, name, hash=None):
         """
-        Creates a new FileObject object with name and path
+        Creates a new FileObject object
 
-        name: The name of the file represented by this FileObject
-        path: The path on the hosts file system where this file is located. If
-            not None then the hash for file is also created
+        name: The path of the file relative to the install dir
+        hash: The sha512 hash of this file
         """
         self.name = name
-        self.path = path
         self.hash = hash
 
     def __eq__(self, other):
         """Compares two dependency objects. Returns True if both have same name
-        and path, false otherwise.
+        false otherwise.
         """
         return (self.name == other.name)
 
@@ -57,9 +54,13 @@
     """Class representing an executable file entity."""
     deps = None
 
-    def __init__(self, name, path=None, hash=None):
-        """Creates a new ExecutableFileObject."""
-        super(ExecutableFileObject, self).__init__(name, path, hash)
+    def __init__(self, name, hash=None):
+        """Creates a new ExecutableFileObject.
+        
+        name: the path of the file relative to the install dir
+        hash: the sha512 hash of the file
+        """
+        super(ExecutableFileObject, self).__init__(name, hash)
         self.deps = list()
 
     def add_dependency(self, dep):
@@ -72,7 +73,7 @@
     
     def __eq__(self, other):
         """The equality relation."""
-        if not (self.name == other.name and self.path == other.path):
+        if not (self.name == other.name):
             return False
         for dep in other.deps:
             if dep not in self.deps:
@@ -81,6 +82,7 @@
 
 class DependencyFileObject(FileObject):
     """Class representing a dependency (library object)."""
+    path = None
     _major = None
     _minor = None
     _rel = None
@@ -88,8 +90,16 @@
     _regex = 
re.compile(".*\.so\.(?P<major>\d+)(?:\.(?P<minor>\d+))?(?:\.(?P<rev>\d+))?$")
     
     def __init__(self, name, path=None, hash=None):
-        """Creates a new DependencyFileObject instance."""
-        super(DependencyFileObject, self).__init__(name, path, hash)
+        """Creates a new DependencyFileObject instance.
+        name: The name of the dependency(the name shown in the ldd output for
+              an executable)
+        path: The absolute path of this dependency
+        hash: The hash of the dependency file
+        """
+        # Having a relative path for the dependency is not a good as the
+        # dependency may not be present in the install dir
+        super(DependencyFileObject, self).__init__(name, hash)
+        self.path = path
         match = self._regex.match(name)
         if match:
             (self._major, self._minor, self._rel) = match.groups()

Modified: gnunet-update/gnunet_update/install.py
===================================================================
--- gnunet-update/gnunet_update/install.py      2011-12-19 16:08:07 UTC (rev 
18694)
+++ gnunet-update/gnunet_update/install.py      2011-12-19 16:22:12 UTC (rev 
18695)
@@ -122,7 +122,7 @@
     dep_dir = os.path.join(install_dir, "lib/gnunet-deps")
     if not os.path.exists(dep_dir):
         os.makedirs(dep_dir)
-    # Add the gnunet dependency dir to the install manifest
+
     orig_working_dir = os.getcwd()
     # Change to dep install dir
     os.chdir(dep_dir)

Modified: gnunet-update/gnunet_update/install_manifest.py
===================================================================
--- gnunet-update/gnunet_update/install_manifest.py     2011-12-19 16:08:07 UTC 
(rev 18694)
+++ gnunet-update/gnunet_update/install_manifest.py     2011-12-19 16:22:12 UTC 
(rev 18695)
@@ -89,9 +89,7 @@
         tokens = read_line.split(';')
         rel_file_path = tokens[0]
         file_hash = tokens[1]
-        file_object = FileObject(os.path.basename(rel_file_path),
-                                 os.path.join(install_dir,
-                                              rel_file_path),
+        file_object = FileObject(rel_file_path,
                                  file_hash)
         file_objects.append(file_object)
     

Modified: gnunet-update/gnunet_update/metadata.py
===================================================================
--- gnunet-update/gnunet_update/metadata.py     2011-12-19 16:08:07 UTC (rev 
18694)
+++ gnunet-update/gnunet_update/metadata.py     2011-12-19 16:22:12 UTC (rev 
18695)
@@ -79,12 +79,12 @@
             for dep in binary_object.deps:
                 writeln_(binary_object.name + ";" + dep.name)
         
-        #write the signatures of files in the package
+        #write the hash values of files in the package
         writeln_("%%") #section seperator
         for file_object in self.binary_objects + self.other_objects:
             writeln_(file_object.name + ";" + file_object.hash)
 
-        # write the signatures of dependencies
+        # write the hash values of dependencies
         writeln_("%%") #section seperator
         for dep in self.dependencies:
             writeln_(dep.name + ";" + dep.realname + ";" + dep.hash)
@@ -114,7 +114,6 @@
             if "%%" == read_line[:2] : 
                 break
             tokens = read_line.split(':')
-            # FIXME: Sanity check on file format
             key = tokens[0]
             value = tokens[1][:-1] # last character will be `\n'
             if "MACHINE" == key:
@@ -149,7 +148,9 @@
             # try to use the existing dependency object
             if dep not in self.dependencies:
                 self.dependencies[dep] = dep
-            seen_bin_object.add_dependency(self.dependencies[dep])
+            else:
+                dep = self.dependencies[dep]
+            seen_bin_object.add_dependency(dep)
             
         # read until next `%%'
         # read the hashes
@@ -167,7 +168,7 @@
             if file_name in _binary_objects: 
                 _binary_objects[file_name].hash = hash
             else:
-                other_object = FileObject(file_name, hash=hash)
+                other_object = FileObject(file_name, hash)
                 self.other_objects.append(other_object)
             
         # read the dependency name, file name(real name) and its hash

Modified: gnunet-update/gnunet_update/package.py
===================================================================
--- gnunet-update/gnunet_update/package.py      2011-12-19 16:08:07 UTC (rev 
18694)
+++ gnunet-update/gnunet_update/package.py      2011-12-19 16:22:12 UTC (rev 
18695)
@@ -61,9 +61,9 @@
 Options:
     -h, --help                : prints this message
     -c, --config=FILENAME     : use configuration file FILENAME
-    -i                        : treat the given path as a location where gnunet
-                                is already installed and package the objects in
-                                that path 
+    -i                        : treat the given source path as a location where
+                                gnunet is already installed and package the
+                                objects in that path 
     -o, --option=OPTION       : options that are to be passed to configure
                                 script in the given source tree. Multiple
                                 number of such options can be specified. These
@@ -118,6 +118,7 @@
 def get_deps(install_dir):
     """Extract dependencies from ldd output."""
     for root, dirs, files in os.walk(install_dir):
+        root_rel = os.path.relpath(root, install_dir)
         for file in files:
             file_path = os.path.join(root, file)
             #ignore symbolic links if they point to something inside 
install_dir
@@ -125,9 +126,7 @@
                 len(os.path.commonprefix([file_path, root])) >= 
                 len(install_dir)):
                 other_objects.append(FileObject(
-                        os.path.join(root[len(install_dir) + 1:],
-                                     file),
-                        file_path,
+                        os.path.join(root_rel, file),
                         "-LINK"))
                 continue
             
@@ -140,18 +139,15 @@
             # points to something outside of the install directory then it may
             # cause issues during installation
             if 0 != proc.returncode:
-                other_object = FileObject(os.path.join(root[len(install_dir) + 
1:],
-                                                           file),
-                                          file_path,
+                other_object = FileObject(os.path.join(root_rel, file),
                                           util.hexdigest(file_path))
                 other_objects.append(other_object)
                 continue
 
             #create a new ExecutableFileObject instance and collect its 
dependencies
-            bin_object = 
ExecutableFileObject(os.path.join(root[len(install_dir) + 1:],
-                                                           file),
-                                              file_path,
+            bin_object = ExecutableFileObject(os.path.join(root_rel,file),
                                               hash=util.hexdigest(file_path))
+
             for dep_data in util.parse_ldd_output(proc_stdout):
                 #we cannot find a library without its location
                 if dep_data[-1][0] == '(':
@@ -160,7 +156,7 @@
                 if dep_data[-1].startswith(os.path.abspath(install_dir)):
                     continue
                 #create a new dependency object and add it to the set
-                dep = DependencyFileObject(os.path.basename(dep_data[0]), 
+                dep = DependencyFileObject(os.path.basename(dep_data[0]),
                                            dep_data[-1])
                 #check in cache if we already saw this dependency
                 if dep not in dependencies:
@@ -194,7 +190,7 @@
         os.chdir(current_dir)
         get_deps(install_prefix)
     else :
-        get_deps(gnunet_src)
+        get_deps(install_prefix)
     test_dependency_collection()
 
     metadata = Metadata(machine=platform.machine(),
@@ -209,7 +205,7 @@
     tar_file = tarfile.open(package_file + ".tgz", 'w:gz')
     #tar_file.add(install_prefix, "install-prefix")
     for file_object in other_objects + binary_objects:
-        tar_file.add(file_object.path, 
+        tar_file.add(os.path.join(install_prefix, file_object.name), 
                      os.path.join("install-prefix", file_object.name))
     
     #generate the metadata file and add it to tar
@@ -292,8 +288,11 @@
         gnunet_src = args[0]
         package_file = args[1]
         #if prefix is not given we need to install into a temporary directory
-        if not prefix_given:
-            install_prefix = tempfile.mkdtemp(prefix="gnunet-install.")
+        if "build" == action:
+            if not prefix_given:
+                install_prefix = tempfile.mkdtemp(prefix="gnunet-install.")
+        else:
+            install_prefix = gnunet_src
         run(action)
 
 if __name__ == "__main__":

Modified: gnunet-update/gnunet_update/update.py
===================================================================
--- gnunet-update/gnunet_update/update.py       2011-12-19 16:08:07 UTC (rev 
18694)
+++ gnunet-update/gnunet_update/update.py       2011-12-19 16:22:12 UTC (rev 
18695)
@@ -142,15 +142,18 @@
     # Delete objects in the to_be_deleted list
     deleted_objects = list()
     for f_object in to_be_deleted_objects:
-        if os.path.isdir(f_object.path): # delete files first
+        f_object_path = os.path.join(install_dir, f_object.name)
+        if os.path.isdir(f_object_path): # delete files first
             continue
-        os.remove(f_object.path)
+        os.remove(f_object_path)
         # to_be_deleted_objects.remove(f_object)
         deleted_objects.append(f_object)
+
     for f_object in [obj for obj in to_be_deleted_objects 
                      if obj not in deleted_objects]: 
+        f_object_path = os.path.join(install_dir, f_object.name)
         #Only directories should be remaining
-        os.rmdir(f_object.path)      # delete them
+        os.rmdir(f_object_path)      # delete them
 
     # Useful files retained from older installation
     retained_objects = [ f_object for f_object in old_install_objects
@@ -179,7 +182,6 @@
     dep_dir = os.path.join(install_dir, "lib/gnunet-deps")
     orig_working_dir = os.getcwd()
     os.chdir(dep_dir)
-    
     # Delete the expired deps
     for dep in expired_deps:
         os.remove(dep.realname)
@@ -214,9 +216,9 @@
     package_tarfile.close()
 
     # run ldconfig -n in the dep_dir
-    proc = subprocess.Popen(["ldconfig", "-n"])
-    proc.wait()
-    os.chdir(orig_working_dir)
+    # proc = subprocess.Popen(["ldconfig", "-n"])
+    # proc.wait()
+    # os.chdir(orig_working_dir)
 
     # Write install manifest file
     install_manifest.write_to_file(install_dir, 




reply via email to

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