1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 """\
21 L{X2GoSessionProfiles} class - managing x2goclient session profiles.
22
23 L{X2GoSessionProfiles} is a public API class. Use this class in your Python X2Go based
24 applications.
25
26 """
27 __NAME__ = 'x2gosessionprofiles-pylib'
28
29 import random
30
31
32 from x2go.defaults import X2GO_SESSIONPROFILES_CONFIGFILES as _X2GO_SESSIONPROFILES_CONFIGFILES
33 import x2go.backends.profiles.base as base
34 import x2go.inifiles as inifiles
35 import x2go.log as log
36
38
39 - def __init__(self, config_files=_X2GO_SESSIONPROFILES_CONFIGFILES, session_profile_defaults=None, logger=None, loglevel=log.loglevel_DEFAULT, **kwargs):
40 """\
41 Retrieve X2Go session profiles from a file, typically C{~/.x2goclient/sessions}.
42
43 @param config_files: a list of config file locations, the first file name in this list the user has write access to will be the user configuration file
44 @type config_files: C{list}
45 @param session_profile_defaults: a default session profile
46 @type session_profile_defaults: C{dict}
47 @param logger: you can pass an L{X2GoLogger} object to the
48 L{x2go.backends.profiles.file.X2GoSessionProfiles} constructor
49 @type logger: L{X2GoLogger} instance
50 @param loglevel: if no L{X2GoLogger} object has been supplied a new one will be
51 constructed with the given loglevel
52 @type loglevel: C{int}
53
54 """
55
56
57 inifiles.X2GoIniFile.__init__(self, config_files=config_files, logger=logger, loglevel=loglevel)
58 base.X2GoSessionProfiles.__init__(self, session_profile_defaults=session_profile_defaults, logger=logger, loglevel=loglevel)
59
61 """\
62 Override the inifile class's get_type method due to the special layout of the session profile
63 class.
64
65 @param section: INI file section
66 @type section: C{str}
67 @param key: key in INI file section
68 @type key: C{str}
69
70 @return: the data type of C{key} in C{section}
71 @rtype: C{type}
72
73 """
74
75 return self.get_profile_option_type(key)
76
78 """\
79 Populate the set of session profiles by loading the session
80 profile configuration from a file in INI format.
81
82 @return: a set of session profiles
83 @rtype: C{dict}
84
85 """
86 session_profiles = [ p for p in self.iniConfig.sections() if p not in self._non_profile_sections and p != 'none' ]
87 _session_profiles_dict = {}
88 for session_profile in session_profiles:
89 for key, default_value in self.defaultSessionProfile.iteritems():
90 if not self.iniConfig.has_option(session_profile, key):
91 self._storeValue(session_profile, key, default_value)
92
93 self.get_profile_metatype(session_profile)
94 _session_profiles_dict[session_profile] = self.get_profile_config(session_profile)
95
96 return _session_profiles_dict
97
100
103
107
109 self.iniConfig.remove_section(profile_id)
110 try: del self.session_profiles[profile_id]
111 except KeyError: pass
112
114 self.session_profiles[profile_id][option] = value
115 if option == 'host':
116 value = ','.join(value)
117 self._X2GoIniFile__update_value(profile_id, option, value)
118
120 return self.get(profile_id, option, key_type)
121
123 return [ o for o in self.iniConfig.options(profile_id) if o != "none" ]
124
126 return [ s for s in self.iniConfig.sections() if s != "none" ]
127
130
133