gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r25294 - in gnunet-update/src: gnunet_update tests
Date: Thu, 6 Dec 2012 14:28:50 +0100

Author: harsha
Date: 2012-12-06 14:28:50 +0100 (Thu, 06 Dec 2012)
New Revision: 25294

Modified:
   gnunet-update/src/gnunet_update/install.py
   gnunet-update/src/gnunet_update/util.py
   gnunet-update/src/tests/test_regression.py
Log:
- manipulatable input

Modified: gnunet-update/src/gnunet_update/install.py
===================================================================
--- gnunet-update/src/gnunet_update/install.py  2012-12-06 13:16:17 UTC (rev 
25293)
+++ gnunet-update/src/gnunet_update/install.py  2012-12-06 13:28:50 UTC (rev 
25294)
@@ -35,7 +35,10 @@
 from config import GnunetUpdateConfig
 from file import ExecutableFileObject, FileObject
 
-def usage():
+# Used for testing; Should be set to sys.stdin if running directly
+stdin = None
+
+def _usage():
     """Print helpful usage information."""    
     print """
 Usage arguments: [options] <package_file> [install/location]
@@ -52,7 +55,7 @@
     -g, --group=GROUP         : install GROUP (multiple options are allowed)
 """
 
-def shared_library_setup(shared_library_paths):
+def _shared_library_setup(shared_library_paths):
     print ("Shared libraries have been installed into the following path(s):")
     for path in shared_library_paths: print path
     print (
@@ -77,7 +80,7 @@
     external_config_file = None
     list_groups = False
     install_group_names = set()
-
+    assert stdin is not None
     try:
         opts, args = getopt.getopt(sys.argv[1:], 
                                    "c:g:lh", 
@@ -88,12 +91,12 @@
     except getopt.GetoptError, err:
         print err
         print "Execption occured"
-        usage()
+        _usage()
         sys.exit(1)
         
     for option, value in opts:
         if option in ("-h", "--help"):
-            usage()
+            _usage()
             sys.exit(0)
         elif option in ("-c", "--config"):
             external_config_file = value
@@ -105,11 +108,11 @@
     if list_groups:
         if len(args) < 1:
             print "Incorrect number of arguments"
-            usage()
+            _usage()
             sys.exit(1)
     elif len(args) != 2:
         print "Incorrect number of arguments"
-        usage()
+        _usage()
         sys.exit(1)
     
     config = GnunetUpdateConfig(external_config_file) # Configuration
@@ -121,7 +124,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()
+        ch = util.getch(sys.stdin)
         if ch is None:
             sys.exit(0)
         if ch not in ['Y', 'y']:
@@ -241,8 +244,9 @@
                                    map(lambda group: group.name, 
selected_groups))
     print "Installation Successful!"
     print "GNUNET has been installed at: " + install_dir
-    shared_library_setup([os.path.join(install_dir, "lib"), 
-                          dep_dir])
+    _shared_library_setup([os.path.join(install_dir, "lib"), 
+                           dep_dir])
 
 if "__main__" == __name__:
+    stdin = sys.stdin
     main()

Modified: gnunet-update/src/gnunet_update/util.py
===================================================================
--- gnunet-update/src/gnunet_update/util.py     2012-12-06 13:16:17 UTC (rev 
25293)
+++ gnunet-update/src/gnunet_update/util.py     2012-12-06 13:28:50 UTC (rev 
25294)
@@ -358,9 +358,12 @@
 import termios
 import fcntl
 
-def getch():
-    """Returns a character read from stdin like UNIX-style getch() function"""
-    fd = sys.stdin.fileno()
+def getch(rfile):
+    """Returns a character read from file like UNIX-style fgetch() function
+
+    rfile: the file to read from
+    """
+    fd = rfile.fileno()
     oldterm = termios.tcgetattr(fd)
     newattr = termios.tcgetattr(fd)
     newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO

Modified: gnunet-update/src/tests/test_regression.py
===================================================================
--- gnunet-update/src/tests/test_regression.py  2012-12-06 13:16:17 UTC (rev 
25293)
+++ gnunet-update/src/tests/test_regression.py  2012-12-06 13:28:50 UTC (rev 
25294)
@@ -121,6 +121,7 @@
             # installation location
             os.path.join(self.install_dir, "install-prefix")
             ]
+        gnunet_update.install.stdin = sys.stdin
         gnunet_update.install.main()
 
 




reply via email to

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