Commits

leafstorm  committed e882560

added clap.sysinfo module

  • Participants
  • Parent commits d7bb527

Comments (0)

Files changed (1)

File lib/clap/sysinfo.py

+"""
+clap.sysinfo
+============
+This is used for platform detection and other platform-specific information,
+such as preferred user data paths.
+
+:copyright: 2010 Matthew "LeafStorm" Frazier
+:license:   MIT/X11, see COPYING for details
+"""
+import os
+import os.path
+import platform
+
+#: This is the actual value of `platform.system`. This could be "Windows",
+#: "Microsoft", "Darwin", "FreeBSD", and so on.
+SYSTEM = platform.system()
+
+#: Whether or not Clap is running on Windows.
+WINDOWS = SYSTEM in frozenset(('Microsoft', 'Windows'))
+
+#: Whether or not Clap is running on Mac OS X.
+MACOSX = SYSTEM == 'Darwin'
+
+
+if WINDOWS:
+    #: This is the user's home directory (or user profile, if Windows).
+    HOME = os.environ['USERPROFILE']
+else:
+    HOME = os.environ['HOME']
+
+if WINDOWS:
+    #: The preferred path for user configuration. On Windows, this is the
+    #: environment variable `APPDATA`. On Mac OS X, it is
+    #: ``~/Library/Preferences``. On any other system, it is the value of
+    #: `XDG_CONFIG_HOME` or ``~/.config`` if that is not defined.
+    USER_CONFIG = os.environ['APPDATA']
+    
+    #: The preferred path for user data. On Windows, this is, again,
+    #: `APPDATA`. On Mac OS X, it is ``~/Library/Application Support``.
+    #: On any other system, it is `XDG_DATA_HOME` or ``~/.local/share``.
+    USER_DATA = os.environ['APPDATA']
+    
+    #: The preferred path for the user's cached data. On Windows, this is
+    #: `LOCALAPPDATA` if available and `APPDATA` if not. On Mac OS X, it is
+    #: ``~/Library/Caches``. On any other system, it is `XDG_CACHE_HOME` or
+    #: ``~/.cache``.
+    USER_CACHE = os.environ.get('LOCALAPPDATA') or os.environ['APPDATA']
+
+elif MACOSX:
+    USER_CONFIG = os.path.join(HOME, 'Library', 'Preferences')
+    USER_DATA = os.path.join(HOME, 'Library', 'Application Support')
+    USER_CACHE = os.path.join(HOME, 'Library', 'Caches')
+
+else:
+    USER_CONFIG = os.environ.get('XDG_CONFIG_HOME',
+                                 os.path.join(HOME, '.config'))
+    USER_DATA = os.environ.get('XDG_DATA_HOME',
+                               os.path.join(HOME, '.local', 'share'))
+    USER_CACHE = os.environ.get('XDG_CACHE_HOME',
+                                os.path.join(HOME, '.cache'))