Package entropy :: Package client :: Package interfaces :: Module client

Source Code for Module entropy.client.interfaces.client

  1  # -*- coding: utf-8 -*- 
  2  ''' 
  3      # DESCRIPTION: 
  4      # Entropy Object Oriented Interface 
  5   
  6      Copyright (C) 2007-2009 Fabio Erculiani 
  7   
  8      This program is free software; you can redistribute it and/or modify 
  9      it under the terms of the GNU General Public License as published by 
 10      the Free Software Foundation; either version 2 of the License, or 
 11      (at your option) any later version. 
 12   
 13      This program is distributed in the hope that it will be useful, 
 14      but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16      GNU General Public License for more details. 
 17   
 18      You should have received a copy of the GNU General Public License 
 19      along with this program; if not, write to the Free Software 
 20      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 21  ''' 
 22   
 23  from __future__ import with_statement 
 24  import os 
 25  from entropy.core import Singleton 
 26  from entropy.output import TextInterface 
 27  from entropy.db import dbapi2 
 28  from entropy.client.interfaces.loaders import LoadersMixin 
 29  from entropy.client.interfaces.cache import CacheMixin 
 30  from entropy.client.interfaces.dep import CalculatorsMixin 
 31  from entropy.client.interfaces.methods import RepositoryMixin, MiscMixin, \ 
 32      MatchMixin 
 33  from entropy.client.interfaces.fetch import FetchersMixin 
 34  from entropy.const import etpConst, etpCache 
 35  from entropy.core import SystemSettings, SystemSettingsPlugin 
 36  from entropy.misc import LogFile 
 37  from entropy.exceptions import SystemDatabaseError, RepositoryError 
 38   
39 -class ClientSystemSettingsPlugin(SystemSettingsPlugin):
40 41 import entropy.tools as entropyTools 42
43 - def system_mask_parser(self, system_settings_instance):
44 45 parser_data = {} 46 # match installed packages of system_mask 47 mask_installed = [] 48 mask_installed_keys = {} 49 while (self._helper.clientDbconn != None): 50 try: 51 self._helper.clientDbconn.validateDatabase() 52 except SystemDatabaseError: 53 break 54 mc_cache = set() 55 m_list = system_settings_instance['repos_system_mask'] + \ 56 system_settings_instance['system_mask'] 57 for atom in m_list: 58 m_ids, m_r = self._helper.clientDbconn.atomMatch(atom, 59 multiMatch = True) 60 if m_r != 0: 61 continue 62 mykey = self.entropyTools.dep_getkey(atom) 63 if mykey not in mask_installed_keys: 64 mask_installed_keys[mykey] = set() 65 for m_id in m_ids: 66 if m_id in mc_cache: 67 continue 68 mc_cache.add(m_id) 69 mask_installed.append(m_id) 70 mask_installed_keys[mykey].add(m_id) 71 break 72 73 parser_data.update({ 74 'repos_installed': mask_installed, 75 'repos_installed_keys': mask_installed_keys, 76 }) 77 return parser_data
78
79 - def masking_validation_parser(self, system_settings_instance):
80 data = { 81 'cache': {}, # package masking validation cache 82 } 83 return data
84
85 - def misc_parser(self, sys_settings_instance):
86 87 """ 88 Parses Entropy client system configuration file. 89 90 @return dict data 91 """ 92 93 data = { 94 'filesbackup': etpConst['filesbackup'], 95 'ignore_spm_downgrades': etpConst['spm']['ignore-spm-downgrades'], 96 'collisionprotect': etpConst['collisionprotect'], 97 'configprotect': etpConst['configprotect'][:], 98 'configprotectmask': etpConst['configprotectmask'][:], 99 'configprotectskip': etpConst['configprotectskip'][:], 100 } 101 102 cli_conf = etpConst['clientconf'] 103 if not (os.path.isfile(cli_conf) and os.access(cli_conf, os.R_OK)): 104 return data 105 106 client_f = open(cli_conf,"r") 107 clientconf = [x.strip() for x in client_f.readlines() if \ 108 x.strip() and not x.strip().startswith("#")] 109 client_f.close() 110 for line in clientconf: 111 112 split_line = line.split("|") 113 split_line_len = len(split_line) 114 115 if line.startswith("filesbackup|") and (split_line_len == 2): 116 117 compatopt = split_line[1].strip().lower() 118 if compatopt in ("disable", "disabled","false", "0", "no",): 119 data['filesbackup'] = False 120 121 elif line.startswith("ignore-spm-downgrades|") and \ 122 (split_line_len == 2): 123 124 compatopt = split_line[1].strip().lower() 125 if compatopt in ("enable", "enabled", "true", "1", "yes"): 126 data['ignore_spm_downgrades'] = True 127 128 elif line.startswith("collisionprotect|") and (split_line_len == 2): 129 130 collopt = split_line[1].strip() 131 if collopt.lower() in ("0", "1", "2",): 132 data['collisionprotect'] = int(collopt) 133 134 elif line.startswith("configprotect|") and (split_line_len == 2): 135 136 configprotect = split_line[1].strip() 137 for myprot in configprotect.split(): 138 data['configprotect'].append( 139 unicode(myprot,'raw_unicode_escape')) 140 141 elif line.startswith("configprotectmask|") and \ 142 (split_line_len == 2): 143 144 configprotect = split_line[1].strip() 145 for myprot in configprotect.split(): 146 data['configprotectmask'].append( 147 unicode(myprot,'raw_unicode_escape')) 148 149 elif line.startswith("configprotectskip|") and \ 150 (split_line_len == 2): 151 152 configprotect = split_line[1].strip() 153 for myprot in configprotect.split(): 154 data['configprotectskip'].append( 155 etpConst['systemroot']+unicode(myprot, 156 'raw_unicode_escape')) 157 158 return data
159 160
161 -class Client(Singleton, TextInterface, LoadersMixin, CacheMixin, CalculatorsMixin, \ 162 RepositoryMixin, MiscMixin, MatchMixin, FetchersMixin):
163
164 - def init_singleton(self, indexing = True, noclientdb = 0, 165 xcache = True, user_xcache = False, repo_validation = True, 166 load_ugc = True, url_fetcher = None, 167 multiple_url_fetcher = None):
168 169 self.__instance_destroyed = False 170 self.atomMatchCacheKey = etpCache['atomMatch'] 171 self.dbapi2 = dbapi2 # export for third parties 172 self.FileUpdates = None 173 self.validRepositories = [] 174 self.UGC = None 175 # supporting external updateProgress stuff, you can point self.progress 176 # to your progress bar and reimplement updateProgress 177 self.progress = None 178 self.clientDbconn = None 179 self.safe_mode = 0 180 self.indexing = indexing 181 self.repo_validation = repo_validation 182 self.noclientdb = False 183 self.openclientdb = True 184 185 # setup package settings (masking and other stuff) 186 self.SystemSettings = SystemSettings() 187 188 # modules import 189 import entropy.dump as dumpTools 190 import entropy.tools as entropyTools 191 self.dumpTools = dumpTools 192 self.entropyTools = entropyTools 193 self.clientLog = LogFile(level = self.SystemSettings['system']['log_level'], 194 filename = etpConst['equologfile'], header = "[client]") 195 196 self.MultipleUrlFetcher = multiple_url_fetcher 197 self.urlFetcher = url_fetcher 198 if self.urlFetcher == None: 199 from entropy.transceivers import UrlFetcher 200 self.urlFetcher = UrlFetcher 201 if self.MultipleUrlFetcher == None: 202 from entropy.transceivers import MultipleUrlFetcher 203 self.MultipleUrlFetcher = MultipleUrlFetcher 204 205 from entropy.cache import EntropyCacher 206 self.Cacher = EntropyCacher() 207 208 from entropy.client.misc import FileUpdates 209 self.FileUpdates = FileUpdates(self) 210 211 from entropy.client.mirrors import StatusInterface 212 # mirror status interface 213 self.MirrorStatus = StatusInterface() 214 215 if noclientdb in (False,0): 216 self.noclientdb = False 217 elif noclientdb in (True,1): 218 self.noclientdb = True 219 elif noclientdb == 2: 220 self.noclientdb = True 221 self.openclientdb = False 222 223 # load User Generated Content Interface 224 if load_ugc: 225 from entropy.client.services.ugc.interfaces import Client as ugcClient 226 self.UGC = ugcClient(self) 227 228 # class init 229 LoadersMixin.__init__(self) 230 231 self.xcache = xcache 232 shell_xcache = os.getenv("ETP_NOCACHE") 233 if shell_xcache: 234 self.xcache = False 235 236 do_validate_repo_cache = False 237 # now if we are on live, we should disable it 238 # are we running on a livecd? (/proc/cmdline has "cdroot") 239 if self.entropyTools.islive(): 240 self.xcache = False 241 elif (not self.entropyTools.is_user_in_entropy_group()) and not user_xcache: 242 self.xcache = False 243 elif not user_xcache: 244 do_validate_repo_cache = True 245 246 if not self.xcache and (self.entropyTools.is_user_in_entropy_group()): 247 try: 248 self.purge_cache(False) 249 except: 250 pass 251 252 if self.openclientdb: 253 self.open_client_repository() 254 255 # create our SystemSettings plugin 256 self.sys_settings_client_plugin_id = \ 257 etpConst['system_settings_plugins_ids']['client_plugin'] 258 self.sys_settings_client_plugin = ClientSystemSettingsPlugin( 259 self.sys_settings_client_plugin_id, self) 260 # Make sure we connect Entropy Client plugin AFTER client db init 261 self.SystemSettings.add_plugin(self.sys_settings_client_plugin) 262 263 # needs to be started here otherwise repository cache will be 264 # always dropped 265 if self.xcache: 266 self.Cacher.start() 267 268 if do_validate_repo_cache: 269 self.validate_repositories_cache() 270 if self.repo_validation: 271 self.validate_repositories() 272 else: 273 self.validRepositories.extend( 274 self.SystemSettings['repositories']['order'])
275
276 - def destroy(self):
277 self.__instance_destroyed = True 278 if hasattr(self,'clientDbconn'): 279 if self.clientDbconn != None: 280 self.clientDbconn.closeDB() 281 del self.clientDbconn 282 if hasattr(self,'FileUpdates'): 283 del self.FileUpdates 284 if hasattr(self,'clientLog'): 285 self.clientLog.close() 286 if hasattr(self,'Cacher'): 287 self.Cacher.stop() 288 if hasattr(self,'SystemSettings') and \ 289 hasattr(self,'sys_settings_client_plugin_id'): 290 291 if hasattr(self.SystemSettings,'remove_plugin'): 292 try: 293 self.SystemSettings.remove_plugin( 294 self.sys_settings_client_plugin_id) 295 except KeyError: 296 pass 297 298 self.close_all_repositories(mask_clear = False) 299 self.closeAllSecurity() 300 self.closeAllQA()
301
302 - def is_destroyed(self):
303 return self.__instance_destroyed
304
305 - def __del__(self):
306 self.destroy()
307