Go to the documentation of this file.00001
00002
00003 from odb import *
00004 import profiler
00005 import socket
00006
00007 USER = 'root'
00008 PASSWORD = ''
00009 DATABASE = 'trans_data'
00010
00011 class TransStringTable(Table):
00012
00013
00014
00015 def _defineRows(self):
00016 self.d_addColumn("string_id", kInteger, primarykey=1, autoincrement=1)
00017
00018 self.d_addColumn("string", kBigString, indexed=1)
00019
00020
00021
00022
00023
00024 class TransLocTable(Table):
00025
00026
00027
00028
00029 def _defineRows(self):
00030 self.d_addColumn("loc_id", kInteger, primarykey=1, autoincrement=1)
00031 self.d_addColumn("string_id", kInteger, indexed=1)
00032 self.d_addColumn("version", kInteger, default=0)
00033 self.d_addColumn("filename", kVarString, 255, indexed=1)
00034 self.d_addColumn("location", kVarString, 255)
00035
00036
00037
00038
00039 class TransMapTable(Table):
00040
00041
00042
00043 def _defineRows(self):
00044 self.d_addColumn("string_id", kInteger, primarykey=1)
00045 self.d_addColumn("lang", kFixedString, 2, primarykey=1)
00046 self.d_addColumn("string", kBigString)
00047
00048 class DB(Database):
00049 def __init__(self, db, debug=0):
00050 self.db = db
00051 self._cursor = None
00052 self.debug = debug
00053
00054 self.addTable("strings", "nt_trans_strings", TransStringTable)
00055 self.addTable("locs", "nt_trans_locs", TransLocTable)
00056 self.addTable("maps", "nt_trans_maps", TransMapTable)
00057
00058 def defaultCursor(self):
00059
00060 if self._cursor is None:
00061 if self.debug:
00062 self._cursor = profiler.ProfilerCursor(self.db.cursor())
00063 else:
00064 self._cursor = self.db.cursor()
00065
00066 return self._cursor
00067
00068 def trans_connect(host = 'localhost', debug=0):
00069
00070 if host != 'localhost':
00071 local_name = socket.gethostname()
00072 if string.find(local_name, '.') == -1:
00073 local_name = local_name + ".neotonic.com"
00074 if local_name == host:
00075 host = 'localhost'
00076
00077 if debug: p = profiler.Profiler("SQL", "Connect -- %s:trans" % (host))
00078 db = MySQLdb.connect(host = host, user=USER, passwd = PASSWORD, db=DATABASE)
00079 if debug: p.end()
00080
00081 retval = DB(db, debug=debug)
00082 return retval