Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0329.py @ 2512:025afb04c10b
plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 02 Mar 2018 17:53:19 +0100 |
parents | c0bec8bac2b5 |
children | 25e16729413b |
comparison
equal
deleted
inserted
replaced
2511:20a5e7db0609 | 2512:025afb04c10b |
---|---|
309 def _addPathData(self, client, query_elt, path, parent_node): | 309 def _addPathData(self, client, query_elt, path, parent_node): |
310 """Fill query_elt with files/directories found in path""" | 310 """Fill query_elt with files/directories found in path""" |
311 name = os.path.basename(path) | 311 name = os.path.basename(path) |
312 if os.path.isfile(path): | 312 if os.path.isfile(path): |
313 size = os.path.getsize(path) | 313 size = os.path.getsize(path) |
314 media_type = mimetypes.guess_type(path, strict=False)[0] | 314 mime_type = mimetypes.guess_type(path, strict=False)[0] |
315 file_elt = self._jf.buildFileElement(name = name, | 315 file_elt = self._jf.buildFileElement(name = name, |
316 size = size, | 316 size = size, |
317 media_type = media_type, | 317 mime_type = mime_type, |
318 date = os.path.getmtime(path)) | 318 modified = os.path.getmtime(path)) |
319 | 319 |
320 query_elt.addChild(file_elt) | 320 query_elt.addChild(file_elt) |
321 # we don't specify hash as it would be too resource intensive to calculate it for all files | 321 # we don't specify hash as it would be too resource intensive to calculate it for all files |
322 # we add file to name_data, so users can request it later | 322 # we add file to name_data, so users can request it later |
323 name_data = client._XEP_0329_names_data.setdefault(name, {}) | 323 name_data = client._XEP_0329_names_data.setdefault(name, {}) |
324 if path not in name_data: | 324 if path not in name_data: |
325 name_data[path] = {'size': size, | 325 name_data[path] = {'size': size, |
326 'media_type': media_type, | 326 'mime_type': mime_type, |
327 'parent': parent_node} | 327 'parent': parent_node} |
328 else: | 328 else: |
329 # we have a directory | 329 # we have a directory |
330 directory_elt = query_elt.addElement('directory') | 330 directory_elt = query_elt.addElement('directory') |
331 directory_elt['name'] = name | 331 directory_elt['name'] = name |
433 iq_result_elt = xmlstream.toResponse(iq_elt, 'result') | 433 iq_result_elt = xmlstream.toResponse(iq_elt, 'result') |
434 query_elt = iq_result_elt.addElement((NS_FIS, 'query')) | 434 query_elt = iq_result_elt.addElement((NS_FIS, 'query')) |
435 query_elt[u'node'] = node_path | 435 query_elt[u'node'] = node_path |
436 for file_data in files_data: | 436 for file_data in files_data: |
437 file_elt = self._jf.buildFileElementFromDict(file_data, | 437 file_elt = self._jf.buildFileElementFromDict(file_data, |
438 date=file_data.get(u'modified', file_data[u'created'])) | 438 modified=file_data.get(u'modified', file_data[u'created'])) |
439 query_elt.addChild(file_elt) | 439 query_elt.addChild(file_elt) |
440 client.send(iq_result_elt) | 440 client.send(iq_result_elt) |
441 | 441 |
442 def onComponentRequest(self, iq_elt, client): | 442 def onComponentRequest(self, iq_elt, client): |
443 return self._requestHandler(client, iq_elt, self._compGetRootNodesCb, self._compGetFilesFromNodeCb) | 443 return self._requestHandler(client, iq_elt, self._compGetRootNodesCb, self._compGetFilesFromNodeCb) |