[Dextrose] [PATCH 5/5][dextrose2][sugar] Updater check bundle integrity

Martin Abente martin.abente.lahaye at gmail.com
Fri Apr 22 12:19:13 EDT 2011


On Wed, Apr 20, 2011 at 3:21 AM, Sascha Silbe <silbe at activitycentral.com> wrote:
> Excerpts from Martin Abente's message of Tue Apr 19 23:21:28 +0200 2011:
>
> [extensions/cpsection/updater/model.py]
>> @@ -378,5 +379,22 @@ class _Downloader(gobject.GObject):
> [...]
>> +    def _check_integrity(self):
>> +        bundle_path = self._output_file.get_path()
>> +
>> +        try:
>> +            bundle_file = ZipFile(bundle_path, 'r')
>> +        except:
>> +            passed = False
>> +        else:
>> +            passed = (bundle_file.testzip() is None)
>> +            bundle_file.close()
>> +
>> +        if passed:
>>              self.emit('finish', True)
>> +        else:
>> +            logging.error('updater: %s bundle file is corrupt' % bundle_path)
>> +            self.emit('finish', False)
>

I like it more, but dextrose used python 2.6 and content management
for zipfile is available since 2.7 ;/

> A more concise way of implementing this would be:
>
>    def _check_integrity(self):
>        bundle_path = self._output_file.get_path()
>        try:
>            with ZipFile(bundle_path, 'r') as bundle_file:
>                bundle_file.testzip()
>        except zipfile.BadZipfile:
>            logging.exception('Downloaded corrupt bundle %s:', bundle_path)
>            self.emit('finish', False)
>        else:
>            self.emit('finish', True)
>
>
> Sascha
>
> --
> http://sascha.silbe.org/
> http://www.infra-silbe.de/
>


More information about the Dextrose mailing list