Package libxyz :: Module pselector
[hide private]
[frames] | no frames]

Source Code for Module libxyz.pselector

  1  #-*- coding: utf8 -* 
  2  # 
  3  # Max E. Kuznecov ~syhpoon <syhpoon@syhpoon.name> 2008 
  4  # 
  5  # This file is part of XYZCommander. 
  6  # XYZCommander is free software: you can redistribute it and/or modify 
  7  # it under the terms of the GNU Lesser Public License as published by 
  8  # the Free Software Foundation, either version 3 of the License, or 
  9  # (at your option) any later version. 
 10  # XYZCommander is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 13  # GNU Lesser Public License for more details. 
 14  # You should have received a copy of the GNU Lesser Public License 
 15  # along with XYZCommander. If not, see <http://www.gnu.org/licenses/>. 
 16   
 17  """ 
 18  Class is used to select first appropriate path. 
 19  """ 
 20   
 21  import os 
 22  import os.path 
 23   
 24  from libxyz import const 
 25   
26 -class PathSelector(object):
27 """ 28 Class is used to select first appropriate path. 29 Common rule is to load system file first and then user's one 30 """ 31
32 - def __init__(self):
33 self.user_dir = os.path.join(os.path.expanduser("~"), const.USER_DIR) 34 self.system_dir = const.SYSTEM_DIR 35 self.conf_dir = const.CONF_DIR 36 self.skins_dir = const.SKINS_DIR 37 self.plugins_dir = const.PLUGINS_DIR 38 self.locale_dir = const.LOCALE_DIR
39 40 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 41
42 - def get_conf(self, conf):
43 """ 44 Return tuple of (system_conf_path, user_conf_path) 45 """ 46 47 return self._get(self.conf_dir, conf)
48 49 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 50
51 - def get_skin(self, skin):
52 """ 53 Return tuple of (system_skin_path, user_skin_path) 54 """ 55 56 return self._get(self.skins_dir, skin)
57 58 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 59
60 - def _get(self, subdir, obj):
61 _userpath = os.path.join(self.user_dir, subdir, obj) 62 _systempath = os.path.join(self.system_dir, subdir, obj) 63 64 return (_systempath, _userpath)
65 66 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 67
68 - def get_first_of(self, files):
69 """ 70 Return first existing file from supplied files or False in none exist 71 """ 72 73 for _file in files: 74 if os.access(_file, os.R_OK): 75 return _file 76 77 return None
78 79 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 80
81 - def get_plugins_dir(self):
82 _userpath = os.path.join(self.user_dir, self.plugins_dir) 83 _systempath = os.path.join(self.system_dir, self.plugins_dir) 84 85 return [_userpath, _systempath]
86 87 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 88
89 - def get_skins_dir(self):
90 _userpath = os.path.join(self.user_dir, self.skins_dir) 91 _systempath = os.path.join(self.system_dir, self.skins_dir) 92 93 return [_userpath, _systempath]
94 95 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96
97 - def get_locale_dir(self):
98 return os.path.join(self.system_dir, self.locale_dir)
99