gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r16853 - gnunet-update


From: gnunet
Subject: [GNUnet-SVN] r16853 - gnunet-update
Date: Wed, 14 Sep 2011 21:17:36 +0200

Author: harsha
Date: 2011-09-14 21:17:36 +0200 (Wed, 14 Sep 2011)
New Revision: 16853

Modified:
   gnunet-update/package.py
Log:
added functions to determine dependencies

Modified: gnunet-update/package.py
===================================================================
--- gnunet-update/package.py    2011-09-14 18:25:10 UTC (rev 16852)
+++ gnunet-update/package.py    2011-09-14 19:17:36 UTC (rev 16853)
@@ -1,6 +1,9 @@
 #!/usr/bin/python
 #File:     package.py
 #Author:   Sree Harsha Totakura
+#
+#TODO:     Add packaging function which packages all objects and dependencies
+#          into a bzip file
 
 #python script to build, install and package along with dependencies the given
 #gnunet source tree
@@ -9,16 +12,16 @@
 import sys
 import os
 import subprocess
+import tempfile
 
-#static variables
+#global variables
 configure = False
 build = False
 install = False
 gnunet_src = ""
 install_prefix = ""
-extractor_base = ""
-libcurl_base = ""
-microhttpd_base = ""
+prefix_given = False
+config_options = list()
 deps = set()
 
 def usage():
@@ -26,21 +29,21 @@
     """
     
     print """
-Usage: package.py [options] [configure_options] /path/to/gnunet/source
-Without any options the source tree is configured with configure_options, built
-and installed. Without any configure_options the source tree is configured 
with 
-system defaults
+Usage: package.py [options] /path/to/gnunet/source
+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 an
+exportable package 
 
 Options:
-    -c            : configure the source
-    -b            : Builds the source in the same directory
-    -i            : Installs gnunet (into the prefix, if set)
-    -h, --help    : Print this message
-    
-Configure options:
-    --prefix=PREFIX        : The directory into which gnunet is to be installed
-    --with-extractor=PFX   : base of libextractor installation
-    --with-libcurl=PFX     : base of libcurl installation
+    -h, --help        : prints this message
+    -i                : treat the given path as a location where gnunet is
+                        already installed and package the objects in that path
+    -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" 
+                             -c "--with-extractor=/opt/Extractor"
+                        
 """
 
 def run_configure():
@@ -56,18 +59,12 @@
     
     #Ideally, by now we should have generated ./configure
     if os.access("./configure", os.R_OK|os.X_OK):
-        proc_args = ["./configure"]
-        if "" != install_prefix:
-            proc_args.append("--prefix=" + install_prefix);
-        if "" != extractor_base:
-            proc_args.append("--with-extractor=" + extractor_base);
-        if "" != libcurl_base:
-            proc_args.append("--with-libcurl=" + libcurl_base);
-        if "" != microhttpd_base:
-            proc_args.append("--with-microhttpd=" + microhttpd_base);
+        config_options.insert(0, "./configure")
         
-        #now run the configure subprocess
-        proc = subprocess.Popen(proc_args, bufsize = -1)
+        if not prefix_given:
+            config_options.insert(1 ,"--prefix=" + install_prefix)
+        
+        proc = subprocess.Popen(config_options, bufsize = -1)
         if 0 != proc.wait():
             print "Configure on the given source tree failed"
             sys.exit(1)
@@ -75,10 +72,6 @@
 def run_make():
     """Runs make on the given source tree
     """
-    
-    if "" != libcurl_base:
-        new_environ = os.environ.copy()
-        new_environ["CFLAGS"] = "-I"+libcurl_base
     proc = subprocess.Popen("make", bufsize = -1)
     if 0 != proc.wait():
         print "Cannot build the source tree. make failed"
@@ -88,7 +81,6 @@
     """Installs the compiled binaries in the given source tree by running make
     install
     """
-    
     proc = subprocess.Popen(["make", "install"], bufsize = -1)
     if 0 != proc.wait():
         print "Failed while installing the compiled binaries."
@@ -106,46 +98,53 @@
     tokens[-1] = tokens[-1].rsplit(' ', 1)[0]
     return tokens
     
-def get_deps:
+def get_deps(install_dir):
     """Extract dependencies from ldd output
     """
-    for root, dirs, files in os.walk(install_prefix):
+    for root, dirs, files in os.walk(install_dir):
         for file in files:
             proc = subprocess.Popen(["ldd", os.path.join(root, file)],
                                     bufsize = -1, stdout = subprocess.PIPE)
             (proc_stdout, proc_stderr) = proc.communicate()
+            proc.stdout.close()
             if 0 != proc.returncode:
                 continue
-             
             
-    
+            for dep in map (extract_deps, proc_stdout.splitlines()):
+                #we cannot find a library without its location
+                if dep[-1][0] == '(':
+                    continue
+                #print dep
+                deps.add(dep[-1])
 
 def run(action):
     """main control procedure
     """
     #change the directory to gnunet_src
-    os.chdir(gnunet_src)
-    if configure :
+    if "build" == action:
+        os.chdir(gnunet_src)
         run_configure()
-    if build:
         run_make()
-    if install:
         run_make_install()
-    
+        get_deps(install_prefix)
+    else :
+        get_deps(gnunet_src)
         
-    
-    
-         
+    print "Here are the dependencies:"
+    for dep in deps:
+        print dep
         
+    if (not prefix_given) and "build" == action:
+        #FIXME: May be delete the temporary directory after packing?
+        print "gnunet has been installed into the temp dir: " + install_prefix
         
-    
+        
 
 #first parse the command line arguments
 try:
     opts, args = getopt.getopt(sys.argv[1:], 
-                               "cbih", 
-                               ["help", "prefix=", "with-extractor=", 
-                                "with-libcurl=", "with-microhttpd="])
+                               "c:hi", 
+                               ["help", "config="])
     
 except getopt.GetoptError, err:
     print err
@@ -153,33 +152,29 @@
     usage()
     sys.exit(2)
 else:
+    action = "build"
     for option, value in opts:
         if option in ("-h", "--help"):
             usage()
             sys.exit(2)
-        elif option == "-c":
-            configure = True
-        elif option == "-b":
-            build = True
+        elif option in ("-c", "--config"):
+            config_options.append(value)
+            #check if the user has given an installation prefix
+            if(value.strip()[0:9] == "--prefix="):
+                prefix_given = True
+                install_prefix = value.strip()[9:] 
         elif option == "-i":
-            install = True
-        elif option == "--prefix":
-            install_prefix = value
-        elif option == "--with-extractor":
-            extractor_base = value
-        elif option == "--with-libcurl":
-            libcurl_base = value
-        elif option == "--with-microhttpd":
-            microhttpd_base = value
-            
-    if not (configure or build or install):
-        configure, build, install = True, True, True
-        
+            action = "extract_deps"  
     if len(args) != 1:
         print "Path to gnunet source tree missing!"
         usage()
         sys.exit(1)
-    gnunet_src = args[0];
-    run()
+    gnunet_src = args[0]
     
-                                
\ No newline at end of file
+    #if the prefix is not given we need to install into a temporary directory
+    if not prefix_given:
+        install_prefix = tempfile.mkdtemp(prefix="gnunet-install.")
+        
+    run(action)
+    
+                                




reply via email to

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