[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r17358 - gnunet-update
From: |
gnunet |
Subject: |
[GNUnet-SVN] r17358 - gnunet-update |
Date: |
Mon, 10 Oct 2011 18:50:00 +0200 |
Author: harsha
Date: 2011-10-10 18:50:00 +0200 (Mon, 10 Oct 2011)
New Revision: 17358
Modified:
gnunet-update/package.py
Log:
Added Datastructures for dependency meta-data
Modified: gnunet-update/package.py
===================================================================
--- gnunet-update/package.py 2011-10-10 16:26:15 UTC (rev 17357)
+++ gnunet-update/package.py 2011-10-10 16:50:00 UTC (rev 17358)
@@ -20,7 +20,7 @@
#File: package.py
#Author: Sree Harsha Totakura
#
-#TODO: Include the Metadata about dependencies in the package file
+#TODO: Export Dependency Metadata to XML file
#python script to build, install and package along with dependencies the given
#gnunet source tree
@@ -31,6 +31,7 @@
import subprocess
import tempfile
import tarfile
+from operator import xor
#global variables
configure = False
@@ -41,12 +42,47 @@
package_file = ""
prefix_given = False
config_options = list()
-deps = set()
+binary_objects = list()
+dependencies = set()
+
+class Dependency:
+ """Class for holding data for a dependency"""
+ def __init__(self, name, path):
+ """Creates a new dependency object with name and path."""
+ self._name = name
+ self._path = path
+
+ def __eq__(self, other):
+ """Compares two dependency objects. Returns True if both have same name
+ and path, false otherwise.
+ """
+ return (self._name == other._name and self._path == other._path)
+
+ def __hash__(self):
+ """Calculates the hashes of )name and _path. Returns XOR of hashes"""
+ return xor(hash(self._name), hash(self._path))
+
+
+class BinaryObject:
+ """Class representing executable code."""
+
+ def __init__(self, name):
+ """Returns am instance of BinaryObject."""
+ self._name = name
+ self._deps = list()
+
+ 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 usage():
- """Print helpful usage information
- """
-
+ """Print helpful usage information."""
print """
Usage: package.py [options] /path/to/gnunet/source package-file
This script compiles and builds given gnunet source tree. It then attempts to
@@ -66,8 +102,7 @@
"""
def run_configure():
- """Runs configure on the given source tree
- """
+ """Runs configure on the given source tree."""
#Clean the directory; it may fail if there is no makefile - ignore it
proc = subprocess.Popen(["make", "clean"])
@@ -93,8 +128,7 @@
sys.exit(1)
def run_make():
- """Runs make on the given source tree
- """
+ """Runs make on the given source tree."""
proc = subprocess.Popen("make", bufsize = -1)
if 0 != proc.wait():
print "Cannot build the source tree. make failed"
@@ -110,20 +144,17 @@
sys.exit(1)
def strip(str):
- """ helper function to strip any trailing characters
- """
+ """ 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
- """
+ """ 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
- """
+ """Extract dependencies from ldd output."""
for root, dirs, files in os.walk(install_dir):
for file in files:
proc = subprocess.Popen(["ldd", os.path.join(root, file)],
@@ -132,17 +163,30 @@
proc.stdout.close()
if 0 != proc.returncode:
continue
+ #create a new BinaryObject instance and collect its dependencies
+ bin_object = BinaryObject(root[len(install_dir) + 1:] + '/' + file)
- for dep in map (extract_deps, proc_stdout.splitlines()):
+ for dep_data in map (extract_deps, proc_stdout.splitlines()):
#we cannot find a library without its location
- if dep[-1][0] == '(':
+ if dep_data[-1][0] == '(':
continue
- #Add the dependency
- deps.add(dep[-1])
+ #create a new dependency object and add it to the set
+ dep = Dependency(dep_data[0], dep_data[-1])
+ if dep not in dependencies: dependencies.add(dep)
+ bin_object.add_dependency(dep)
+ #Add the binary object to the global list of binary objects
+ binary_objects.append(bin_object)
+def test_dependency_collection():
+ """Function to check whether we are collecting dependencies correctly."""
+ for bin_object in binary_objects:
+ print bin_object._name
+ deps = bin_object.get_dependencies()
+ for dep in deps:
+ print "|--" + dep._name + " (" + dep._path + ")"
+
def run(action):
- """main control procedure
- """
+ """main control procedure."""
#change the directory to gnunet_src
if "build" == action:
current_dir = os.getcwd()
@@ -152,6 +196,7 @@
run_make_install()
os.chdir(current_dir)
get_deps(install_prefix)
+ test_dependency_collection()
else :
get_deps(gnunet_src)
@@ -160,10 +205,10 @@
tar_file.add(install_prefix, "install-prefix")
print "Here are the dependencies:"
- for dep in deps:
- print dep
- if os.path.islink(dep):
- dep_realpath = os.path.realpath(dep)
+ 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))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r17358 - gnunet-update,
gnunet <=