gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r18085 - in gnunet-update: . bin etc gnunet_update share sh


From: gnunet
Subject: [GNUnet-SVN] r18085 - in gnunet-update: . bin etc gnunet_update share share/gnunet-update test test/confs test/confs/gnunet-update-home test/confs/gnunet-update-home/etc test/confs/gnunet-update-home/share test/confs/gnunet-update-home/share/gnunet-update test/confs/user-home test/confs/user-home/.gnunet-update
Date: Wed, 9 Nov 2011 23:40:14 +0100

Author: harsha
Date: 2011-11-09 23:40:14 +0100 (Wed, 09 Nov 2011)
New Revision: 18085

Added:
   gnunet-update/etc/
   gnunet-update/etc/gnunet-update.conf
   gnunet-update/gnunet_update/config.py
   gnunet-update/share/
   gnunet-update/share/gnunet-update/
   gnunet-update/share/gnunet-update/defaults.conf
   gnunet-update/test/confs/
   gnunet-update/test/confs/gnunet-update-home/
   gnunet-update/test/confs/gnunet-update-home/etc/
   gnunet-update/test/confs/gnunet-update-home/etc/gnunet-update.conf
   gnunet-update/test/confs/gnunet-update-home/share/
   gnunet-update/test/confs/gnunet-update-home/share/gnunet-update/
   gnunet-update/test/confs/gnunet-update-home/share/gnunet-update/defaults.conf
   gnunet-update/test/confs/user-home/
   gnunet-update/test/confs/user-home/.gnunet-update/
   gnunet-update/test/confs/user-home/.gnunet-update/gnunet-update.conf
   gnunet-update/test/test_config.py
Modified:
   gnunet-update/bin/gnunet-update
   gnunet-update/gnunet_update/install.py
Log:
added unit test case for config parsing

Modified: gnunet-update/bin/gnunet-update
===================================================================
--- gnunet-update/bin/gnunet-update     2011-11-09 22:12:05 UTC (rev 18084)
+++ gnunet-update/bin/gnunet-update     2011-11-09 22:40:14 UTC (rev 18085)
@@ -31,7 +31,7 @@
        if [ -L $EXEC_NAME ]
        then
                #Follow the symbolic link
-               REAL_EXEC=`realpath $EXEC_NAME`
+               REAL_EXEC=`readlink -f $EXEC_NAME`
                $REAL_EXEC $@
                exit $?
        elif [ ${EXEC_NAME:0:1} == '/' ] # Absolute path

Added: gnunet-update/etc/gnunet-update.conf
===================================================================
--- gnunet-update/etc/gnunet-update.conf                                (rev 0)
+++ gnunet-update/etc/gnunet-update.conf        2011-11-09 22:40:14 UTC (rev 
18085)
@@ -0,0 +1,37 @@
+# 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:    etc/gnunet-update.conf
+# Author:  Sree Harsha Totakura
+
+# Default configuration file
+
+# This section is for signing
+
+[CONFIG]
+# Use this setting to additionally load configuration from user specific files
+# %(HOME)s will be expanded to the value set to the $HOME env variable
+USER_CONFIG_FILE = %(HOME)s/.gnunet-update/gnunet-update.conf
+
+[SECURITY]
+# Specify which GPG key to use for signing by its Fingerprint
+# PGP_SIGN_KEY = 8E68 1D8A 25AB B102 AFB5  4B40 3B6F 8AF1 43C2 1F3B
+
+# If you don't want to be prompted for your private key password during
+# signing, you may specify your private key password here
+# PGP_SIGN_KEY_PASSWORD = private_key_secret

Added: gnunet-update/gnunet_update/config.py
===================================================================
--- gnunet-update/gnunet_update/config.py                               (rev 0)
+++ gnunet-update/gnunet_update/config.py       2011-11-09 22:40:14 UTC (rev 
18085)
@@ -0,0 +1,63 @@
+# 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:    gnunet_update/config.py
+# Author:  Sree Harsha Totakura
+
+
+"""Library for holding gnunet-update configuration."""
+
+import ConfigParser
+import os
+
+
+class GnunetUpdateConfig:
+    """Class for holding configuration."""
+    
+    def __init__(self):
+        """Constructor."""
+        self._set_defaults()
+        self._config_parser = ConfigParser.SafeConfigParser(self._defaults)
+        # Read the bare defaults
+        bare_conf_fd = open(os.path.join(os.environ['GNUNET_UPDATE_HOME'],
+                                         'share/gnunet-update/defaults.conf'),
+                             "rb")
+        self._config_parser.readfp(bare_conf_fd)
+        bare_conf_fd.close()
+        # Read the main configuration
+        self._config_parser.read(os.path.join(os.environ['GNUNET_UPDATE_HOME'],
+                                                'etc/gnunet-update.conf'))
+
+        if self._config_parser.get('CONFIG', 'USER_CONFIG_FILE') is not None:
+            self._config_parser.read(self._config_parser.get('CONFIG',
+                                                               
'USER_CONFIG_FILE'))
+
+    def _set_defaults(self):
+        """Sets the defaults. It is important to do this at run time."""
+        # The dictionary holding defaults. Every key which is ever used should
+        # have a default value here
+        self._defaults = {
+            'HOME' : os.environ['HOME'],
+            'USER_CONFIG_FILE': None,
+            'PGP_SIGN_KEY': None,
+            'PGP_SIGN_KEY_PASSWORD' : None
+            }
+    
+    def get(self, section, key):
+        """Returns the value of key in section."""
+        return self._config_parser.get(section, key)

Modified: gnunet-update/gnunet_update/install.py
===================================================================
--- gnunet-update/gnunet_update/install.py      2011-11-09 22:12:05 UTC (rev 
18084)
+++ gnunet-update/gnunet_update/install.py      2011-11-09 22:40:14 UTC (rev 
18085)
@@ -21,7 +21,6 @@
 #
 #Python sript for installing the packages packed using package script
 #
-#TODO: run ldconfig on the installed dependency directory
 
 import tarfile
 import sys
@@ -166,6 +165,10 @@
             os.remove(dep.name)
         os.symlink(dep.realname, dep.name)
 
+    # run ldconfig -n in the dep_dir
+    proc = subprocess.Popen(["ldconfig", "-n"])
+    proc.wait()
+
     os.chdir(orig_working_dir)
     package_tarfile.close()
 

Added: gnunet-update/share/gnunet-update/defaults.conf
===================================================================
--- gnunet-update/share/gnunet-update/defaults.conf                             
(rev 0)
+++ gnunet-update/share/gnunet-update/defaults.conf     2011-11-09 22:40:14 UTC 
(rev 18085)
@@ -0,0 +1,30 @@
+# DO NOT EDIT THIS FILE!
+#
+# 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:    share/gnunet-update/defaults.conf
+# Author:  Sree Harsha Totakura
+# 
+# The default configuration file.
+#
+# Do NOT edit this file. For customization edit etc/gnunet-update.conf file
+
+[CONFIG]
+
+[SECURITY]
\ No newline at end of file

Added: gnunet-update/test/confs/gnunet-update-home/etc/gnunet-update.conf
===================================================================
--- gnunet-update/test/confs/gnunet-update-home/etc/gnunet-update.conf          
                (rev 0)
+++ gnunet-update/test/confs/gnunet-update-home/etc/gnunet-update.conf  
2011-11-09 22:40:14 UTC (rev 18085)
@@ -0,0 +1,40 @@
+# 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:    etc/gnunet-update.conf
+# Author:  Sree Harsha Totakura
+
+# Default configuration file
+
+# This section is for signing
+
+[CONFIG]
+# Use this setting to additionally load configuration from user specific files
+# %(HOME)s will be expanded to the value set to the $HOME env variable
+USER_CONFIG_FILE = %(HOME)s/.gnunet-update/gnunet-update.conf
+
+[SECURITY]
+# Specify which GPG key to use for signing by its Fingerprint
+# PGP_SIGN_KEY = 8E68 1D8A 25AB B102 AFB5  4B40 3B6F 8AF1 43C2 1F3B
+
+# If you don't want to be prompted for your private key password during
+# signing, you may specify your private key password here
+# PGP_SIGN_KEY_PASSWORD = private_key_secret
+
+[TEST]
+FOO = BAR

Added: 
gnunet-update/test/confs/gnunet-update-home/share/gnunet-update/defaults.conf
===================================================================
--- 
gnunet-update/test/confs/gnunet-update-home/share/gnunet-update/defaults.conf   
                            (rev 0)
+++ 
gnunet-update/test/confs/gnunet-update-home/share/gnunet-update/defaults.conf   
    2011-11-09 22:40:14 UTC (rev 18085)
@@ -0,0 +1,30 @@
+# DO NOT EDIT THIS FILE!
+#
+# 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:    share/gnunet-update/defaults.conf
+# Author:  Sree Harsha Totakura
+# 
+# The default configuration file.
+#
+# Do NOT edit this file. For customization edit etc/gnunet-update.conf file
+
+[CONFIG]
+
+[SECURITY]
\ No newline at end of file

Added: gnunet-update/test/confs/user-home/.gnunet-update/gnunet-update.conf
===================================================================
--- gnunet-update/test/confs/user-home/.gnunet-update/gnunet-update.conf        
                        (rev 0)
+++ gnunet-update/test/confs/user-home/.gnunet-update/gnunet-update.conf        
2011-11-09 22:40:14 UTC (rev 18085)
@@ -0,0 +1,7 @@
+
+[SECURITY]
+PGP_SIGN_KEY = ABCDEFGHIJKLMNOPQRSTUV
+PGP_SIGN_KEY_PASSWORD = test
+
+[TEST]
+FOO = FOO

Added: gnunet-update/test/test_config.py
===================================================================
--- gnunet-update/test/test_config.py                           (rev 0)
+++ gnunet-update/test/test_config.py   2011-11-09 22:40:14 UTC (rev 18085)
@@ -0,0 +1,75 @@
+# 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:    gnunet_update/tests/test_config.py
+# Author:  Sree Harsha Totakura
+
+
+"""Test cases for config.py."""
+
+import unittest
+import os
+import ConfigParser
+
+from gnunet_update.config import GnunetUpdateConfig
+
+
+pwd = os.path.dirname(__file__)
+
+class TestConfig(unittest.TestCase):
+    
+    def setUp(self):
+        # Modify HOME to point to testing home
+        os.environ['HOME'] = os.path.join(pwd, 'confs/user-home')
+        # Modify 
+        os.environ['GNUNET_UPDATE_HOME'] = os.path.join(pwd,
+                                                        
'confs/gnunet-update-home')
+
+
+    def test_config_init(self):
+        """Test if the Config constructor is working."""
+        config = GnunetUpdateConfig()
+        # Test if interpolation is working
+        self.assertEqual(config.get('CONFIG', 'USER_CONFIG_FILE'),
+                         os.path.join(pwd, 
'confs/user-home/.gnunet-update/gnunet-update.conf'))
+
+    def test_config_overwrite(self):
+        """Test if a recent configuration overwrites existing options."""
+        config = GnunetUpdateConfig()
+        self.assertEqual(config.get('TEST', 'FOO'), 'FOO')
+
+    def test_config_new(self):
+        """Test if values added by recent configuration are available."""
+        config = GnunetUpdateConfig()
+        self.assertEqual(config.get('SECURITY', 'PGP_SIGN_KEY'), 
+                         'ABCDEFGHIJKLMNOPQRSTUV')
+
+    def test_config_exception(self):
+        """Test if exception is raised for non existing sections and 
options."""
+        config = GnunetUpdateConfig()
+        # Test for non existing section
+        self.assertRaises(ConfigParser.NoSectionError,
+                          config.get, 'ABC', 'XYZ')
+        # Test for non existing option
+        self.assertRaises(ConfigParser.NoOptionError,
+                          config.get, 'TEST', 'XYZ')
+        
+        
+
+if __name__ == '__main__':
+    unittest.main()


Property changes on: gnunet-update/test/test_config.py
___________________________________________________________________
Added: svn:executable
   + *




reply via email to

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