1
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
29
30 import entropy.dump as dumpTools
31 import entropy.tools as entropyTools
32
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),
47 },
48 'repository_server:pkginfo': {
49 'auth': False,
50 'built_in': False,
51 'cb': self.docmd_pkginfo,
52 'args': ["myargs"],
53 'as_user': False,
54 'desc': "returns metadata of the provided idpackages",
55 'syntax': "<SESSION_ID> repository_server:pkginfo <content fmt True/False> <repository> <arch> <product> <branch> <idpackage>",
56 'from': unicode(self),
57 },
58 'repository_server:pkginfo_strict': {
59 'auth': False,
60 'built_in': False,
61 'cb': self.docmd_pkginfo,
62 'args': ["myargs", "False"],
63 'as_user': False,
64 'desc': "returns metadata of the provided idpackages excluding 'content'",
65 'syntax': "<SESSION_ID> repository_server:pkginfo_strict <content fmt True/False> <repository> <arch> <product> <branch> <idpackage>",
66 'from': unicode(self),
67 },
68 'repository_server:treeupdates': {
69 'auth': False,
70 'built_in': False,
71 'cb': self.docmd_treeupdates,
72 'args': ["myargs"],
73 'as_user': False,
74 'desc': "returns repository treeupdates metadata",
75 'syntax': "<SESSION_ID> repository_server:treeupdates <repository> <arch> <product> <branch>",
76 'from': unicode(self),
77 },
78 'repository_server:get_package_sets': {
79 'auth': False,
80 'built_in': False,
81 'cb': self.docmd_package_sets,
82 'args': ["myargs"],
83 'as_user': False,
84 'desc': "returns repository package sets metadata",
85 'syntax': "<SESSION_ID> repository_server:get_package_sets <repository> <arch> <product> <branch>",
86 'from': unicode(self),
87 },
88 'repository_server:get_repository_metadata': {
89 'auth': False,
90 'built_in': False,
91 'cb': self.docmd_repository_metadata,
92 'args': ["myargs"],
93 'as_user': False,
94 'desc': "returns repository metadata (package sets, treeupdates, libraries <=> idpackages map)",
95 'syntax': "<SESSION_ID> repository_server:get_repository_metadata <repository> <arch> <product> <branch>",
96 'from': unicode(self),
97 }
98 }
99
101 for db in self.HostInterface.syscache['db_trashed']:
102 db.closeDB()
103 self.HostInterface.syscache['db_trashed'].clear()
104
106
107 self.trash_old_databases()
108
109 if len(myargs) < 5:
110 return None
111 repository = myargs[0]
112 arch = myargs[1]
113 product = myargs[2]
114 try:
115 branch = str(myargs[3])
116 except (UnicodeEncodeError,UnicodeDecodeError,):
117 return None
118 foreign_idpackages = myargs[4:]
119 x = (repository,arch,product,branch,)
120
121 valid = self.HostInterface.is_repository_available(x)
122 if not valid:
123 return valid
124
125 dbpath = self.get_database_path(repository, arch, product, branch)
126 dbconn = self.HostInterface.open_db(dbpath, docache = False)
127 mychecksum = dbconn.database_checksum(do_order = True, strict = False, strings = True)
128 myids = dbconn.listAllIdpackages()
129 dbconn.closeDB()
130 foreign_idpackages = set(foreign_idpackages)
131
132 removed_ids = foreign_idpackages - myids
133 added_ids = myids - foreign_idpackages
134
135 return {'removed': removed_ids, 'added': added_ids, 'checksum': mychecksum}
136
172
173
175
176 self.trash_old_databases()
177
178 if len(myargs) < 4:
179 return None
180 repository = myargs[0]
181 arch = myargs[1]
182 product = myargs[2]
183 try:
184 branch = str(myargs[3])
185 except (UnicodeEncodeError,UnicodeDecodeError,):
186 return None
187
188 x = (repository,arch,product,branch,)
189 valid = self.HostInterface.is_repository_available(x)
190 if not valid:
191 return valid
192
193 cached = self.HostInterface.get_dcache((repository, arch, product, branch, 'docmd_package_sets'), repository)
194 if cached != None:
195 return cached
196
197 dbpath = self.get_database_path(repository, arch, product, branch)
198 dbconn = self.HostInterface.open_db(dbpath, docache = False)
199
200
201 data = dbconn.retrievePackageSets()
202
203 self.HostInterface.set_dcache((repository, arch, product, branch, 'docmd_package_sets'), data, repository)
204 dbconn.closeDB()
205
206 return data
207
208
210
211 self.trash_old_databases()
212
213 if len(myargs) < 4:
214 return None
215 repository = myargs[0]
216 arch = myargs[1]
217 product = myargs[2]
218 try:
219 branch = str(myargs[3])
220 except (UnicodeEncodeError,UnicodeDecodeError,):
221 return None
222
223 x = (repository,arch,product,branch,)
224 valid = self.HostInterface.is_repository_available(x)
225 if not valid:
226 return valid
227
228 cached = self.HostInterface.get_dcache((repository, arch, product, branch, 'docmd_treeupdates'), repository)
229 if cached != None:
230 return cached
231
232 dbpath = self.get_database_path(repository, arch, product, branch)
233 dbconn = self.HostInterface.open_db(dbpath, docache = False)
234
235
236 data = {}
237 data['actions'] = dbconn.listAllTreeUpdatesActions()
238 data['digest'] = dbconn.retrieveRepositoryUpdatesDigest(repository)
239
240 self.HostInterface.set_dcache((repository, arch, product, branch, 'docmd_treeupdates'), data, repository)
241 dbconn.closeDB()
242
243 return data
244
245
247
248 self.trash_old_databases()
249
250 if len(myargs) < 6:
251 return None
252 format_content_for_insert = myargs[0]
253 if type(format_content_for_insert) is not bool:
254 format_content_for_insert = False
255 repository = myargs[1]
256 arch = myargs[2]
257 product = myargs[3]
258 try:
259 branch = str(myargs[4])
260 except (UnicodeEncodeError,UnicodeDecodeError,):
261 return None
262 zidpackages = myargs[5:]
263 idpackages = []
264 for idpackage in zidpackages:
265 if type(idpackage) is int:
266 idpackages.append(idpackage)
267 if not idpackages:
268 return None
269 idpackages = tuple(sorted(idpackages))
270 x = (repository,arch,product,branch,)
271
272 valid = self.HostInterface.is_repository_available(x)
273 if not valid:
274 return valid
275
276 get_cont_cache = '_cont'
277 if not get_content:
278 get_cont_cache = ''
279
280 cached = self.HostInterface.get_dcache(
281 (repository, arch, product, branch, idpackages, 'docmd_pkginfo'+get_cont_cache),
282 repository
283 )
284 if cached != None:
285 return cached
286
287 dbpath = self.get_database_path(repository, arch, product, branch)
288 dbconn = self.HostInterface.open_db(dbpath, docache = False)
289
290 result = {}
291 for idpackage in idpackages:
292 try:
293 mydata = dbconn.getPackageData(
294 idpackage,
295 content_insert_formatted = format_content_for_insert,
296 get_content = get_content
297 )
298 except:
299 tb = self.entropyTools.get_traceback()
300 print tb
301 self.HostInterface.socketLog.write(tb)
302 dbconn.closeDB()
303 return None
304 result[idpackage] = mydata.copy()
305
306 self.HostInterface.set_dcache(
307 (repository, arch, product, branch, idpackages, 'docmd_pkginfo'+get_cont_cache),
308 result,
309 repository
310 )
311 dbconn.closeDB()
312 return result
313
315 repoitems = (repository,arch,product,branch,)
316 mydbroot = self.HostInterface.repositories[repoitems]['dbpath']
317 dbpath = os.path.join(mydbroot,etpConst['etpdatabasefile'])
318 return dbpath
319