summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2013-02-16 23:18:57 +0000
committerIsis Lovecruft <isis@torproject.org>2013-02-16 23:18:57 +0000
commit2773a3d35a2c87100da520b7e947d1d77f52e134 (patch)
treea5caf2e4c94adfab2973a43d1e1f3f4e4cec1013 /src
parentd3bc6e22b618771e02b2941f573759a8021e8752 (diff)
Moved client platform detection code to leap/mx/util/config.py.
* Remove extraneous storage.Storage() initializations. * Autosetup calls to config._get_config_location based on whether config.filename has been set elsewhere.
Diffstat (limited to 'src')
-rw-r--r--src/leap/mx/util/config.py44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/leap/mx/util/config.py b/src/leap/mx/util/config.py
index 3eb4cdb..9bf90e8 100644
--- a/src/leap/mx/util/config.py
+++ b/src/leap/mx/util/config.py
@@ -42,11 +42,36 @@ filename = None
basic = storage.Storage()
advanced = storage.Storage()
-def _create_config_file(file):
+PLATFORMS = {'LINUX': sys.platform.startswith("linux"),
+ 'OPENBSD': sys.platform.startswith("openbsd"),
+ 'FREEBSD': sys.platform.startswith("freebsd"),
+ 'NETBSD': sys.platform.startswith("netbsd"),
+ 'DARWIN': sys.platform.startswith("darwin"),
+ 'SOLARIS': sys.platform.startswith("sunos"),
+ 'WINDOWS': sys.platform.startswith("win32")}
+
+def getClientPlatform(platform_name=None):
+ """
+ Determine the client's operating system platform. Optionally, if
+ :param:`platform_name` is given, check that this is indeed the platform
+ we're operating on.
+
+ @param platform_name: A string, upper-, lower-, or mixed case, of one
+ of the keys in the :attr:`leap.util.version.PLATFORMS`
+ dictionary. E.g. 'Linux' or 'OPENBSD', etc.
+ @returns: A string specifying the platform name, and the boolean test
+ used to determine it.
+ """
+ for name, test in PLATFORMS.items():
+ if not platform_name or platform_name.upper() == name:
+ if test:
+ return name, test
+
+def _create_config_file(conffile):
"""
xxx fill me in
"""
- with open(file, 'w+') as conf:
+ with open(conffile, 'w+') as conf:
conf.write("""
#
# mx.conf
@@ -72,12 +97,6 @@ advanced:
""")
conf.flush()
- try:
- assert os.path.isfile(file), "Config file %s not created!" % file
- except AssertionError, ae:
- raise SystemExit(ae.message)
- else:
- return file
def _get_config_filename(filename=None, use_dot_config_directory=False):
"""
@@ -147,14 +166,12 @@ def loadConfig(filename=config_filename):
## from leap.util import config
## config.basic.foo = bar
##
- basic = Storage()
try:
for k, v in configuration['basic'].items():
basic[k] = v
except AttributeError:
pass
- advanced = Storage()
try:
for k, v in configuration['advanced'].items():
advanced[k] = v
@@ -168,8 +185,7 @@ def loadConfig(filename=config_filename):
## This is the name of the config file to use:
## If not set, it defaults to 'leap_mx/leap_mx.conf'
-if not config_filename:
- config_filename = _get_config_filename()
+if not filename:
+ filename = _get_config_location()
else:
- config_filename = _get_config_filename(filename=config_filename)
-
+ filename = _get_config_location(config_filename=filename)