Files
entropy/libraries/dumpTools.py
lxnay dd59c1b146 Entropy/Equo:
- Socket Interface:
  - completed termination strings
  - completed the basic structure and protocol specifications
- Database backend:
  - removed useless indexes
  - implemented useful indexes
  - improved queries speed (whose make dependencies calculation faster)
  - implemented tables automigration to INTEGER PRIMARY KEY AUTOINCREMENT to allow future repositories differential updates
- Entropy as user:
  - made equo update possible to be run for users in 'entropy' group, this will allow to have a powerful GUI notification applet
- improved repositories synchronization speed


git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@1521 cd1c1023-2f26-0410-ae45-c471fc1f0318
2008-03-27 20:06:34 +00:00

110 lines
3.3 KiB
Python

#!/usr/bin/python
'''
# DESCRIPTION:
# load/save a data to file by dumping its structure
Copyright (C) 2007-2008 Fabio Erculiani
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
from entropyConstants import *
try:
import cPickle as pickle
except ImportError:
import pickle
'''
@description: dump object to file
@input: name of the object, object
@output: status code
'''
def dumpobj(name, object, completePath = False):
while 1: # trap ctrl+C
if completePath:
dmpfile = name
else:
dump_path = os.path.join(etpConst['dumpstoragedir'],name)
dump_dir = os.path.dirname(dump_path)
#dump_name = os.path.basename(dump_path)
if not os.path.isdir(dump_dir):
os.makedirs(dump_dir,0775)
const_setup_perms(dump_dir,etpConst['entropygid'])
dmpfile = dump_path+".dmp"
if os.path.isfile(dmpfile):
os.remove(dmpfile)
f = open(dmpfile,"wb")
pickle.dump(object,f)
os.chmod(dmpfile,0664)
if etpConst['entropygid'] != None:
os.chown(dmpfile,-1,etpConst['entropygid'])
f.flush()
f.close()
break
'''
@description: serialize object to f (file)
@input: object, file object
@output: file object, pointer to the beginning
'''
def serialize(object, f):
pickle.dump(object,f)
f.flush()
f.seek(0)
return f
'''
@description: unserialize file to object (file)
@input: file object
@output: object
'''
def unserialize(f):
x = pickle.load(f)
return x
'''
@description: load object from a file
@input: name of the object
@output: object or, if error -1
'''
def loadobj(name, completePath = False):
while 1:
if completePath:
dmpfile = name
else:
dump_path = os.path.join(etpConst['dumpstoragedir'],name)
#dump_dir = os.path.dirname(dump_path)
#dump_name = os.path.basename(dump_path)
dmpfile = dump_path+".dmp"
if os.path.isfile(dmpfile) and os.access(dmpfile,os.R_OK):
f = open(dmpfile,"rb")
x = None
try:
x = pickle.load(f)
except ValueError:
pass
except EOFError:
pass
except pickle.UnpicklingError:
pass
f.close()
return x
break
def removeobj(name):
if os.path.isfile(etpConst['dumpstoragedir']+"/"+name+".dmp"):
try:
os.remove(etpConst['dumpstoragedir']+"/"+name+".dmp")
except OSError:
pass