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

Source Code for Module entropy.client.interfaces.cache

  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  from __future__ import with_statement 
 23  import os 
 24  from entropy.const import * 
 25  from entropy.exceptions import * 
 26  from entropy.output import red, darkred, darkgreen 
 27  from entropy.i18n import _ 
 28   
29 -class CacheMixin:
30
32 # is the list of repos changed? 33 cached = self.Cacher.pop(etpCache['repolist']) 34 if cached == None: 35 # invalidate matching cache 36 try: self.repository_move_clear_cache() 37 except IOError: pass 38 elif isinstance(cached,tuple): 39 difflist = [x for x in cached if x not in \ 40 self.SystemSettings['repositories']['order']] 41 for repoid in difflist: 42 try: self.repository_move_clear_cache(repoid) 43 except IOError: pass 44 self.store_repository_list_cache()
45
47 self.Cacher.push(etpCache['repolist'], 48 tuple(self.SystemSettings['repositories']['order']), 49 async = False)
50
51 - def generate_cache(self, depcache = True, configcache = True, client_purge = True, install_queue = True):
52 self.Cacher.stop() 53 # clean first of all 54 self.purge_cache(client_purge = client_purge) 55 if depcache: 56 self.do_depcache(do_install_queue = install_queue) 57 if configcache: 58 self.do_configcache() 59 self.Cacher.start()
60
61 - def do_configcache(self):
62 self.updateProgress( 63 darkred(_("Configuration files")), 64 importance = 2, 65 type = "warning" 66 ) 67 self.updateProgress( 68 red(_("Scanning hard disk")), 69 importance = 1, 70 type = "warning" 71 ) 72 self.FileUpdates.scanfs(dcache = False, quiet = True) 73 self.updateProgress( 74 darkred(_("Cache generation complete.")), 75 importance = 2, 76 type = "info" 77 )
78
79 - def do_depcache(self, do_install_queue = True):
80 81 self.updateProgress( 82 darkgreen(_("Resolving metadata")), 83 importance = 1, 84 type = "warning" 85 ) 86 # we can barely ignore any exception from here 87 # especially cases where client db does not exist 88 try: 89 update, remove, fine, spm_fine = self.calculate_world_updates() 90 del fine, spm_fine, remove 91 if do_install_queue: 92 self.get_install_queue(update, False, False) 93 self.calculate_available_packages() 94 except: 95 pass 96 97 self.updateProgress( 98 darkred(_("Dependencies cache filled.")), 99 importance = 2, 100 type = "warning" 101 )
102
103 - def purge_cache(self, showProgress = True, client_purge = True):
104 if self.entropyTools.is_user_in_entropy_group(): 105 skip = set() 106 if not client_purge: 107 skip.add("/"+etpCache['dbMatch']+"/"+etpConst['clientdbid']) # it's ok this way 108 skip.add("/"+etpCache['dbSearch']+"/"+etpConst['clientdbid']) # it's ok this way 109 for key in etpCache: 110 if showProgress: 111 self.updateProgress( 112 darkred(_("Cleaning %s => dumps...")) % (etpCache[key],), 113 importance = 1, 114 type = "warning", 115 back = True 116 ) 117 self.clear_dump_cache(etpCache[key], skip = skip) 118 119 if showProgress: 120 self.updateProgress( 121 darkgreen(_("Cache is now empty.")), 122 importance = 2, 123 type = "info" 124 )
125
126 - def clear_dump_cache(self, dump_name, skip = []):
127 self.Cacher.discard() 128 self.SystemSettings._clear_dump_cache(dump_name, skip = skip)
129
130 - def update_ugc_cache(self, repository):
131 if not self.UGC.is_repository_eapi3_aware(repository): 132 return None 133 status = True 134 135 votes_dict, err_msg = self.UGC.get_all_votes(repository) 136 if isinstance(votes_dict,dict): 137 self.UGC.UGCCache.save_vote_cache(repository, votes_dict) 138 else: 139 status = False 140 141 downloads_dict, err_msg = self.UGC.get_all_downloads(repository) 142 if isinstance(downloads_dict,dict): 143 self.UGC.UGCCache.save_downloads_cache(repository, downloads_dict) 144 else: 145 status = False 146 return status
147
148 - def repository_move_clear_cache(self, repoid = None):
149 return self.SystemSettings._clear_repository_cache(repoid = repoid)
150
151 - def get_available_packages_chash(self, branch):
152 # client digest not needed, cache is kept updated 153 return str(hash("%s%s%s" % ( 154 self.all_repositories_checksum(), 155 branch,self.validRepositories,)))
156
158 sum_hashes = '' 159 for repo in self.validRepositories: 160 try: 161 dbconn = self.open_repository(repo) 162 except (RepositoryError): 163 continue # repo not available 164 try: 165 sum_hashes += dbconn.database_checksum() 166 except self.dbapi2.OperationalError: 167 pass 168 return sum_hashes
169
170 - def get_available_packages_cache(self, branch = None, myhash = None):
171 if branch == None: 172 branch = self.SystemSettings['repositories']['branch'] 173 if myhash == None: myhash = self.get_available_packages_chash(branch) 174 return self.Cacher.pop("%s%s" % (etpCache['world_available'],myhash))
175
176 - def get_world_update_cache(self, empty_deps, branch = None, 177 db_digest = None):
178 179 if branch == None: 180 branch = self.SystemSettings['repositories']['branch'] 181 182 misc_settings = self.SystemSettings[self.sys_settings_client_plugin_id]['misc'] 183 ignore_spm_downgrades = misc_settings['ignore_spm_downgrades'] 184 if self.xcache: 185 if db_digest == None: db_digest = self.all_repositories_checksum() 186 c_hash = "%s%s" % (etpCache['world_update'], 187 self.get_world_update_cache_hash(db_digest, empty_deps, branch, 188 ignore_spm_downgrades),) 189 disk_cache = self.Cacher.pop(c_hash) 190 if disk_cache != None: 191 try: 192 if len(disk_cache['r']) == 4: 193 return disk_cache['r'] 194 except (KeyError, TypeError): 195 return None
196
197 - def get_world_update_cache_hash(self, db_digest, empty_deps, branch, ignore_spm_downgrades):
198 return str(hash("%s|%s|%s|%s|%s|%s" % ( 199 db_digest,empty_deps,self.validRepositories, 200 self.SystemSettings['repositories']['order'], branch, 201 ignore_spm_downgrades, 202 )))
203