[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r17405 - gnunet-update
From: |
gnunet |
Subject: |
[GNUnet-SVN] r17405 - gnunet-update |
Date: |
Wed, 12 Oct 2011 14:23:52 +0200 |
Author: harsha
Date: 2011-10-12 14:23:52 +0200 (Wed, 12 Oct 2011)
New Revision: 17405
Modified:
gnunet-update/package.py
Log:
modified metadata export
Modified: gnunet-update/package.py
===================================================================
--- gnunet-update/package.py 2011-10-12 12:01:24 UTC (rev 17404)
+++ gnunet-update/package.py 2011-10-12 12:23:52 UTC (rev 17405)
@@ -21,19 +21,8 @@
#Author: Sree Harsha Totakura
#
#TODO:
-# Use cpickle for faster (de)serialization.
-# Obtain major, min and revision numbers of dependencies if they
-# exist.
-# ?Do not treat symlinks to binary object files as binary objects?
-# e.g: libfun.so.0 -> libfun.so.0.0.0. The problem here is that we are
-# currently storing dependencies for both of them where in we only
-# need for one (libfun.so.0.0.0)
#
-#Thoughts:
-# Should we use XML for storing metadata?
-# What should happen if the install-prefix is different in the target
-# machine where we have to install from the machine which is used to
-# pack?
+#Thoughts:
#
#python script to build, install and package along with dependencies the given
@@ -42,10 +31,10 @@
import getopt
import sys
import os
+import re
import subprocess
import tempfile
import tarfile
-import pickle
from operator import xor
from xml.dom.minidom import Document
@@ -63,7 +52,8 @@
class Dependency:
- """Class for holding data for a dependency"""
+ """Class for holding data for a dependency"""
+ major = minor = rev = None
def __init__(self, name, path):
"""Creates a new dependency object with name and path."""
self.name = name
@@ -76,7 +66,7 @@
return (self.name == other.name and self.path == other.path)
def __hash__(self):
- """Calculates the hashes of name and path. Returns XOR of hashes"""
+ """Calculates the hashes of name and path. Returns XOR of hashes."""
return xor(hash(self.name), hash(self.path))
@@ -95,7 +85,20 @@
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 + ";"
+ dep_str += "-1:" if dep.major == None else dep.major + ":"
+ dep_str += "-1:" if dep.minor == None else dep.minor + ":"
+ dep_str += "-1" if dep.rev == None else dep.rev
+ return dep_str + "\n"
+
+ def dependency_listlines(self):
+ """Return list of lines which describe all dependencies."""
+ return map(self._dependency_ascii, self._deps)
+
def usage():
"""Print helpful usage information."""
print """
@@ -111,7 +114,7 @@
-c "option" : options that are to be passed to configure script in
the
given source tree. Multiple number of such options can
be specified. These must be enclosed in double quotes.
- E.g: -c "--prefix /opt/gnunet"
+ E.g: -c "--prefix=/opt/gnunet"
-c "--with-extractor=/opt/Extractor"
"""
@@ -151,7 +154,7 @@
def run_make_install():
"""Installs the compiled binaries in the given source tree by running make
- install
+ installdep_str += "-1:" if dep.minor == None else dep.minor + ":"
"""
proc = subprocess.Popen(["make", "install"], bufsize = -1)
if 0 != proc.wait():
@@ -170,9 +173,17 @@
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:
- proc = subprocess.Popen(["ldd", os.path.join(root, file)],
+ file_path = os.path.join(root, file)
+ #ignore symbolic links if they point to something inside
install_dir
+ if (os.path.islink(file_path) and
+ len(os.path.commonprefix([file_path, root])) >=
+ len(install_dir)):
+ continue
+
+ proc = subprocess.Popen(["ldd", file_path],
bufsize = -1, stdout = subprocess.PIPE)
(proc_stdout, proc_stderr) = proc.communicate()
proc.stdout.close()
@@ -187,6 +198,19 @@
continue
#create a new dependency object and add it to the set
dep = Dependency(dep_data[0], dep_data[-1])
+ #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.rev) = match2.groups() if match2 else match.groups()
+ else:
+ raise Exception('Unhandled discrepancy.')
+
if dep not in dependencies:
dependencies[dep] = dep
else:
@@ -202,35 +226,9 @@
deps = bin_object.get_dependencies()
for dep in deps:
print "|--" + dep.name + " (" + dep.path + ")"
-
-#for now we aren't using this code. However, if we ever need to use XML this
may
-#give us a start
-def generate_xml_metadata():
- """Generates XML file containing dependency metadata."""
- #Create the document first
- xml_doc = Document()
- root_node = xml_doc.createElement("metadata")
- xml_doc.appendChild(root_node)
- binary_objects_list_node = xml_doc.createElement("binary_object_list")
- root_node.appendChild(binary_objects_list_node)
-
- for binary_object in binary_objects:
- binary_object_node = xml_doc.createElement("binary_object")
- binary_object_node.setAttribute("name", binary_object.name)
-
- for dep in binary_object.get_dependencies():
- binary_object_node.setAttribute("dependency", hash(dep))
-
- binary_objects_list_node.appendChild(binary_object_node)
-
- dependency_list_node = xml_doc.createElement("dependency_list")
-
- for dependency in dict.keys():
- dependency_node = xml_doc.createElement("dependency")
- dependency_node.setAttribute("id", hash(dependency))
def run(action):
- """main control procedure."""
+ """control procedure."""
#change the directory to gnunet_src
if "build" == action:
current_dir = os.getcwd()
@@ -243,13 +241,12 @@
else :
get_deps(gnunet_src)
test_dependency_collection()
-
- #Export dependency metadata using pickle
+
metadata_file = tempfile.NamedTemporaryFile()
- pickler = pickle.Pickler(metadata_file.file, 0)
- pickler.dump(dependencies)
- pickler.dump(binary_objects)
+ for binary_object in binary_objects:
+ metadata_file.file.writelines(binary_object.dependency_listlines())
+
#package the installed files
tar_file = tarfile.open(package_file + ".tgz", 'w:gz')
tar_file.add(install_prefix, "install-prefix")
@@ -312,5 +309,4 @@
install_prefix = tempfile.mkdtemp(prefix="gnunet-install.")
run(action)
-
-
+
\ No newline at end of file
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r17405 - gnunet-update,
gnunet <=