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  import os 
 14  from entropy.services.skel import SocketCommands 
 15  from entropy.const import etpConst 
 16   
17 -class Repository(SocketCommands):
18 19 import entropy.dump as dumpTools 20 import entropy.tools as entropyTools 21
22 - def __init__(self, HostInterface):
23 24 SocketCommands.__init__(self, HostInterface, inst_name = "repository_server") 25 26 self.valid_commands = { 27 'repository_server:dbdiff': { 28 'auth': False, 29 'built_in': False, 30 'cb': self.docmd_dbdiff, 31 'args': ["myargs"], 32 'as_user': False, 33 'desc': "returns idpackage differences against the latest available repository", 34 'syntax': "<SESSION_ID> repository_server:dbdiff <repository> <arch> <product> <branch> [idpackages]", 35 'from': str(self), # from what class 36 }, 37 'repository_server:pkginfo_strict': { 38 'auth': False, 39 'built_in': False, 40 'cb': self.docmd_pkginfo_strict, 41 'args': ["myargs"], 42 'as_user': False, 43 'desc': "returns metadata of the provided idpackages excluding 'content'", 44 'syntax': "<SESSION_ID> repository_server:pkginfo_strict <content fmt True/False> <repository> <arch> <product> <branch> <idpackage>", 45 'from': str(self), # from what class 46 }, 47 'repository_server:treeupdates': { 48 'auth': False, 49 'built_in': False, 50 'cb': self.docmd_treeupdates, 51 'args': ["myargs"], 52 'as_user': False, 53 'desc': "returns repository treeupdates metadata", 54 'syntax': "<SESSION_ID> repository_server:treeupdates <repository> <arch> <product> <branch>", 55 'from': str(self), # from what class 56 }, 57 'repository_server:get_package_sets': { 58 'auth': False, 59 'built_in': False, 60 'cb': self.docmd_package_sets, 61 'args': ["myargs"], 62 'as_user': False, 63 'desc': "returns repository package sets metadata", 64 'syntax': "<SESSION_ID> repository_server:get_package_sets <repository> <arch> <product> <branch>", 65 'from': str(self), # from what class 66 }, 67 'repository_server:get_repository_metadata': { 68 'auth': False, 69 'built_in': False, 70 'cb': self.docmd_repository_metadata, 71 'args': ["myargs"], 72 'as_user': False, 73 'desc': "returns repository metadata (package sets, treeupdates, libraries <=> idpackages map)", 74 'syntax': "<SESSION_ID> repository_server:get_repository_metadata <repository> <arch> <product> <branch>", 75 'from': str(self), # from what class 76 } 77 }
78
79 - def trash_old_databases(self):
80 for db in self.HostInterface.syscache['db_trashed']: 81 db.closeDB() 82 self.HostInterface.syscache['db_trashed'].clear()
83
84 - def docmd_dbdiff(self, myargs):
85 86 self.trash_old_databases() 87 88 if len(myargs) < 5: 89 return None 90 repository = myargs[0] 91 arch = myargs[1] 92 product = myargs[2] 93 try: 94 branch = str(myargs[3]) 95 except (UnicodeEncodeError, UnicodeDecodeError,): 96 return None 97 foreign_idpackages = myargs[4:] 98 x = (repository, arch, product, branch,) 99 100 valid = self.HostInterface.is_repository_available(x) 101 if not valid: 102 return valid 103 104 dbpath = self.get_database_path(repository, arch, product, branch) 105 dbconn = self.HostInterface.open_db(dbpath, docache = False) 106 mychecksum = dbconn.checksum(do_order = True, strict = False, strings = True) 107 myids = dbconn.listAllIdpackages() 108 dbconn.closeDB() 109 foreign_idpackages = set(foreign_idpackages) 110 111 removed_ids = foreign_idpackages - myids 112 added_ids = myids - foreign_idpackages 113 114 return {'removed': removed_ids, 'added': added_ids, 'checksum': mychecksum}
115
116 - def docmd_repository_metadata(self, myargs):
117 118 self.trash_old_databases() 119 120 if len(myargs) < 4: 121 return None 122 repository = myargs[0] 123 arch = myargs[1] 124 product = myargs[2] 125 try: 126 branch = str(myargs[3]) 127 except (UnicodeEncodeError, UnicodeDecodeError,): 128 return None 129 130 x = (repository, arch, product, branch,) 131 valid = self.HostInterface.is_repository_available(x) 132 if not valid: 133 return valid 134 135 cached = self.HostInterface.get_dcache((repository, arch, product, branch, 'docmd_repository_metadata'), repository) 136 if cached != None: 137 return cached 138 139 metadata = {} 140 dbpath = self.get_database_path(repository, arch, product, branch) 141 dbconn = self.HostInterface.open_db(dbpath, docache = False) 142 metadata['sets'] = dbconn.retrievePackageSets() 143 metadata['treeupdates_actions'] = dbconn.listAllTreeUpdatesActions() 144 metadata['treeupdates_digest'] = dbconn.retrieveRepositoryUpdatesDigest(repository) 145 # FIXME: kept for backward compatibility (<=0.99.0.x) remove in future 146 metadata['library_idpackages'] = [] 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 not isinstance(format_content_for_insert, 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 isinstance(idpackage, 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