comparison cagou/plugins/plugin_transfer_android_gallery.py @ 312:772c170b47a9

Python3 port: /!\ Cagou now runs with Python 3.6+ Port has been done in the same way as for backend (check backend commit b2d067339de3 message for details).
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:14:22 +0200
parents 1b835bcfa663
children 4d660b252487
comparison
equal deleted inserted replaced
311:a0d978d3ce84 312:772c170b47a9
35 RESULT_OK = -1 35 RESULT_OK = -1
36 36
37 37
38 38
39 PLUGIN_INFO = { 39 PLUGIN_INFO = {
40 "name": _(u"gallery"), 40 "name": _("gallery"),
41 "main": "AndroidGallery", 41 "main": "AndroidGallery",
42 "platforms": ('android',), 42 "platforms": ('android',),
43 "external": True, 43 "external": True,
44 "description": _(u"upload a photo from photo gallery"), 44 "description": _("upload a photo from photo gallery"),
45 "icon_medium": u"{media}/icons/muchoslava/png/gallery_50.png", 45 "icon_medium": "{media}/icons/muchoslava/png/gallery_50.png",
46 } 46 }
47 47
48 48
49 class AndroidGallery(object): 49 class AndroidGallery(object):
50 50
59 59
60 def on_activity_result(self, requestCode, resultCode, data): 60 def on_activity_result(self, requestCode, resultCode, data):
61 # TODO: move file dump to a thread or use async callbacks during file writting 61 # TODO: move file dump to a thread or use async callbacks during file writting
62 if requestCode == PHOTO_GALLERY and resultCode == RESULT_OK: 62 if requestCode == PHOTO_GALLERY and resultCode == RESULT_OK:
63 if data is None: 63 if data is None:
64 log.warning(u"No data found in activity result") 64 log.warning("No data found in activity result")
65 self.cancel_cb(self, None) 65 self.cancel_cb(self, None)
66 return 66 return
67 uri = data.getData() 67 uri = data.getData()
68 68
69 # we get filename in the way explained at https://developer.android.com/training/secure-file-sharing/retrieve-info.html 69 # we get filename in the way explained at https://developer.android.com/training/secure-file-sharing/retrieve-info.html
78 tmp_dir = tempfile.mkdtemp() 78 tmp_dir = tempfile.mkdtemp()
79 tmp_file = os.path.join(tmp_dir, filename) 79 tmp_file = os.path.join(tmp_dir, filename)
80 def cleaning(): 80 def cleaning():
81 os.unlink(tmp_file) 81 os.unlink(tmp_file)
82 os.rmdir(tmp_dir) 82 os.rmdir(tmp_dir)
83 log.debug(u'temporary file cleaned') 83 log.debug('temporary file cleaned')
84 buff = bytearray(4096) 84 buff = bytearray(4096)
85 with open(tmp_file, 'wb') as f: 85 with open(tmp_file, 'wb') as f:
86 while True: 86 while True:
87 ret = input_stream.read(buff, 0, 4096) 87 ret = input_stream.read(buff, 0, 4096)
88 if ret != -1: 88 if ret != -1: