Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0234.py @ 1568:1f7a34d499e0
plugins XEP-0234, file: use of SatFile for writing too
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 08 Nov 2015 14:44:33 +0100 |
parents | 268fda4236ca |
children | c668081eba1c |
comparison
equal
deleted
inserted
replaced
1567:268fda4236ca | 1568:1f7a34d499e0 |
---|---|
99 options={C.XMLUI_DATA_FILETYPE: C.XMLUI_DATA_FILETYPE_DIR}, | 99 options={C.XMLUI_DATA_FILETYPE: C.XMLUI_DATA_FILETYPE_DIR}, |
100 profile=profile) | 100 profile=profile) |
101 d.addCallback(self._gotConfirmation, session, content_data, application_data, profile) | 101 d.addCallback(self._gotConfirmation, session, content_data, application_data, profile) |
102 return d | 102 return d |
103 | 103 |
104 def _openFileWrite(self, content_data, file_path, file_data, profile): | |
105 assert 'file_obj' not in content_data | |
106 content_data['file_obj'] = self._f.File( | |
107 self.host, | |
108 file_path, | |
109 'w', | |
110 size=file_data['size'], | |
111 profile=profile, | |
112 ) | |
113 | |
104 def _gotConfirmation(self, data, session, content_data, application_data, profile): | 114 def _gotConfirmation(self, data, session, content_data, application_data, profile): |
105 """Called when the permission and dest path have been received | 115 """Called when the permission and dest path have been received |
106 | 116 |
107 @param data(dict): xmlui data received from file dialog | 117 @param data(dict): xmlui data received from file dialog |
108 return (bool): True if copy is wanted and OK | 118 return (bool): True if copy is wanted and OK |
118 | 128 |
119 # we manage case where file already exists | 129 # we manage case where file already exists |
120 if os.path.exists(file_path): | 130 if os.path.exists(file_path): |
121 def check_overwrite(overwrite): | 131 def check_overwrite(overwrite): |
122 if overwrite: | 132 if overwrite: |
123 assert 'file_obj' not in content_data | 133 self._openFileWrite(content_data, file_path, file_data, profile) |
124 content_data['file_obj'] = open(file_path, 'w') | |
125 return True | 134 return True |
126 else: | 135 else: |
127 return self._getDestDir(session, content_data, profile) | 136 return self._getDestDir(session, content_data, profile) |
128 | 137 |
129 exists_d = xml_tools.deferConfirm( | 138 exists_d = xml_tools.deferConfirm( |
132 _(CONFIRM_OVERWRITE_TITLE), | 141 _(CONFIRM_OVERWRITE_TITLE), |
133 profile=profile) | 142 profile=profile) |
134 exists_d.addCallback(check_overwrite) | 143 exists_d.addCallback(check_overwrite) |
135 return exists_d | 144 return exists_d |
136 | 145 |
137 assert 'file_obj' not in content_data | 146 self._openFileWrite(content_data, file_path, file_data, profile) |
138 content_data['file_obj'] = open(file_path, 'w') | |
139 return True | 147 return True |
140 | 148 |
141 # jingle callbacks | 149 # jingle callbacks |
142 | 150 |
143 def jingleSessionInit(self, session, content_name, filepath, name=None, file_desc=None, profile=C.PROF_KEY_NONE): | 151 def jingleSessionInit(self, session, content_name, filepath, name=None, file_desc=None, profile=C.PROF_KEY_NONE): |