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 39 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 40
41 - def get_conf(self, conf):
42 """ 43 Return tuple of (system_conf_path, user_conf_path) 44 """ 45 46 return self._get(self.conf_dir, conf)
47 48 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 49
50 - def get_skin(self, skin):
51 """ 52 Return tuple of (system_skin_path, user_skin_path) 53 """ 54 55 return self._get(self.skins_dir, skin)
56 57 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 58
59 - def _get(self, subdir, obj):
60 _userpath = os.path.join(self.user_dir, subdir, obj) 61 _systempath = os.path.join(self.system_dir, subdir, obj) 62 63 return (_systempath, _userpath)
64 65 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 66
67 - def get_first_of(self, files):
68 """ 69 Return first existing file from supplied files or False in none exist 70 """ 71 72 for _file in files: 73 if os.access(_file, os.R_OK): 74 return _file 75 76 return None
77 78 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 79
80 - def get_plugins_dir(self):
81 _userpath = os.path.join(self.user_dir, self.plugins_dir) 82 _systempath = os.path.join(self.system_dir, self.plugins_dir) 83 84 return [_userpath, _systempath]
85 86 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 87
88 - def get_skins_dir(self):
89 _userpath = os.path.join(self.user_dir, self.skins_dir) 90 _systempath = os.path.join(self.system_dir, self.skins_dir) 91 92 return [_userpath, _systempath]
93