gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r17826 - gnunet-update/gnunet_update
Date: Thu, 27 Oct 2011 23:09:48 +0200

Author: harsha
Date: 2011-10-27 23:09:48 +0200 (Thu, 27 Oct 2011)
New Revision: 17826

Added:
   gnunet-update/gnunet_update/__main__.py
Modified:
   gnunet-update/gnunet_update/install.py
   gnunet-update/gnunet_update/package.py
Log:
added install module

Added: gnunet-update/gnunet_update/__main__.py
===================================================================
--- gnunet-update/gnunet_update/__main__.py                             (rev 0)
+++ gnunet-update/gnunet_update/__main__.py     2011-10-27 21:09:48 UTC (rev 
17826)
@@ -0,0 +1,55 @@
+# 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:     package.py
+#Author:   Sree Harsha Totakura
+#
+#gnunet_update python package execution start point
+import sys
+
+def usage():
+     """Print helpful usage information."""
+     print """
+Usage: python gnunet_update <action> [action args]
+Runs action with action args which are passed to action.
+
+Valid actions are:
+    package
+    install
+
+To know more about each action and what it does type:
+    python gnunet_update action --help
+"""
+
+if len(sys.argv) < 2:
+    usage()
+    sys.exit(1)
+    
+function = sys.argv[1]
+sys.argv = sys.argv[1:]
+
+if "package" == function:
+    import package
+    package.main()
+elif "install" == function:
+    import install
+    install.main()
+else:
+    #Print usage information
+    usage()
+    sys.exit(1)
\ No newline at end of file

Modified: gnunet-update/gnunet_update/install.py
===================================================================
--- gnunet-update/gnunet_update/install.py      2011-10-27 20:49:32 UTC (rev 
17825)
+++ gnunet-update/gnunet_update/install.py      2011-10-27 21:09:48 UTC (rev 
17826)
@@ -19,4 +19,106 @@
 #File:     package.py
 #Author:   Sree Harsha Totakura
 #
-#Python sript for installing the packages packed using package script
\ No newline at end of file
+#Python sript for installing the packages packed using package script
+#
+#TODO: Add the library install dir and the dependency install dir to 
+#LD_LIBRARY_PATH env variable and notify user to add it to ld.so.conf
+#
+#TODO: Install only required dependencies
+#TODO: run ldconfig on the installed dependency directory
+
+import tarfile
+import sys
+import os
+import getopt
+import re
+import platform
+
+def usage():
+    """Print helpful usage information."""    
+    print """
+Usage arguments: [options] <package_file> </path/to/install/location>
+This script tries to install the contents in the package file in the given 
+location.
+
+Options:
+    -h, --help        : prints this message
+"""
+
+def main():
+    """Execution start point."""
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
+    except getopt.GetoptError, err:
+        print err
+        print "Execption occured"
+        usage()
+        sys.exit(1)
+        
+    for option, value in opts:
+        if option in ("-h", "--help"):
+            usage()
+            sys.exit(2)
+    
+    if len(args) != 2:
+        print "insufficient number of arguments"
+        usage()
+        sys.exit(1)
+    
+    package_tarfile = tarfile.open(args[0],'r')
+    install_dir = args[1]
+    
+    try: 
+        metadata_tarinfo = package_tarfile.getmember("metadata.dat")
+    except KeyError, err:
+        print err
+        print "Metadata not found in the given tarfile. Quitting"
+        package_tarfile.close()
+        sys.exit(2)
+    
+    metadata_file = package_tarfile.extractfile(metadata_tarinfo)
+    regex = re.compile("(?P<key>OS|MACHINE):(?P<value>.*)\n")
+    
+    #check whether the host os and machine architecture match    
+    OS_OK = MACHINE_OK = False
+    host_os = platform.system()
+    host_machine = platform.machine()
+    header_lines = 2
+    
+    while not (OS_OK and MACHINE_OK):
+        if header_lines == 0:
+            print "The given package is not suited for this platform."
+            metadata_file.close()
+            package_tarfile.close()
+            sys.exit(1)
+            
+        match = regex.match(metadata_file.readline())
+        if not match:
+            print "Provided package doesn't conform to the expected format."
+            metadata_file.close()
+            package_tarfile.close()
+            sys.exit(1)
+            
+        if "OS" == match.group("key"):
+            OS_OK = host_os == match.group("value") 
+        if "MACHINE" == match.group("key"):
+            MACHINE_OK = host_machine == match.group("value")
+    metadata_file.close()
+    
+    #Platform check is done; now unpack the tarfile into destination directory
+    try:
+        os.stat(install_dir)
+    except OSError:
+        os.mkdir(install_dir, 0755)
+    
+    #FIXME: Security warning! Perhaps we should examin the contents of tarfile
+    #before extracting
+    for member in package_tarfile.getmembers():
+        if "metadata.dat" == member.name:
+            continue
+        package_tarfile.extract(member, install_dir)
+        
+    package_tarfile.close()
+    
+if "__main__" == __name__:
+    main()
\ No newline at end of file

Modified: gnunet-update/gnunet_update/package.py
===================================================================
--- gnunet-update/gnunet_update/package.py      2011-10-27 20:49:32 UTC (rev 
17825)
+++ gnunet-update/gnunet_update/package.py      2011-10-27 21:09:48 UTC (rev 
17826)
@@ -35,6 +35,7 @@
 import subprocess
 import tempfile
 import tarfile
+import platform
 from dependency import Dependency, BinaryObject
 
 #global variables
@@ -50,7 +51,7 @@
 def usage():
     """Print helpful usage information."""    
     print """
-Usage: package.py [options] /path/to/gnunet/source package-file
+Usage arguments: [options] /path/to/gnunet/source package-file
 This script compiles and builds given gnunet source tree. It then attempts to 
 install it and packs the installed files along with their dependencies into
 package-file
@@ -194,6 +195,11 @@
 
     metadata_file = tempfile.NamedTemporaryFile()
     
+    #Add platform specific information to the metadata
+    machine_type = platform.machine();
+    metadata_file.file.writelines(["OS:" + platform.system() + "\n",
+                                   "MACHINE:" + platform.machine() + "\n"])
+     
     for binary_object in binary_objects:
         metadata_file.file.writelines(binary_object.dependency_listlines())
     




reply via email to

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