Use json as services format instead of python pickle.

This commit is contained in:
Tomas Groth 2013-06-09 14:14:25 +02:00
parent 93cce9c3aa
commit f6f93f41d1
1 changed files with 9 additions and 5 deletions

View File

@ -35,6 +35,7 @@ import logging
import os import os
import shutil import shutil
import zipfile import zipfile
import json
from tempfile import mkstemp from tempfile import mkstemp
from datetime import datetime, timedelta from datetime import datetime, timedelta
@ -458,7 +459,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
path_file_name = unicode(self.file_name()) path_file_name = unicode(self.file_name())
path, file_name = os.path.split(path_file_name) path, file_name = os.path.split(path_file_name)
base_name = os.path.splitext(file_name)[0] 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) log.debug(u'ServiceManager.save_file - %s', path_file_name)
Settings().setValue(self.main_window.service_manager_settings_section + u'/last directory', path) Settings().setValue(self.main_window.service_manager_settings_section + u'/last directory', path)
service = [] service = []
@ -512,7 +513,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
file_size = os.path.getsize(file_item) file_size = os.path.getsize(file_item)
total_size += file_size total_size += file_size
log.debug(u'ServiceManager.save_file - ZIP contents size is %i bytes' % total_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. # 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)) allow_zip_64 = (total_size > 2147483648 + len(service_content))
log.debug(u'ServiceManager.save_file - allowZip64 is %s' % allow_zip_64) 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 = unicode(self.file_name())
path, file_name = os.path.split(path_file_name) path, file_name = os.path.split(path_file_name)
base_name = os.path.splitext(file_name)[0] 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) log.debug(u'ServiceManager.save_file - %s', path_file_name)
Settings().setValue(self.main_window.service_manager_settings_section + u'/last directory', path) Settings().setValue(self.main_window.service_manager_settings_section + u'/last directory', path)
service = [] service = []
@ -698,11 +699,14 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
log.debug(u'Extract file: %s', osfile) log.debug(u'Extract file: %s', osfile)
zip_info.filename = osfile zip_info.filename = osfile
zip_file.extract(zip_info, self.servicePath) 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) p_file = os.path.join(self.servicePath, osfile)
if 'p_file' in locals(): if 'p_file' in locals():
file_to = open(p_file, u'r') 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() file_to.close()
self.new_file() self.new_file()
self.set_file_name(file_name) self.set_file_name(file_name)