Re: [Sugar-devel] [PATCH] Change the logic used to determine the format used to save files.
Excerpts from Gonzalo Odiard's message of Thu Oct 14 22:23:35 +0200 2010: Please mention the module name as part of the patch summary, e.g.: [PATCH Write] keep file type across load/save (SL #2127) The subject is created by git send-email. I can change the first line from the patch, but no how you say. Check out the --subject-prefix option of git format-patch. git send-email delegates the actual patch preparation to git format-patch (unless you pass it a pre-formatted patch as a file). [full-quote trimmed] Please remember to trim those parts of your message you don't reply to. Sascha -- http://sascha.silbe.org/ http://www.infra-silbe.de/ signature.asc Description: PGP signature ___ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel
[Sugar-devel] [PATCH] Change the logic used to determine the format used to save files.
From: Gonzalo Odiard godi...@sugarlabs.org Fix the tickets OLPC #5291, OLPC #1925, SL #2127 --- AbiWordActivity.py | 36 +++- 1 files changed, 23 insertions(+), 13 deletions(-) diff --git a/AbiWordActivity.py b/AbiWordActivity.py index 7deab8c..3613ce5 100644 --- a/AbiWordActivity.py +++ b/AbiWordActivity.py @@ -423,28 +423,38 @@ class AbiWordActivity (activity.Activity): #self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyLeft', self.participants[buddy.object_path()], 0, 0) def read_file(self, file_path): -logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', file_path, self.metadata['mime_type']) -if 'source' in self.metadata and self.metadata['source'] == '1': -logger.debug('Opening file in view source mode') -self.abiword_canvas.load_file('file://' + file_path, 'text/plain') +logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', +file_path, self.metadata['mime_type']) +if self.metadata['mime_type'] in ['text/plain', 'text/csv']: +logging.debug('Opening file in text mode') +self.abiword_canvas.load_file('file://' + file_path, 'text/plain') else: self.abiword_canvas.load_file('file://' + file_path, '') # we pass no mime/file type, let libabiword autodetect it, so we can handle multiple file formats def write_file(self, file_path): logging.debug('AbiWordActivity.write_file') -# check if we have a default mimetype; if not, fall back to OpenDocument -# also fallback if we know we cannot export in that format -if 'mime_type' not in self.metadata or self.metadata['mime_type'] == '' or \ -self.metadata['mime_type'] == 'application/msword': -self.metadata['mime_type'] = 'application/vnd.oasis.opendocument.text' - -# if we were viewing the source of a file, -# then always save as plain text +# if we were viewing a text file save as plain text actual_mimetype = self.metadata['mime_type'] -if 'source' in self.metadata and self.metadata['source'] == '1': +if self.metadata['mime_type'] in ['text/plain', 'text/csv']: logger.debug('Writing file as type source (text/plain)') actual_mimetype = 'text/plain' +else: +# if not is a abiword file, fall back to OpenDocument +if self.metadata['mime_type'] not in ['application/x-abiword', + 'text/x-xml-abiword']: +actual_mimetype = 'application/vnd.oasis.opendocument.text' +# change the extension in the file name and the description +self._change_file_ext(self.metadata['title'], '.odt') +self._change_file_ext(self.metadata['description'], '.odt') + +self.metadata['mime_type'] = actual_mimetype self.metadata['fulltext'] = self.abiword_canvas.get_content(extension_or_mimetype=.txt)[:3000] self.abiword_canvas.save('file://' + file_path, actual_mimetype, '') + +def _change_file_ext(self, file_name, extension): +last_point_posi = file_name.rfind('.') +if last_point_posi -1: +file_name = file_name[0:last_point_posi] + extension +return file_name -- 1.7.2.3 ___ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel
Re: [Sugar-devel] [PATCH] Change the logic used to determine the format used to save files.
Excerpts from godiard's message of Thu Oct 14 20:10:14 +0200 2010: Fix the tickets OLPC #5291, OLPC #1925, SL #2127 Please provide some background information as part of the patch description. What are you changing and why? Please mention the module name as part of the patch summary, e.g.: [PATCH Write] keep file type across load/save (SL #2127) This a) ensures maintainers notice patches for their modules and b) enables reviewers to prioritise patches depending on how well they know the module. [AbiWordActivity.py] @@ -423,28 +423,38 @@ class AbiWordActivity (activity.Activity): #self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyLeft', self.participants[buddy.object_path()], 0, 0) def read_file(self, file_path): -logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', file_path, self.metadata['mime_type']) -if 'source' in self.metadata and self.metadata['source'] == '1': -logger.debug('Opening file in view source mode') -self.abiword_canvas.load_file('file://' + file_path, 'text/plain') +logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', +file_path, self.metadata['mime_type']) Please don't mix style changes with bug fixes. +if self.metadata['mime_type'] in ['text/plain', 'text/csv']: +logging.debug('Opening file in text mode') +self.abiword_canvas.load_file('file://' + file_path, 'text/plain') else: self.abiword_canvas.load_file('file://' + file_path, '') # we pass no mime/file type, let libabiword autodetect it, so we can handle multiple file formats I fail to see how this addresses (one of?) the tickets you mentioned. Also it will cause the activity to break if the Journal entry doesn't have a MIME type set. [write_file()] Same comments as for read_file(). +# change the extension in the file name and the description +self._change_file_ext(self.metadata['title'], '.odt') +self._change_file_ext(self.metadata['description'], '.odt') Randomly changing user-set metadata is a no-no. Sascha -- http://sascha.silbe.org/ http://www.infra-silbe.de/ signature.asc Description: PGP signature ___ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel
Re: [Sugar-devel] [PATCH] Change the logic used to determine the format used to save files.
On Thu, Oct 14, 2010 at 5:08 PM, Sascha Silbe sascha-ml-reply-to-201...@silbe.org wrote: Excerpts from godiard's message of Thu Oct 14 20:10:14 +0200 2010: Fix the tickets OLPC #5291, OLPC #1925, SL #2127 Please provide some background information as part of the patch description. What are you changing and why? Please mention the module name as part of the patch summary, e.g.: [PATCH Write] keep file type across load/save (SL #2127) The subject is created by git send-email. I can change the first line from the patch, but no how you say. This a) ensures maintainers notice patches for their modules and b) enables reviewers to prioritise patches depending on how well they know the module. [AbiWordActivity.py] @@ -423,28 +423,38 @@ class AbiWordActivity (activity.Activity): #self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyLeft', self.participants[buddy.object_path()], 0, 0) def read_file(self, file_path): -logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', file_path, self.metadata['mime_type']) -if 'source' in self.metadata and self.metadata['source'] == '1': -logger.debug('Opening file in view source mode') -self.abiword_canvas.load_file('file://' + file_path, 'text/plain') +logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', +file_path, self.metadata['mime_type']) Please don't mix style changes with bug fixes. +if self.metadata['mime_type'] in ['text/plain', 'text/csv']: +logging.debug('Opening file in text mode') +self.abiword_canvas.load_file('file://' + file_path, 'text/plain') else: self.abiword_canvas.load_file('file://' + file_path, '') # we pass no mime/file type, let libabiword autodetect it, so we can handle multiple file formats I fail to see how this addresses (one of?) the tickets you mentioned. Also it will cause the activity to break if the Journal entry doesn't have a MIME type set. The code correct http://bugs.sugarlabs.org/ticket/2127 where .csv files are opened and saved like odt files. That is because canvas.load_file must be called with the mime type (and specifically 'text/plain') [write_file()] Same comments as for read_file(). +# change the extension in the file name and the description +self._change_file_ext(self.metadata['title'], '.odt') +self._change_file_ext(self.metadata['description'], '.odt') Randomly changing user-set metadata is a no-no. Not randomly. Write save the files like OpenDocument but don't change the metadata. If you copy the file from the journal to a pen drive or look at the file in the datastore can see it. It's difficult to see the actual behavior in the patch, but I have tested it a long time. Sascha -- http://sascha.silbe.org/ http://www.infra-silbe.de/ ___ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel ___ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel