Modification du converter pour permettre la conversion des sauvegardes utilisateurs vers le nouveau format shelves.

Les données utilisateurs sont stockées dans le repertoire personnel plutot que dans /user/data
This commit is contained in:
Le_dahut 2014-03-08 22:07:20 +01:00
parent a8c7706059
commit 8021754366
1 changed files with 70 additions and 6 deletions

View File

@ -3,13 +3,24 @@
import shelve import shelve
import csv import csv
import os
import pyglet import pyglet
from pyglet import image from pyglet import image
from os.path import expanduser
global items,worlds global items,worlds,finished
'''********************* fonctions Chargement ANCIENNE ****************************************************************''' '''********************* fonctions Chargement ANCIENNE ****************************************************************'''
def readpref(file):
global finished
with open(file, 'a+') as f:
try:
finished=list(csv.reader(f,delimiter=';'))[0]
f.close()
except:
print "no"
def loaditems(n,file): def loaditems(n,file):
global items global items
with open(file, 'rb') as f: with open(file, 'rb') as f:
@ -76,6 +87,23 @@ def readgrid(file):
'''********************* fonction ecriture NOUVELLE ****************************************************************''' '''********************* fonction ecriture NOUVELLE ****************************************************************'''
def sync():
global Uworlds,finished
write(gethome()+"/dbdata",["Uworlds","finished"])
def verifyhome():
global Uworlds,finished
if not os.path.exists(gethome()):
os.makedirs(gethome())
if not os.path.exists(gethome()+"/dbdata"):
Uworlds=[[{0:0}]]
finished=[(0,0)]
sync()
def gethome():
home = expanduser("~")+"/.wirechem"
return home
def write(afile,var): def write(afile,var):
d=shelve.open(afile,writeback=True) d=shelve.open(afile,writeback=True)
for k in var: for k in var:
@ -91,7 +119,13 @@ loaditems(int("0x20000", 16),"data/menus.dat")
loaditems(0,"data/elements.dat") loaditems(0,"data/elements.dat")
worlds=[] worlds=[]
Uworlds=[] Uworlds=[]
verifyhome()
readpref("user/pref.dat")
linked=finished
finished=[]
for k in linked:
if len(k)>4:
finished.append((int(k[5]),int(k[7])))
for i in range(sizeworld): for i in range(sizeworld):
ele=items[items[int("0x40000",16)+i]] ele=items[items[int("0x40000",16)+i]]
readgrid(ele['file']) readgrid(ele['file'])
@ -100,7 +134,7 @@ for i in range(sizeworld):
worlds.append(0) worlds.append(0)
worlds[ele['world']]=[] worlds[ele['world']]=[]
while len(worlds[ele['world']])<=ele['grid']: while len(worlds[ele['world']])<=ele['grid']:
worlds[ele['world']].append(0) worlds[ele['world']].append({})
link=[] link=[]
for k in ele['validate']: for k in ele['validate']:
if len(k)>4: if len(k)>4:
@ -126,8 +160,39 @@ for i in range(sizeworld):
'maxtemp':maxtemp, 'maxtemp':maxtemp,
'world_new':world_new, 'world_new':world_new,
'world_art':world_art} 'world_art':world_art}
print worlds
world_art=[]
if os.path.exists("user/"+ele['file']):
print ele['file']
readgrid("user/"+ele['file'])
while len(Uworlds)<=ele['world']:
Uworlds.append(0)
Uworlds[ele['world']]=[]
while len(Uworlds[ele['world']])<=ele['grid']:
Uworlds[ele['world']].append({})
Uworlds[ele['world']][ele['grid']]={'nom':nom,
'element':element,
'description':descriptif,
'_xx':ele['coordx'],
'_yy':ele['coordy'],
'video':ele['tuto']!="",
'link':link,
'tech':tech,
'cout':cout,
'victory':victory,
'current':current,
'cycle':cycle,
'nrj':nrj,
'rayon':rayon,
'temp':temp,
'maxcycle':maxcycle,
'maxnrj':maxnrj,
'maxrayon':maxrayon,
'maxtemp':maxtemp,
'world_new':world_new,
'world_art':world_art}
write("dbdata",["worlds"]) write("dbdata",["worlds"])
write(gethome()+"/dbdata",["Uworlds","finished"])
f=open("dbsrc", 'wb+') f=open("dbsrc", 'wb+')
afile="""#!/usr/bin/env python afile="""#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
@ -147,4 +212,3 @@ global worlds
worlds=""" worlds="""
f.write(afile+str(worlds).replace(", '",",\n '").replace(", [",", \n\t\t\t[")+"""\nwrite("dbdata",["worlds"])""") f.write(afile+str(worlds).replace(", '",",\n '").replace(", [",", \n\t\t\t[")+"""\nwrite("dbdata",["worlds"])""")
f.close() f.close()