[X2Go-Commits] x2gobroker.git - build-main (branch) updated: d9a975b5e648d5ee0a207814da8f85abc81e9f64

X2Go dev team git-admin at x2go.org
Sun May 19 13:03:01 CEST 2013


The branch, build-main has been updated
       via  d9a975b5e648d5ee0a207814da8f85abc81e9f64 (commit)
      from  2b35e46b3b90f217ed03b610a2f9ca699fe232f0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
-----------------------------------------------------------------------

Summary of changes:
 x2gobroker/backends/base.py              |   13 +++++++
 x2gobroker/backends/inifile.py           |   11 +-----
 x2gobroker/config.py                     |   22 ++++++++++--
 x2gobroker/tests/test_backend_inifile.py |   57 ++++++++++++++++++++++++++++++
 4 files changed, 91 insertions(+), 12 deletions(-)

The diff of changes is:
diff --git a/x2gobroker/backends/base.py b/x2gobroker/backends/base.py
index ee824f9..b590fdb 100644
--- a/x2gobroker/backends/base.py
+++ b/x2gobroker/backends/base.py
@@ -131,6 +131,19 @@ class X2GoBroker(object):
         """
         return {}
 
+    def get_profile(self, profile_id):
+        """\
+        Get the session profile for profile ID <profile_id>.
+
+        @param profile_id: the ID of a profile, in other words the section name in the configuration file
+        @type profile_id: C{unicode}
+
+        @return: a dictionary representing the session profile for ID <profile_id>
+        @rtype: C{dict}
+
+        """
+        return {}
+
     def test_connection(self):
         #if($cgi->param('task') eq 'testcon')
         #{
diff --git a/x2gobroker/backends/inifile.py b/x2gobroker/backends/inifile.py
index b5100a8..5d2f451 100644
--- a/x2gobroker/backends/inifile.py
+++ b/x2gobroker/backends/inifile.py
@@ -62,17 +62,8 @@ class X2GoBroker(base.X2GoBroker):
 
         return self.session_profiles.get_defaults()
 
-    def get_profile_config(self, profile_id):
-        """\
-        Get the session profile for profile ID <profile_id>.
-
-        @param profile_id: the ID of a profile, in other words the section name in the configuration file
-        @type profile_id: C{unicode}
+    def get_profile(self, profile_id):
 
-        @return: a dictionary representing the session profile for ID <profile_id>
-        @rtype: C{dict}
-
-        """
         return self.session_profiles.get_section(profile_id)
 
     def list_profiles(self, username):
diff --git a/x2gobroker/config.py b/x2gobroker/config.py
index b0ed1f8..0feded0 100644
--- a/x2gobroker/config.py
+++ b/x2gobroker/config.py
@@ -160,7 +160,7 @@ class X2GoBrokerConfigFile(object):
         method.
 
         """
-        for section, sectionvalue in self.defaultValues.items():
+        for section, sectionvalue in [ (key, value) for (key, value) in self.defaultValues.items() if key.upper() != 'DEFAULT' ]:
             for key, value in sectionvalue.items():
                 if self.iniConfig.has_option(section, key): continue
                 if not self.iniConfig.has_section(section):
@@ -213,7 +213,13 @@ class X2GoBrokerConfigFile(object):
         @rtype: class
 
         """
-        return type(self.defaultValues[section][key])
+        if section in self.defaultValues.keys():
+            return type(self.defaultValues[section][key])
+        else:
+            try:
+                return type(self.defaultValues['DEFAULT'][key])
+            except KeyError:
+                return None
 
     def has_value(self, section, key):
         """\
@@ -248,12 +254,23 @@ class X2GoBrokerConfigFile(object):
         """
         if key_type is None:
             key_type = self.get_type(section, key)
+
         if self.iniConfig.has_option(section, key) or section == 'DEFAULT':
+
+            if key_type is None:
+
+                return self.iniConfig.get(section, key)
+
             if key_type is types.BooleanType:
+
                 return self.iniConfig.getboolean(section, key)
+
             elif key_type is types.IntType:
+
                 return self.iniConfig.getint(section, key)
+
             elif key_type is types.ListType:
+
                 _val = self.iniConfig.get(section, key)
                 _val = _val.strip()
                 if _val.startswith('[') and _val.endswith(']'):
@@ -263,6 +280,7 @@ class X2GoBrokerConfigFile(object):
                 else:
                     _val = [ _val ]
                 return _val
+
             else:
                 _val = self.iniConfig.get(section, key)
                 return _val.decode(x2gobroker.utils.get_encoding())
diff --git a/x2gobroker/tests/test_backend_inifile.py b/x2gobroker/tests/test_backend_inifile.py
index 8110902..12f55c7 100644
--- a/x2gobroker/tests/test_backend_inifile.py
+++ b/x2gobroker/tests/test_backend_inifile.py
@@ -19,6 +19,7 @@
 
 import unittest
 import tempfile
+import copy
 
 # Python X2GoBroker modules
 import x2gobroker.backends.inifile
@@ -49,6 +50,62 @@ class TestX2GoBrokerBackendInifile(unittest.TestCase):
         for _param in _expected_profile_defaults:
             self.assertTrue( ( _param in _profile_defaults.keys() and _profile_defaults[_param] == _expected_profile_defaults[_param] ) )
 
+    ### TEST SESSION PROFILES: get_profile(profile_id)
+
+    def test_getprofile(self):
+        _session_profiles = """
+[DEFAULT]
+exports =
+fullscreen = false
+width = 800
+height = 600
+applications = TERMINAL, WWWBROWSER
+
+[testprofile1]
+user = foo
+cmd = GNOME
+
+[testprofile2]
+user = bar
+cmd = KDE
+fullscreen = true
+"""
+        tf = tempfile.NamedTemporaryFile()
+        print >> tf, _session_profiles
+        tf.seek(0)
+        inifile_backend = x2gobroker.backends.inifile.X2GoBroker(profile_config_file=tf.name)
+        _expected_defaults = {
+            'exports': '',
+            'fullscreen': False,
+            'width': 800,
+            'height': 600,
+            'applications': ['TERMINAL','WWWBROWSER',]
+        }
+        _expected_profile1 = copy.deepcopy(_expected_defaults)
+        _expected_profile1.update({
+            'user': 'foo',
+            'cmd': 'GNOME',
+        })
+        _expected_profile2 = copy.deepcopy(_expected_defaults)
+        _expected_profile2.update({
+            'user': 'bar',
+            'cmd': 'KDE',
+            'fullscreen': True,
+        })
+        _profile1 = inifile_backend.get_profile('testprofile1')
+        del _profile1['default']
+        for key in _expected_profile1.keys():
+            self.assertTrue( ( key in _profile1.keys() ) )
+        for key in _profile1.keys():
+            self.assertTrue( ( key in _expected_profile1.keys()  and _profile1[key] == _expected_profile1[key] ) )
+
+        _profile2 = inifile_backend.get_profile('testprofile2')
+        del _profile2['default']
+        for key in _expected_profile2.keys():
+            self.assertTrue( ( key in _profile2.keys() ) )
+        for key in _profile2.keys():
+            self.assertTrue( ( key in _expected_profile2.keys() ) and ( _profile2[key] == _expected_profile2[key] ) )
+
     ### TEST: select_profile() method
 
 #    def test_profileselection(self):


hooks/post-receive
-- 
x2gobroker.git (HTTP(S) Session broker for X2Go)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "x2gobroker.git" (HTTP(S) Session broker for X2Go).




More information about the x2go-commits mailing list