Guest User

Untitled

a guest
Jun 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.89 KB | None | 0 0
  1. # Copyright (c) 2008, Aldo Cortesi. All rights reserved.
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. #
  10. # The above copyright notice and this permission notice shall be included in
  11. # all copies or substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. # SOFTWARE.
  20.  
  21. import os.path
  22. import sys
  23. import utils
  24.  
  25. class ConfigError(Exception): pass
  26.  
  27.  
  28. class Config:
  29.     keys = ()
  30.     mouse = ()
  31.     groups = None
  32.     layouts = None
  33.     screens = ()
  34.     main = None
  35.     follow_mouse_focus = True
  36.     cursor_warp = False
  37.  
  38.  
  39. class File(Config):
  40.     def __init__(self, fname=None):
  41.         if not fname:
  42.             config_directory = os.path.expandvars('$XDG_CONFIG_HOME')
  43.             if config_directory == '$XDG_CONFIG_HOME': #if variable wasn't set
  44.                 config_directory = os.path.expanduser("~/.config")
  45.             fname = os.path.join(config_directory, "qtile", "config.py")
  46.         elif fname == "default":
  47.             fname = utils.data.path("resources/default-config.py")
  48.  
  49.         self.fname = fname
  50.         globs = {}
  51.  
  52.         if not os.path.isfile(fname):
  53.             raise ConfigError("Config file does not exist: %s"%fname)
  54.         try:
  55.             sys.path.append(os.path.dirname(self.fname)) #to allow 'import'ing from the config dir
  56.             execfile(self.fname, {}, globs)
  57.         except Exception, v:
  58.             raise ConfigError(str(v))
  59.  
  60.  
  61.         self.keys = globs.get("keys")
  62.         self.mouse = globs.get("mouse", [])
  63.         self.groups = globs.get("groups")
  64.         self.follow_mouse_focus = globs.get("follow_mouse_focus", True)
  65.         self.cursor_warp = globs.get("cursor_warp", False)
  66.         self.layouts = globs.get("layouts")
  67.         self.floating_layout = globs.get('floating_layout', None)
  68.         if self.floating_layout is None:
  69.             from .layout import Floating
  70.             self.floating_layout = Floating()
  71.         self.screens = globs.get("screens")
  72.  
  73.         if not self.screens:
  74.             raise ConfigError("Cannot have no screens setup")
  75.        
  76.         self.main = globs.get("main")
Add Comment
Please, Sign In to add comment