Entropy/UGC Client/Server Interface
- implement new command ugc:get_documents_by_identifiers to allow retrieval of documents through their identifiers git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@2345 cd1c1023-2f26-0410-ae45-c471fc1f0318
This commit is contained in:
@@ -16894,6 +16894,11 @@ class DistributionUGCInterface(RemoteDbSkelInterface):
|
||||
mydict['size'] = int(os.stat(mypath)[6])
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
mydict['size'] = len(mydict['ddata'].tostring())
|
||||
except:
|
||||
pass
|
||||
return metadata
|
||||
|
||||
def get_ugc_metadata_doctypes_by_identifiers(self, identifiers, typeslist):
|
||||
@@ -16908,6 +16913,18 @@ class DistributionUGCInterface(RemoteDbSkelInterface):
|
||||
mydict['pkgkey'] = self.get_pkgkey(mydict['idkey'])
|
||||
return metadata
|
||||
|
||||
def get_ugc_metadata_by_identifiers(self, identifiers):
|
||||
self.check_connection()
|
||||
self.execute_query('SELECT * FROM entropy_docs WHERE `iddoc` IN %s', (identifiers,))
|
||||
metadata = self.fetchall()
|
||||
if metadata:
|
||||
for mydict in metadata:
|
||||
if not mydict.has_key('iddoc'): continue
|
||||
mydict['keywords'] = self.get_ugc_keywords(mydict['iddoc'])
|
||||
if not mydict.has_key('idkey'): continue
|
||||
mydict['pkgkey'] = self.get_pkgkey(mydict['idkey'])
|
||||
return metadata
|
||||
|
||||
def get_ugc_vote(self, pkgkey):
|
||||
self.check_connection()
|
||||
idkey = self.get_idkey(pkgkey)
|
||||
@@ -17371,6 +17388,16 @@ class DistributionUGCCommands(SocketCommandsSkel):
|
||||
'syntax': "<SESSION_ID> get_comments_by_identifiers <identifier1> <identifier2> <identifier3>",
|
||||
'from': str(self), # from what class
|
||||
},
|
||||
'ugc:get_documents_by_identifiers': {
|
||||
'auth': False,
|
||||
'built_in': False,
|
||||
'cb': self.docmd_get_documents_by_identifiers,
|
||||
'args': ["myargs"],
|
||||
'as_user': False,
|
||||
'desc': "get the documents belonging to the provided identifiers",
|
||||
'syntax': "<SESSION_ID> get_documents_by_identifiers <identifier1> <identifier2> <identifier3>",
|
||||
'from': str(self), # from what class
|
||||
},
|
||||
'ugc:get_vote': {
|
||||
'auth': False,
|
||||
'built_in': False,
|
||||
@@ -17866,6 +17893,13 @@ class DistributionUGCCommands(SocketCommandsSkel):
|
||||
return None
|
||||
return metadata
|
||||
|
||||
def _get_generic_documents_by_identifiers(self, identifiers):
|
||||
ugc = self._load_ugc_interface()
|
||||
metadata = ugc.get_ugc_metadata_by_identifiers(identifiers)
|
||||
if not metadata:
|
||||
return None
|
||||
return metadata
|
||||
|
||||
def docmd_get_comments(self, myargs):
|
||||
|
||||
if not myargs:
|
||||
@@ -17899,6 +17933,26 @@ class DistributionUGCCommands(SocketCommandsSkel):
|
||||
|
||||
return metadata,'ok'
|
||||
|
||||
def docmd_get_documents_by_identifiers(self, myargs):
|
||||
|
||||
if not myargs:
|
||||
return None,'wrong arguments'
|
||||
|
||||
identifiers = []
|
||||
for myarg in myargs:
|
||||
try:
|
||||
identifiers.append(int(myarg))
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
if not identifiers:
|
||||
return None,'wrong arguments'
|
||||
|
||||
metadata = self._get_generic_documents_by_identifiers(identifiers)
|
||||
if metadata == None:
|
||||
return None,'no metadata available'
|
||||
|
||||
return metadata,'ok'
|
||||
|
||||
def docmd_get_allvotes(self):
|
||||
ugc = self._load_ugc_interface()
|
||||
@@ -20118,6 +20172,16 @@ class EntropyRepositorySocketClientCommands(EntropySocketClientCommands):
|
||||
)
|
||||
return self.do_generic_handler(cmd, session_id)
|
||||
|
||||
def ugc_get_documents_by_identifiers(self, session_id, identifiers):
|
||||
|
||||
self.Service.check_socket_connection()
|
||||
cmd = "%s %s %s" % (
|
||||
session_id,
|
||||
'ugc:get_documents_by_identifiers',
|
||||
' '.join([str(x) for x in identifiers]),
|
||||
)
|
||||
return self.do_generic_handler(cmd, session_id)
|
||||
|
||||
def ugc_send_file_stream(self, session_id, file_path):
|
||||
|
||||
if not (os.path.isfile(file_path) and os.access(file_path,os.R_OK)):
|
||||
@@ -20953,6 +21017,9 @@ class UGCClientInterface:
|
||||
def get_comments_by_identifiers(self, repository, identifiers):
|
||||
return self.do_cmd(repository, False, "ugc_get_textdocs_by_identifiers", [identifiers], {})
|
||||
|
||||
def get_documents_by_identifiers(self, repository, identifiers):
|
||||
return self.do_cmd(repository, False, "ugc_get_documents_by_identifiers", [identifiers], {})
|
||||
|
||||
def add_comment(self, repository, pkgkey, comment, title, keywords):
|
||||
return self.do_cmd(repository, True, "ugc_add_comment", [pkgkey, comment, title, keywords], {})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user