db_trans.py
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     # access patterns:
00013     #   -> lookup individual entries by string_id
00014     #   -> lookup entry by string
00015     def _defineRows(self):
00016         self.d_addColumn("string_id", kInteger, primarykey=1, autoincrement=1)
00017         # we can't actually index this... but we can index part with myisam
00018         self.d_addColumn("string", kBigString, indexed=1)
00019 
00020 ## hmm, on second thought, storing this is in the database is kind 
00021 ## of silly..., since it essentially could change with each run.  It may
00022 ## not even be necessary to store this anywhere except in memory while 
00023 ## trans is running
00024 class TransLocTable(Table):
00025     # access patterns:
00026     #   -> find "same" entry by filename/offset
00027     #   -> dump all locations for a version
00028     #   -> maybe: find all locations for a filename
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         # this can either be:
00036         # ofs:x:y
00037         # hdf:foo.bar.baz
00038 
00039 class TransMapTable(Table):
00040     # access patterns:
00041     #   -> dump all for a language
00042     #   -> lookup entry by string_id/lang
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         # share one cursor for this db object!
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     # try to optimize connection if on this machine
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


pyclearsilver
Author(s): Scott Hassan/hassan@willowgarage.com
autogenerated on Sat Dec 28 2013 17:47:30