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

Source Code for Module entropy.services.repository.commands

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