Package entropy :: Package services :: Package repository :: Module commands

Source Code for Module entropy.services.repository.commands

  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.services.skel import SocketCommands 
 26  from entropy.const import etpConst 
 27   
28 -class Repository(SocketCommands):
29 30 import entropy.dump as dumpTools 31 import entropy.tools as entropyTools 32
33 - def __init__(self, HostInterface):
34 35 SocketCommands.__init__(self, HostInterface, inst_name = "repository_server") 36 37 self.valid_commands = { 38 'repository_server:dbdiff': { 39 'auth': False, 40 'built_in': False, 41 'cb': self.docmd_dbdiff, 42 'args': ["myargs"], 43 'as_user': False, 44 'desc': "returns idpackage differences against the latest available repository", 45 'syntax': "<SESSION_ID> repository_server:dbdiff <repository> <arch> <product> <branch> [idpackages]", 46 'from': unicode(self), # from what class 47 }, 48 'repository_server:pkginfo_strict': { 49 'auth': False, 50 'built_in': False, 51 'cb': self.docmd_pkginfo_strict, 52 'args': ["myargs"], 53 'as_user': False, 54 'desc': "returns metadata of the provided idpackages excluding 'content'", 55 'syntax': "<SESSION_ID> repository_server:pkginfo_strict <content fmt True/False> <repository> <arch> <product> <branch> <idpackage>", 56 'from': unicode(self), # from what class 57 }, 58 'repository_server:treeupdates': { 59 'auth': False, 60 'built_in': False, 61 'cb': self.docmd_treeupdates, 62 'args': ["myargs"], 63 'as_user': False, 64 'desc': "returns repository treeupdates metadata", 65 'syntax': "<SESSION_ID> repository_server:treeupdates <repository> <arch> <product> <branch>", 66 'from': unicode(self), # from what class 67 }, 68 'repository_server:get_package_sets': { 69 'auth': False, 70 'built_in': False, 71 'cb': self.docmd_package_sets, 72 'args': ["myargs"], 73 'as_user': False, 74 'desc': "returns repository package sets metadata", 75 'syntax': "<SESSION_ID> repository_server:get_package_sets <repository> <arch> <product> <branch>", 76 'from': unicode(self), # from what class 77 }, 78 'repository_server:get_repository_metadata': { 79 'auth': False, 80 'built_in': False, 81 'cb': self.docmd_repository_metadata, 82 'args': ["myargs"], 83 'as_user': False, 84 'desc': "returns repository metadata (package sets, treeupdates, libraries <=> idpackages map)", 85 'syntax': "<SESSION_ID> repository_server:get_repository_metadata <repository> <arch> <product> <branch>", 86 'from': unicode(self), # from what class 87 } 88 }
89
90 - def trash_old_databases(self):
91 for db in self.HostInterface.syscache['db_trashed']: 92 db.closeDB() 93 self.HostInterface.syscache['db_trashed'].clear()
94
95 - def docmd_dbdiff(self, myargs):
96 97 self.trash_old_databases() 98 99 if len(myargs) < 5: 100 return None 101 repository = myargs[0] 102 arch = myargs[1] 103 product = myargs[2] 104 try: 105 branch = str(myargs[3]) 106 except (UnicodeEncodeError,UnicodeDecodeError,): 107 return None 108 foreign_idpackages = myargs[4:] 109 x = (repository,arch,product,branch,) 110 111 valid = self.HostInterface.is_repository_available(x) 112 if not valid: 113 return valid 114 115 dbpath = self.get_database_path(repository, arch, product, branch) 116 dbconn = self.HostInterface.open_db(dbpath, docache = False) 117 mychecksum = dbconn.database_checksum(do_order = True, strict = False, strings = True) 118 myids = dbconn.listAllIdpackages() 119 dbconn.closeDB() 120 foreign_idpackages = set(foreign_idpackages) 121 122 removed_ids = foreign_idpackages - myids 123 added_ids = myids - foreign_idpackages 124 125 return {'removed': removed_ids, 'added': added_ids, 'checksum': mychecksum}
126
127 - def docmd_repository_metadata(self, myargs):
128 129 self.trash_old_databases() 130 131 if len(myargs) < 4: 132 return None 133 repository = myargs[0] 134 arch = myargs[1] 135 product = myargs[2] 136 try: 137 branch = str(myargs[3]) 138 except (UnicodeEncodeError,UnicodeDecodeError,): 139 return None 140 141 x = (repository,arch,product,branch,) 142 valid = self.HostInterface.is_repository_available(x) 143 if not valid: 144 return valid 145 146 cached = self.HostInterface.get_dcache((repository, arch, product, branch, 'docmd_repository_metadata'), repository) 147 if cached != None: 148 return cached 149 150 metadata = {} 151 dbpath = self.get_database_path(repository, arch, product, branch) 152 dbconn = self.HostInterface.open_db(dbpath, docache = False) 153 metadata['sets'] = dbconn.retrievePackageSets() 154 metadata['treeupdates_actions'] = dbconn.listAllTreeUpdatesActions() 155 metadata['treeupdates_digest'] = dbconn.retrieveRepositoryUpdatesDigest(repository) 156 metadata['library_idpackages'] = dbconn.retrieveNeededLibraryIdpackages() 157 158 self.HostInterface.set_dcache((repository, arch, product, branch, 'docmd_repository_metadata'), metadata, repository) 159 dbconn.closeDB() 160 161 return metadata
162 163
164 - def docmd_package_sets(self, myargs):
165 166 self.trash_old_databases() 167 168 if len(myargs) < 4: 169 return None 170 repository = myargs[0] 171 arch = myargs[1] 172 product = myargs[2] 173 try: 174 branch = str(myargs[3]) 175 except (UnicodeEncodeError,UnicodeDecodeError,): 176 return None 177 178 x = (repository,arch,product,branch,) 179 valid = self.HostInterface.is_repository_available(x) 180 if not valid: 181 return valid 182 183 cached = self.HostInterface.get_dcache((repository, arch, product, branch, 'docmd_package_sets'), repository) 184 if cached != None: 185 return cached 186 187 dbpath = self.get_database_path(repository, arch, product, branch) 188 dbconn = self.HostInterface.open_db(dbpath, docache = False) 189 190 # get data 191 data = dbconn.retrievePackageSets() 192 193 self.HostInterface.set_dcache((repository, arch, product, branch, 'docmd_package_sets'), data, repository) 194 dbconn.closeDB() 195 196 return data
197 198
199 - def docmd_treeupdates(self, myargs):
200 201 self.trash_old_databases() 202 203 if len(myargs) < 4: 204 return None 205 repository = myargs[0] 206 arch = myargs[1] 207 product = myargs[2] 208 try: 209 branch = str(myargs[3]) 210 except (UnicodeEncodeError,UnicodeDecodeError,): 211 return None 212 213 x = (repository,arch,product,branch,) 214 valid = self.HostInterface.is_repository_available(x) 215 if not valid: 216 return valid 217 218 cached = self.HostInterface.get_dcache((repository, arch, product, branch, 'docmd_treeupdates'), repository) 219 if cached != None: 220 return cached 221 222 dbpath = self.get_database_path(repository, arch, product, branch) 223 dbconn = self.HostInterface.open_db(dbpath, docache = False) 224 225 # get data 226 data = {} 227 data['actions'] = dbconn.listAllTreeUpdatesActions() 228 data['digest'] = dbconn.retrieveRepositoryUpdatesDigest(repository) 229 230 self.HostInterface.set_dcache((repository, arch, product, branch, 'docmd_treeupdates'), data, repository) 231 dbconn.closeDB() 232 233 return data
234 235
236 - def docmd_pkginfo_strict(self, myargs):
237 238 self.trash_old_databases() 239 240 if len(myargs) < 6: 241 return None 242 format_content_for_insert = myargs[0] 243 if type(format_content_for_insert) is not bool: 244 format_content_for_insert = False 245 repository = myargs[1] 246 arch = myargs[2] 247 product = myargs[3] 248 try: 249 branch = str(myargs[4]) 250 except (UnicodeEncodeError,UnicodeDecodeError,): 251 return None 252 zidpackages = myargs[5:] 253 idpackages = [] 254 for idpackage in zidpackages: 255 if type(idpackage) is int: 256 idpackages.append(idpackage) 257 if not idpackages: 258 return None 259 idpackages = tuple(sorted(idpackages)) 260 x = (repository,arch,product,branch,) 261 262 valid = self.HostInterface.is_repository_available(x) 263 if not valid: 264 return valid 265 266 cached = self.HostInterface.get_dcache( 267 (repository, arch, product, branch, idpackages, 'docmd_pkginfo_strict'), 268 repository 269 ) 270 if cached != None: 271 return cached 272 273 dbpath = self.get_database_path(repository, arch, product, branch) 274 dbconn = self.HostInterface.open_db(dbpath, docache = False) 275 276 result = {} 277 for idpackage in idpackages: 278 try: 279 mydata = dbconn.getPackageData( 280 idpackage, 281 content_insert_formatted = format_content_for_insert, 282 get_content = False 283 ) 284 except: 285 tb = self.entropyTools.get_traceback() 286 print tb 287 self.HostInterface.socketLog.write(tb) 288 dbconn.closeDB() 289 return None 290 result[idpackage] = mydata.copy() 291 292 self.HostInterface.set_dcache( 293 (repository, arch, product, branch, idpackages, 'docmd_pkginfo_strict'), 294 result, 295 repository 296 ) 297 dbconn.closeDB() 298 return result
299
300 - def get_database_path(self, repository, arch, product, branch):
301 repoitems = (repository,arch,product,branch,) 302 mydbroot = self.HostInterface.repositories[repoitems]['dbpath'] 303 dbpath = os.path.join(mydbroot,etpConst['etpdatabasefile']) 304 return dbpath
305