Crossfire Server, Trunk
CFBank_Init.py
Go to the documentation of this file.
1 import os.path
2 
3 import Crossfire
4 import CFBank
5 
6 def convert_bdb(bank):
7  path = os.path.join(Crossfire.LocalDirectory(), 'ImperialBank_DB.db')
8  if os.path.isfile(path):
9  Crossfire.Log(Crossfire.LogInfo, "Converting ImperialBank_DB.db (BDB)")
10  import berkeleydb.dbshelve as shelve
11  accounts = shelve.open(path, 'r')
12  for account in accounts.keys():
13  name = account.decode('ascii')
14  balance = accounts[account]
15  bank.deposit(name, balance)
16  accounts.close()
17  bak_file = os.path.join(Crossfire.LocalDirectory(), 'ImperialBank_DB.db.bak')
18  os.rename(path, bak_file)
19 
20 def convert(bank):
21  path = os.path.join(Crossfire.LocalDirectory(), 'ImperialBank_DB')
22  if os.path.isfile(path):
23  Crossfire.Log(Crossfire.LogInfo, "Converting ImperialBank_DB (DBM)")
24  import shelve
25  s = shelve.open(path, 'r')
26  for name, balance in s.iteritems():
27  bank.deposit(name, balance)
28  s.close()
29  bak_file = os.path.join(Crossfire.LocalDirectory(), 'ImperialBank_DB.bak')
30  os.rename(path, bak_file)
31 
32 def main():
33  Crossfire.Log(Crossfire.LogInfo, "Initializing CFBank")
34  with CFBank.CFBank() as bank:
35  bank.init_schema()
36  convert_bdb(bank)
37  convert(bank)
38 
39 main()
CFBank_Init.main
def main()
Definition: CFBank_Init.py:32
convert
Definition: convert.py:1
CFBank.CFBank
Definition: CFBank.py:10
CFBank_Init.convert
def convert(bank)
Definition: CFBank_Init.py:20
CFBank_Init.convert_bdb
def convert_bdb(bank)
Definition: CFBank_Init.py:6