From f6f93f41d15a56889c7633132666603c35192754 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sun, 9 Jun 2013 14:14:25 +0200 Subject: [PATCH] Use json as services format instead of python pickle. --- openlp/core/ui/servicemanager.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 8ddd4135e..14b75638f 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -35,6 +35,7 @@ import logging import os import shutil import zipfile +import json from tempfile import mkstemp from datetime import datetime, timedelta @@ -458,7 +459,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog): path_file_name = unicode(self.file_name()) path, file_name = os.path.split(path_file_name) base_name = os.path.splitext(file_name)[0] - service_file_name = '%s.osd' % base_name + service_file_name = '%s.osjd' % base_name log.debug(u'ServiceManager.save_file - %s', path_file_name) Settings().setValue(self.main_window.service_manager_settings_section + u'/last directory', path) service = [] @@ -512,7 +513,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog): file_size = os.path.getsize(file_item) total_size += file_size log.debug(u'ServiceManager.save_file - ZIP contents size is %i bytes' % total_size) - service_content = cPickle.dumps(service) + service_content = json.dumps(service) # Usual Zip file cannot exceed 2GiB, file with Zip64 cannot be extracted using unzip in UNIX. allow_zip_64 = (total_size > 2147483648 + len(service_content)) log.debug(u'ServiceManager.save_file - allowZip64 is %s' % allow_zip_64) @@ -572,7 +573,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog): path_file_name = unicode(self.file_name()) path, file_name = os.path.split(path_file_name) base_name = os.path.splitext(file_name)[0] - service_file_name = '%s.osd' % base_name + service_file_name = '%s.osjd' % base_name log.debug(u'ServiceManager.save_file - %s', path_file_name) Settings().setValue(self.main_window.service_manager_settings_section + u'/last directory', path) service = [] @@ -698,11 +699,14 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog): log.debug(u'Extract file: %s', osfile) zip_info.filename = osfile zip_file.extract(zip_info, self.servicePath) - if osfile.endswith(u'osd'): + if osfile.endswith(u'osjd') or osfile.endswith(u'osd'): p_file = os.path.join(self.servicePath, osfile) if 'p_file' in locals(): file_to = open(p_file, u'r') - items = cPickle.load(file_to) + if osfile.endswith(u'osjd'): + items = json.load(file_to) + else: + items = cPickle.load(file_to) file_to.close() self.new_file() self.set_file_name(file_name)