[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r17379 - gnunet-update
From: |
gnunet |
Subject: |
[GNUnet-SVN] r17379 - gnunet-update |
Date: |
Tue, 11 Oct 2011 15:29:02 +0200 |
Author: harsha
Date: 2011-10-11 15:29:02 +0200 (Tue, 11 Oct 2011)
New Revision: 17379
Modified:
gnunet-update/package.py
Log:
added metadata serialization
Modified: gnunet-update/package.py
===================================================================
--- gnunet-update/package.py 2011-10-11 13:27:22 UTC (rev 17378)
+++ gnunet-update/package.py 2011-10-11 13:29:02 UTC (rev 17379)
@@ -20,7 +20,21 @@
#File: package.py
#Author: Sree Harsha Totakura
#
-#TODO: Export Dependency Metadata to XML file
+#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?
+#
#python script to build, install and package along with dependencies the given
#gnunet source tree
@@ -31,7 +45,9 @@
import subprocess
import tempfile
import tarfile
+import pickle
from operator import xor
+from xml.dom.minidom import Document
#global variables
configure = False
@@ -43,25 +59,25 @@
prefix_given = False
config_options = list()
binary_objects = list()
-dependencies = set()
+dependencies = dict()
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
+ 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)
+ 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))
+ """Calculates the hashes of name and path. Returns XOR of hashes"""
+ return xor(hash(self.name), hash(self.path))
class BinaryObject:
@@ -69,7 +85,7 @@
def __init__(self, name):
"""Returns am instance of BinaryObject."""
- self._name = name
+ self.name = name
self._deps = list()
def add_dependency(self, dep):
@@ -79,7 +95,6 @@
def get_dependencies(self):
"""Return the list of dependencies."""
return self._deps
-
def usage():
"""Print helpful usage information."""
@@ -172,7 +187,10 @@
continue
#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)
+ if dep not in dependencies:
+ dependencies[dep] = dep
+ else:
+ dep = dependencies[dep]
bin_object.add_dependency(dep)
#Add the binary object to the global list of binary objects
binary_objects.append(bin_object)
@@ -180,10 +198,36 @@
def test_dependency_collection():
"""Function to check whether we are collecting dependencies correctly."""
for bin_object in binary_objects:
- print bin_object._name
+ print bin_object.name
deps = bin_object.get_dependencies()
for dep in deps:
- print "|--" + dep._name + " (" + dep._path + ")"
+ 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."""
@@ -196,19 +240,29 @@
run_make_install()
os.chdir(current_dir)
get_deps(install_prefix)
- test_dependency_collection()
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)
+
#package the installed files
tar_file = tarfile.open(package_file + ".tgz", 'w:gz')
tar_file.add(install_prefix, "install-prefix")
-
+
+ #add the metadata file to tar
+ metadata_file.file.flush()
+ tar_file.add(metadata_file.name, "metadata.dat")
+
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.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))
@@ -218,6 +272,7 @@
print "gnunet has been installed into the temp dir: " + install_prefix
tar_file.close()
+ metadata_file.close()
#first parse the command line arguments
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r17379 - gnunet-update,
gnunet <=