gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r25301 - in gnunet-update/src: gnunet_update tests


From: gnunet
Subject: [GNUnet-SVN] r25301 - in gnunet-update/src: gnunet_update tests
Date: Thu, 6 Dec 2012 17:06:23 +0100

Author: harsha
Date: 2012-12-06 17:06:23 +0100 (Thu, 06 Dec 2012)
New Revision: 25301

Modified:
   gnunet-update/src/gnunet_update/install.py
   gnunet-update/src/gnunet_update/util.py
   gnunet-update/src/tests/test_regression.py
Log:
fix 2679: Installer should extend PATH env variable in default profile files

Modified: gnunet-update/src/gnunet_update/install.py
===================================================================
--- gnunet-update/src/gnunet_update/install.py  2012-12-06 15:21:32 UTC (rev 
25300)
+++ gnunet-update/src/gnunet_update/install.py  2012-12-06 16:06:23 UTC (rev 
25301)
@@ -28,6 +28,7 @@
 import getopt
 import subprocess
 import tempfile
+import stat
 
 import util
 import install_manifest
@@ -35,8 +36,8 @@
 from config import GnunetUpdateConfig
 from file import ExecutableFileObject, FileObject
 
-# Used for testing; Should be set to sys.stdin if running directly
-stdin = None
+# Used for testing; Sets from where we read input
+getch_ = None
 
 def _usage():
     """Print helpful usage information."""    
@@ -80,7 +81,7 @@
     external_config_file = None
     list_groups = False
     install_group_names = set()
-    assert stdin is not None
+    assert getch_ is not None
     try:
         opts, args = getopt.getopt(sys.argv[1:], 
                                    "c:g:lh", 
@@ -124,7 +125,7 @@
     if not util.gpg_key_exists(pgp_sign_key):
         print "We are about to download and install a GPG key with 
fingerprint: " + pgp_sign_key
         print "Press [Y] to proceed or any other key to abort"
-        ch = util.getch(sys.stdin)
+        ch = getch_()
         if ch is None:
             sys.exit(0)
         if ch not in ['Y', 'y']:
@@ -164,7 +165,7 @@
         os.stat(install_dir)
     except OSError:             # Given directory not present 
         os.mkdir(install_dir, 0755)
-    
+    install_dir = os.path.abspath(install_dir)
     available_libs = util.get_available_libs()    # already available 
dependencies
     installed_files = list()    # List of files that are installed from package
     all_objects = metadata.binary_objects + metadata.other_objects
@@ -244,9 +245,49 @@
                                    map(lambda group: group.name, 
selected_groups))
     print "Installation Successful!"
     print "GNUNET has been installed at: " + install_dir
+    print ("Press [Y] to add "+ install_dir + "/bin to PATH in"
+           "~/.profile.d/gnunet OR any other key to continue without adding")
+    ch = getch_()
+    if ch in ['Y', 'y']:
+        home = os.environ['HOME']
+        try:
+            os.mkdir(os.path.join(home, '.profile.d'))
+        except OSError:
+            pass
+        gnprofile_name = os.path.join(home, '.profile.d/gnunet.sh')
+        gnprofile_write_ok = False
+        try:
+            with open(gnprofile_name, 'w') as gnprofile:
+                gnprofile.write("#!/bin/sh\n")
+                gnprofile.write("# Added by gnunet-update installer\n")
+                gnprofile.write("export PATH=${PATH}:" + 
+                                os.path.join(install_dir, "bin\n"))
+                gnprofile.write("export GNUNET_PREFIX=" + install_dir + "\n")
+                gnprofile_write_ok = True
+        except IOError as (errno, errstr):
+            print "Writing failed while writing to "+ gnprofile_name
+            + "due to error: " + errstr
+        if gnprofile_write_ok:
+            os.chmod (gnprofile_name,
+                      stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR |
+                      stat.S_IXGRP | stat.S_IRGRP)
+            profile_name = os.path.join(home, ".profile")
+            try:
+                with open(profile_name, "a") as profile:                       
             
+                    profile.write("\n# Added by gnunet-update installer\n")
+                    profile.write("for part in $HOME/.profile.d/*.sh; do\n"
+                                  ". $part\n"
+                                  "done\n")
+            except IOError as (errno, errstr):
+                print "Writing failed while writing to "+ profile_name
+                + "due to error: " + errstr
     _shared_library_setup([os.path.join(install_dir, "lib"), 
                            dep_dir])
 
+def _getch_stdin():
+    return util.getch (sys.stdin, sys.stdin.fileno())
+
 if "__main__" == __name__:
-    stdin = sys.stdin
+    global getch_
+    getch_ = _getch_stdin
     main()

Modified: gnunet-update/src/gnunet_update/util.py
===================================================================
--- gnunet-update/src/gnunet_update/util.py     2012-12-06 15:21:32 UTC (rev 
25300)
+++ gnunet-update/src/gnunet_update/util.py     2012-12-06 16:06:23 UTC (rev 
25301)
@@ -358,30 +358,32 @@
 import termios
 import fcntl
 
-def getch(rfile):
+def getch(rfile, fd=None):
     """Returns a character read from file like UNIX-style fgetch() function
 
     rfile: the file to read from
+    fd: The fileno() of rfile. Can be None for testing using StringIO objects
     """
-    fd = rfile.fileno()
-    oldterm = termios.tcgetattr(fd)
-    newattr = termios.tcgetattr(fd)
-    newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
-    termios.tcsetattr(fd, termios.TCSANOW, newattr)
-    oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
-    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
+    if fd is not None:
+        oldterm = termios.tcgetattr(fd)
+        newattr = termios.tcgetattr(fd)
+        newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
+        termios.tcsetattr(fd, termios.TCSANOW, newattr)
+        oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
+        fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
     input_ok = False
     try:        
         while True:
             try:
-                c = sys.stdin.read(1)
+                c = rfile.read(1)
                 input_ok = True
                 break
             except IOError: 
                 pass
     finally:
-        termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
-        fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
+        if fd is not None:
+            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
+            fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
     if input_ok:
         return c
     return None

Modified: gnunet-update/src/tests/test_regression.py
===================================================================
--- gnunet-update/src/tests/test_regression.py  2012-12-06 15:21:32 UTC (rev 
25300)
+++ gnunet-update/src/tests/test_regression.py  2012-12-06 16:06:23 UTC (rev 
25301)
@@ -31,11 +31,13 @@
 import tempfile
 import sys
 import shutil
+import StringIO
 
 import __init__
 import gnunet_update.package
 import gnunet_update.install
 import gnunet_update.update
+import gnunet_update.util as util
 
 class TestRegression(unittest.TestCase):
     """UnitTest class"""
@@ -121,10 +123,25 @@
             # installation location
             os.path.join(self.install_dir, "install-prefix")
             ]
-        gnunet_update.install.stdin = sys.stdin
+        testhomedir = os.environ['HOME']
+        try:
+            os.unlink (os.path.join(testhomedir, ".profile"))
+        except:
+            pass
+        try:
+            shutil.rmtree (os.path.join(testhomedir, ".profile.d"))
+        except:
+            pass
+        strio = StringIO.StringIO("Y")
+        def _getch_strio():
+            return util.getch (strio)
+        gnunet_update.install.getch_ = _getch_strio
         gnunet_update.install.main()
+        # The following file should be created by the installer
+        fd = open (os.path.join(testhomedir, '.profile'))
+        fd.close()
+        strio.close()
 
-
         # Update old package installation to new package installation
         sys.argv = ["update"] + self.common_argv + [
             # The new package file




reply via email to

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