Change service format from pickle based to json based.

This commit is contained in:
Tomas Groth 2013-06-30 14:14:30 +02:00
parent 1760e68a9f
commit 5c8c3145bc

View File

@ -32,6 +32,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
@ -477,7 +478,7 @@ class ServiceManager(QtGui.QWidget):
path_file_name = unicode(self.fileName()) path_file_name = unicode(self.fileName())
path, file_name = os.path.split(path_file_name) path, file_name = os.path.split(path_file_name)
basename = os.path.splitext(file_name)[0] basename = os.path.splitext(file_name)[0]
service_file_name = '%s.osd' % basename service_file_name = '%s.osj' % basename
log.debug(u'ServiceManager.saveFile - %s', path_file_name) log.debug(u'ServiceManager.saveFile - %s', path_file_name)
SettingsManager.set_last_dir( SettingsManager.set_last_dir(
self.mainwindow.serviceManagerSettingsSection, self.mainwindow.serviceManagerSettingsSection,
@ -542,7 +543,7 @@ class ServiceManager(QtGui.QWidget):
total_size += file_size total_size += file_size
log.debug(u'ServiceManager.saveFile - ZIP contents size is %i bytes' % log.debug(u'ServiceManager.saveFile - ZIP contents size is %i bytes' %
total_size) total_size)
service_content = cPickle.dumps(service) service_content = json.dumps(service)
# Usual Zip file cannot exceed 2GiB, file with Zip64 cannot be # Usual Zip file cannot exceed 2GiB, file with Zip64 cannot be
# extracted using unzip in UNIX. # extracted using unzip in UNIX.
allow_zip_64 = (total_size > 2147483648 + len(service_content)) allow_zip_64 = (total_size > 2147483648 + len(service_content))
@ -672,12 +673,15 @@ class ServiceManager(QtGui.QWidget):
log.debug(u'Extract file: %s', osfile) log.debug(u'Extract file: %s', osfile)
zipinfo.filename = osfile zipinfo.filename = osfile
zip.extract(zipinfo, self.servicePath) zip.extract(zipinfo, self.servicePath)
if osfile.endswith(u'osd'): if osfile.endswith(u'osd') or osfile.endswith(u'osj'):
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():
Receiver.send_message(u'cursor_busy') Receiver.send_message(u'cursor_busy')
fileTo = open(p_file, u'r') fileTo = open(p_file, u'r')
items = cPickle.load(fileTo) if p_file.endswith(u'osj'):
items = json.load(fileTo)
else:
items = cPickle.load(fileTo)
fileTo.close() fileTo.close()
self.newFile() self.newFile()
self.mainwindow.displayProgressBar(len(items)) self.mainwindow.displayProgressBar(len(items))