<s> from gluon . sql import DAL , Field <EOL> class ITM_DB ( ) : <EOL> FILENAME = '<STR_LIT>' <EOL> CONNECTION = '<STR_LIT>' . format ( FILENAME ) <EOL> DEFAULT_OPTIONS = { } <EOL> def __init__ ( self , path = None , isInit = False ) : <EOL> self . isInit = isInit <EOL> if path is not None : <EOL> self . db = DAL ( ITM_DB . CONNECTION , lazy_tables = not self . isInit , migrate = self . isInit , folder = path ) <EOL> else : <EOL> self . db = DAL ( ITM_DB . CONNECTION , lazy_tables = not self . isInit , migrate = self . isInit ) <EOL> def __enter__ ( self ) : <EOL> self . DefineOptionsTable ( ) <EOL> return self <EOL> def __exit__ ( self , type , value , traceback ) : <EOL> self . db . commit ( ) <EOL> def DefineOptionsTable ( self ) : <EOL> self . db . define_table ( '<STR_LIT>' , <EOL> Field ( '<STR_LIT:key>' , '<STR_LIT:string>' , required = True , unique = True ) , <EOL> Field ( '<STR_LIT:value>' , '<STR_LIT:string>' , required = True ) , <EOL> migrate = self . isInit <EOL> ) <EOL> for key , value in ITM_DB . DEFAULT_OPTIONS . iteritems ( ) : <EOL> self . SetOption ( key , value , overwrite = self . isInit ) <EOL> def SetOption ( self , key , value , overwrite = True ) : <EOL> where = self . db . options . key == key <EOL> if self . db ( where ) . count ( ) > <NUM_LIT:0> : <EOL> if overwrite : <EOL> self . db ( where ) . update ( value = value ) <EOL> else : <EOL> self . db . options . insert ( key = key , value = value ) <EOL> self . db . commit ( ) <EOL> def GetOption ( self , key ) : <EOL> where = self . db . options . key == key <EOL> keyValue = self . db ( where ) . select ( self . db . options . value ) . first ( ) <EOL> if keyValue : <EOL> return keyValue . value <EOL> else : <EOL> return None <EOL> def Reset ( self ) : <EOL> pass </s>
