File: db_upgrade.py

package info (click to toggle)
pyscrabble 1.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 15,276 kB
  • ctags: 1,396
  • sloc: python: 11,667; sh: 429; makefile: 67
file content (37 lines) | stat: -rw-r--r-- 905 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'''
Use me to upgrade the old shelve-backed database to ZODB
'''
import shelve
from pyscrabble import db
from pyscrabble import manager

USER_LIST_LOCATION         = 'pyscrabble.users.list'
MESSAGES_LOCATION          = 'messages.list'
GAME_LIST_LOCATION         = 'pyscrabble.games.list'
SERVER_STATS_LOCATION      = 'server.stats.list'

r = manager.ResourceManager()
db = db.DB()

s = shelve.open(r["config"][USER_LIST_LOCATION], writeback = True)
for k,v in s.iteritems():
    db.users[k] = v
s.close()

s = shelve.open(r["config"][MESSAGES_LOCATION], writeback = True)
for k,v in s.iteritems():
    db.messages[k] = v
s.close()

s = shelve.open(r["config"][GAME_LIST_LOCATION], writeback = True)
for k,v in s.iteritems():
    db.games[k] = v
s.close()

s = shelve.open(r["config"][SERVER_STATS_LOCATION], writeback = True)
for k,v in s.iteritems():
    db.stats[k] = v
s.close()

db.sync()
print 'Done'