Package install :: Package MoSTBioDat :: Package DataBase :: Package Scheme :: Module MoSTBioDatScheme
[hide private]
[frames] | no frames]

Source Code for Module install.MoSTBioDat.DataBase.Scheme.MoSTBioDatScheme

  1  #!/usr/bin/env python 
  2  ########################################## 
  3  # MoSTBioDatScheme.py:                   # 
  4  # Relational Scheme for MoSTBioDatDB.py  # 
  5  ########################################## 
  6   
  7  ###################################################### 
  8  # Copyright (c) 2007-2008 Andrzej Bak                # 
  9  # ARC Seibersdorf & University of Silesia            # 
 10  # Author: Andrzej Bak <Andrzej.Bak@us.edu.pl>        # 
 11  # License: GNU General Public License, version: 3    # 
 12  # URL: http://chemoinformatyka.us.edu.pl/mostbiodat/ # 
 13  # Version: 1, 06.01.2010                             # 
 14  ###################################################### 
 15   
 16  try: 
 17      import sys 
 18      import shelve 
 19      import os 
 20      import anydbm 
 21      from MoSTBioDat.DataBase.Connect.MoSTBioDatDB import * 
 22      from MoSTBioDat.DataBase.Query.SQLBuilder.QueryBuilder import * 
 23  except ImportError,e: 
 24      print 'Error: %s' %e 
 25      sys.exit(1) 
 26  ############ MoSTBioDatScheme class ################## 
27 -class MoSTBioDatScheme(MoSTBioDatDB):
28 """ 29 INPUT: 30 host - string, host to connect 31 user - string, user to connect as 32 passwd - string, password to use 33 db - string, database to use 34 port - integer, TCP/IP port to connect to 35 unix_socket - string, location of unix_socket to use 36 conv - conversion dictionary, see MySQLdb.converters 37 connect_timeout - number of seconds to wait before the connection attempt fails. 38 compress - if set, compression is enabled 39 named_pipe - if set, a named pipe is used to connect (Windows only) 40 init_command - command which is run once the connection is created 41 read_default_file - file from which default client values are read 42 read_default_group - configuration group to use from the default file 43 cursorclass - class object, used to create cursors (keyword only) 44 use_unicode - if True, text-like columns are returned as unicode objects 45 using the connection's character set. Otherwise, text-like 46 columns are returned as strings. columns are returned as 47 normal strings. Unicode objects will always be encoded to 48 the connection's character set regardless of this setting. 49 charset - if supplied, the connection character set will be changed 50 to this character set (MySQL-4.1 and newer). This implies 51 use_unicode=True. 52 sql_mode - if supplied, the session SQL mode will be changed to this 53 setting (MySQL-4.1 and newer). For more details and legal 54 values, see the MySQL documentation. 55 client_flag - integer, flags to use or 0 56 (see MySQL docs or constants/CLIENTS.py) 57 ssl - dictionary or mapping, contains SSL connection parameters; 58 see the MySQL documentation for more details 59 (mysql_ssl_set()). If this is set, and the client does not 60 support SSL, NotSupportedError will be raised. 61 local_infile - integer, non-zero enables LOAD LOCAL INFILE; zero disables 62 format - string format for log handler 63 filter - filter object from logger object 64 datefmt - data/time format 65 path - directory path to log file 66 filename - log filename, default log 67 filemode - mode to open log file, default='a' 68 level - set root logger level to specified level 69 logfilelevel- set level to log file 70 cache - create cache for query, default=True 71 scheme2file - Boolean - save database scheme to shelve file 72 log - log flag, boolean default=False 73 OUTPUT: 74 class object 75 """
76 - def __init__(self,host='localhost',db='',user=None,passwd=None,port=3306,scheme2file=True,log=False,**kwargs):
77 MoSTBioDatDB.__init__(self,host,db,user,passwd,port,cache=False,**kwargs) 78 self.scheme2file=scheme2file 79 self.connectDB() 80 self.logging=log
81
82 - def executeQuery(self,query):
83 """ 84 execute SQL query 85 INPUT: 86 SQL query - str 87 OUTPUT: 88 list of cursor dictionary 89 """ 90 if self.connection: 91 if self.logging: 92 self.log.info('Query execution: %s',query) 93 try: 94 self.cursor=self.connection.cursor(cursorclass=MySQLdb.cursors.DictCursor) 95 except MySQLdb.InternalError, e: 96 self.connection=None 97 if self.logging: 98 self.log.exception('Cursor error: %s',e) 99 raise InternalError(ErrorMessage(e)) 100 else: 101 if self.kwargs['db']: 102 try: 103 self.cursor.execute('use %s;' %self.kwargs['db']) 104 except MySQLdb.Error,e: 105 if self.logging: 106 self.log.exception('MySQLdb error: %s',e) 107 raise Error(ErrorMessage(e)) 108 try: 109 t0=time.time() 110 self.cursor.execute(query) 111 self.commit() 112 113 except MySQLdb.OperationalError,e: 114 if self.logging: 115 self.log.exception('Operational error: %s',e) 116 raise OperationalError(ErrorMessage(e)) 117 sys.exit(1) 118 except MySQLdb.ProgrammingError,e: 119 if self.logging: 120 self.log.exception('Programming error: %s',e) 121 raise ProgrammingError(ErrorMessage(e)) 122 except MySQLdb.IntegrityError,e: 123 if self.logging: 124 self.log.exception('Integrity error: %s',e) 125 raise IntegrityError(ErrorMessage(e)) 126 except MySQLdb.InternalError,e: 127 if self.logging: 128 self.log.exception('Internal error: %s',e) 129 raise InternalError(ErrorMessage(e)) 130 except MySQLdb.DataError,e: 131 if self.logging: 132 self.log.exception('Data error error: %s',e) 133 raise DataError(ErrorMessage(e)) 134 except MySQLdb.NotSupportedError,e: 135 if self.logging: 136 self.log.exception('Not supported error: %s',e) 137 raise NotSupportedError(ErrorMessage(e)) 138 except MySQLdb.DatabaseError,e: 139 if self.logging: 140 self.log.exception('Database error: %s',e) 141 raise DatabaseError(ErrorMessage(e)) 142 except MySQLdb.InterfaceError,e: 143 if self.logging: 144 self.log.exception('Interface error: %s',e) 145 raise InterfaceError(ErrorMessage(e)) 146 except MySQLdb.Warning,e: 147 if self.logging: 148 self.log.exception('Warning: %s',e) 149 raise Warning(ErrorMessage(e)) 150 except MySQLdb.Error,e: 151 if self.logging: 152 self.log.exception('MySQLdb error: %s',e) 153 raise Error(ErrorMessage(e)) 154 else: 155 dblist=[] 156 while True: 157 row=self.cursor.fetchone() 158 if not row: 159 break 160 dblist.append(row) 161 t1=time.time() 162 dt=t1-t0 163 if self.logging: 164 self.log.info('Database time query execution:%s',geTime(dt)) 165 self.cursor.close() 166 return dblist # list of cursor dictionary 167 else: 168 print 'Connect to database!'
169
170 - def lastInsID(self):
171 """ 172 last inserted ID 173 INPUT: 174 class object 175 OUTPUT: 176 lastID - int, last inserted ID 177 """ 178 lastID='SELECT LAST_INSERT_ID();' 179 result=self.executeQuery(lastID) 180 lastID=result[0]['LAST_INSERT_ID()'] 181 return lastID
182
183 - def geTables(self):
184 """ 185 get database tables 186 INPUT: 187 class object 188 OUTPUT: 189 cursor dictionary with table name 190 """ 191 return self.executeQuery('show tables;')
192
193 - def geTablesDesc(self,**kwarg):
194 """ 195 get tables description 196 INPUT: 197 temporary - str - filename path to temporary directory, default /tmp/SchemeDB 198 schemepath - str - path to scheme directory, default /tmp/SchemeDB 199 schemefilename - str - scheme filename, default dbsheme 200 protocol - int - shelve protocol, default highest -1 201 """ 202 self.kwarg={} 203 self.kwarg=kwarg 204 keys=("temporary","schemepath","schemefilename","protocol") 205 filter(lambda key: filterKeys(kwarg,keys,key),kwarg.keys()) 206 if not self.kwarg.has_key('schemepath'): 207 self.kwarg.setdefault('schemepath','/tmp/SchemeDB') 208 if not self.kwarg.has_key('schemefilename'): 209 self.kwarg.setdefault('schemefilename','dbscheme') 210 if not self.kwarg.has_key('protocol'): 211 self.kwarg.setdefault('protocol',-1) 212 if not self.kwarg.has_key('temporary'): 213 self.kwarg.setdefault('temporary','/tmp/SchemeDB') 214 215 tables=self.geTables()#get tables 216 if not tables: 217 print 'No tables in database!' 218 self.log.info("No tables in database!") 219 sys.exit(1) 220 else: 221 tabdict={} 222 t0=time.time() 223 for item in tables: 224 tabname=item.values()[0] 225 tabquery='desc '+str(tabname)+';' 226 tablist=self.executeQuery(tabquery)#SQL desc table; 227 tabdict[tabname]=tablist #insert desc to dictionary 228 t1=time.time() 229 dt=t1-t0 230 print 'Number of tables: %d rows in %s' %(len(tables),geTime(dt)) 231 if self.scheme2file: 232 self.createdict()#create dictionary 233 try: 234 dbscheme=shelve.open(self.dictfullfilename,protocol=self.kwarg['protocol']) 235 except anydbm.error,error: 236 print 'Error: %s, %s' %(error,self.dictfullfilename) 237 else: 238 for key,value in tabdict.iteritems(): 239 dbscheme[key]=value#insert into shelve dictionary 240 dbscheme.close() 241 return tabdict
242
243 - def geTableDesc(self,tablename=None,**kwarg):
244 """ 245 get table description 246 INPUT: 247 temporary - str - filename path to temporary directory, default /tmp/SchemeDB 248 schemepath - str - path to scheme directory, default /tmp/SchemeDB 249 schemefilename - str - scheme filename, default dbsheme 250 protocol - int - shelve protocol, default highest -1 251 """ 252 self.kwarg={} 253 self.kwarg=kwarg 254 keys=("temporary","schemepath","schemefilename","protocol") 255 filter(lambda key: filterKeys(kwarg,keys,key),kwarg.keys()) 256 if not self.kwarg.has_key('schemepath'): 257 self.kwarg.setdefault('schemepath','/tmp/SchemeDB') 258 if not self.kwarg.has_key('schemefilename'): 259 self.kwarg.setdefault('schemefilename','dbscheme') 260 if not self.kwarg.has_key('protocol'): 261 self.kwarg.setdefault('protocol',-1) 262 if not self.kwarg.has_key('temporary'): 263 self.kwarg.setdefault('temporary','/tmp/SchemeDB') 264 265 if not tablename: 266 print 'Error: Table not specified!' 267 sys.exit(1) 268 269 tabquery='show tables like \'%s\';' %tablename 270 tablist=self.executeQuery(tabquery) 271 272 if not tablist: 273 print 'Error: No table in database!' 274 sys.exit(1) 275 276 tabdict={} 277 t0=time.time() 278 tabquery='desc %s;'%tablename 279 tablist=self.executeQuery(tabquery)#SQL desc table; 280 tabdict[tablename]=tablist #insert desc to dictionary 281 t1=time.time() 282 dt=t1-t0 283 print '%s scheme loaded in%s' %(tablename,geTime(dt)) 284 if self.scheme2file: 285 self.createdict()#create dictionary 286 try: 287 dbscheme=shelve.open(self.dictfullfilename,protocol=self.kwarg['protocol']) 288 except anydbm.error,error: 289 print 'Error: %s, %s' %(error,self.dictfullfilename) 290 else: 291 for key,value in tabdict.iteritems(): 292 dbscheme[key]=value#insert into shelve dictionary 293 dbscheme.close() 294 return tabdict
295
296 - def createdict(self):
297 """ 298 create dictionary 299 INPUT: 300 class object 301 OUTPUT: 302 path to dictionary 303 """ 304 if self.kwarg['schemepath']=='': 305 self.kwarg['schemepath']=os.path.abspath(os.curdir) 306 if not os.path.isdir(self.kwarg['schemepath']): 307 try: 308 os.makedirs(self.kwarg['schemepath']) 309 except Exception,error: 310 print 'Error: %s, %s for %s' %(error[0],error[1],self.kwarg['schemepath']) 311 print 'Scheme files in %s' %self.kwarg['temporary']#create directory in temporary path 312 self.kwarg['schemepath']=self.kwarg['temporary'] 313 if not os.path.exists(self.kwarg['schemepath']): 314 os.makedirs(self.kwarg['schemepath']) 315 else: 316 if not os.access(self.kwarg['schemepath'],os.W_OK): 317 print 'Error: Permission denied! Unable to write in %s' %self.kwarg['schemepath'] 318 self.kwarg['schemepath']=self.kwarg['temporary'] 319 if not os.path.exists(self.kwarg['schemepath']): 320 os.makedirs(self.kwarg['schemepath']) 321 322 elif not os.access(self.kwarg['schemepath'],os.W_OK): 323 print 'Error: Permission denied! Unable to write in %s' %self.kwarg['schemepath'] 324 sys.exit(1) 325 326 self.dictfullfilename=os.path.join(self.kwarg['schemepath'],self.kwarg['schemefilename']) 327 print 'Scheme file: %s' %self.dictfullfilename
328 ################## End of class #######################
329 -def showdict(dictfullfilename,item='all'):
330 """ 331 show dictionary 332 INPUT: 333 dictfullfilename - str - dictionary filename full path 334 item - dictionary items, default 'all' 335 OUTPUT: 336 dictionary full filepath 337 """ 338 if (os.path.exists(dictfullfilename) and os.path.isfile(dictfullfilename)): 339 if os.access(dictfullfilename,os.R_OK): 340 try: 341 dbquery=shelve.open(dictfullfilename) 342 except anydbm.error,error: 343 print 'Error: %s for %s' %(error,dictfullfilename) 344 else: 345 if item=='all': 346 for key,value in dbquery.iteritems(): 347 print 'Table:',key, 'Column desc:',value 348 else: 349 tabledesc=dbquery.get(item,None)#get value 350 print item,tabledesc 351 else: 352 print 'Permission denied: %s' %dictfullfilename 353 else: 354 print 'Unable to find file!'
355
356 -class createHTML(object):
357 """ 358 INPUT: 359 dictfullfilename - scheme dictionary file full path 360 path - directory path for html files 361 OUTPUT: 362 opened dictionary 363 """
364 - def __init__(self,dictfullfilename,path='.',temporary='/tmp/SchemeDB'):
365 self.dictfullfilename=dictfullfilename 366 self.path=path 367 self.dbquery=None 368 self.temporary=temporary 369 self.openDict()#open dictionary 370 if self.dbquery: 371 self.createPath()#create path 372 self.createCss()#create style.css 373 self.createIndex()#create index.html 374 else: 375 print 'Unable to open dictionary file' 376 sys.exit(1)
377
378 - def openDict(self):
379 """ 380 open scheme dictionary 381 INPUT: 382 class object 383 OUTPUT: 384 opened dictionary 385 """ 386 if (os.path.exists(self.dictfullfilename) and os.path.isfile(self.dictfullfilename)): 387 if os.access(self.dictfullfilename,os.R_OK): 388 try: 389 dbquery=shelve.open(self.dictfullfilename) 390 except anydbm.error,error: 391 print 'Error: %s for %s' %(error,self.dictfullfilename) 392 else: 393 self.dbquery=dbquery 394 else: 395 print 'Permission denied: %s' %self.dictfullfilename 396 else: 397 print 'Unable to find file!'
398
399 - def createPath(self):
400 """ 401 create path with table.html 402 INPUT: 403 class object 404 OUTPUT: 405 path to scheme file 406 """ 407 if self.path=='': 408 self.path=os.path.abspath(os.curdir) 409 if not os.path.isdir(self.path): 410 try: 411 os.makedirs(self.path) 412 except Exception,error: 413 print 'Error: %s, %s for %s' %(error[0],error[1],self.path) 414 print 'HTML files in %s' %self.temporary#create directory in temporary path 415 self.path=self.temporary 416 if not os.path.exists(self.path): 417 os.makedirs(self.path) 418 else: 419 if not os.access(self.path,os.W_OK): 420 print 'Error: Permission denied! Unable to write in %s' %self.path 421 self.path=self.temporary 422 if not os.path.exists(self.path): 423 os.makedirs(self.path) 424 elif not os.access(self.path,os.W_OK): 425 print 'Error: Permission denied! Unable to write in %s' %self.path 426 sys.exit(1) 427 print 'Scheme HTML files: %s' %self.path
428
429 - def createCss(self):
430 """ 431 create style.css file 432 INPUT: 433 class object 434 OUTPUT: 435 opened css file 436 """ 437 csspath=os.path.join(self.path,"style.css") 438 try: 439 cssfile=open(csspath,'w') 440 except IOError,error: 441 print 'Error: %s, %s' %(error[0],error[1]) 442 else: 443 csscontents=""" 444 #page{ 445 margin-top:0px; 446 margin:auto; 447 border: none; 448 padding: 0px; 449 width: 758px; 450 height:auto; 451 min-height:560px; 452 margin-bottom:0px; 453 } 454 #header { 455 position: relative; 456 width:758px; 457 height:60px; 458 text-align: center; 459 background: #F0F0D0; 460 color: #A00000; 461 letter-spacing: 0.25em; 462 font-size: 28px; 463 font-family: sans-serif ; 464 border-bottom:5px double #A0A080; 465 border-top: 5px double #A0A080; 466 border-left:1px solid #A0A080; 467 border-right:1px solid #A0A080; 468 line-height: 60px; 469 text-align: center; 470 margin-bottom:3px; 471 } 472 #label { 473 position: relative; 474 width:758px; 475 height: 15px; 476 text-align: center; 477 color: #A00000; 478 letter-spacing: 0.25em; 479 font-size: 10px; 480 font-family: sans-serif ; 481 border-bottom:1px solid #FFFFFF; 482 border-top: 1px solid #FFFFFF; 483 border-left:1px solid #FFFFFF; 484 border-right:1px solid #FFFFFF; 485 line-height: 15px; 486 text-align: center; 487 margin-bottom:0px; 488 } 489 490 #main_page{ 491 position: relative; 492 display:block; 493 top: 3px; 494 left: 0px; 495 width: 758px; 496 height:auto; 497 min-height:440px; 498 font-family: sans-serif; 499 font-size: 14px; 500 color: #A00000; 501 text-align: center; 502 margin-top:0px; 503 margin-left:0px; 504 padding: 0px; 505 border: solid 1px #A0A080; 506 margin-bottom:0px; 507 } 508 509 #main_menu { 510 position: relative; 511 display: block; 512 top: 0px; 513 left: 0px; 514 width: 300px; 515 height: 20px; 516 font-family:sans-serif; 517 } 518 519 #main_menu a { 520 position: relative; 521 display: block; 522 width: 300px; 523 height: 20px; 524 text-align: center; 525 font-family:sans-serif; 526 font-size: 14px; 527 line-height: 20px; 528 padding: 1px 1px; 529 margin: 0 0 2; 530 border-width: 1; 531 border: solid 1px #A0A080; 532 text-decoration: none; 533 color: #A00000; 534 background: #F0F0D0; 535 border: solid 1px #A0A080; 536 } 537 538 #main_menu a:hover { 539 position: relative; 540 width: 290px; 541 height: 20px; 542 color: #EEE8AA; 543 background: #A0A080; 544 border-left: 5px solid #EEE8AA; 545 border-right: 5px solid #EEE8AA; 546 border-bottom: 2px solid #000000; 547 border-top: 2px solid #000000; 548 font-family:sans-serif; 549 font-size: 14px; 550 } 551 552 h5{ 553 font-size:12px; 554 text-align:center; 555 font-family:sans-serif; 556 letter-spacing: 0.20em; 557 } 558 559 #footnote{ 560 position: relative; 561 display:block; 562 top:0px; 563 left: 0px; 564 width: 758px; 565 height: 10px; 566 border: solid 1px #A0A080; 567 font-family:sans-serif; 568 text-align: right; 569 line-height: 25px; 570 border-bottom:5px double #A0A080; 571 border-top: 1px #A0A080; 572 border-left:#F0F0D0; 573 border-right:#F0F0D0; 574 margin-top:5px; 575 } 576 577 #main_menu1 a { 578 display: block; 579 text-align: center; 580 position:relative; 581 left: 10px; 582 top:10px; 583 width: 100px; 584 height: 13px; 585 font: 11px,Verdana, sans-serif; 586 padding: 3px 1px; 587 margin: 0 0 1; 588 border-width: 3; 589 text-decoration: none; 590 color: #A00000; 591 background: #F0F0D0; 592 border-bottom: 1px solid #A00000; 593 border-top: 1px solid #A00000; 594 border-right: 1px solid #A00000; 595 border-left: 1px solid #A00000; 596 } 597 598 #main_menu1 a:hover { 599 color: #F00000; 600 background: #F0F0D0; 601 border-bottom: 1px solid #F00000; 602 border-top: 1px solid #F00000; 603 border-left: 1px solid #F00000; 604 border-right: 1px solid #F00000; 605 } 606 table#tables{ 607 font-size: 12px; 608 font-family: sans-serif; 609 color: #A00000; 610 background: #E0E0C0; 611 text-align:center; 612 line-height:15px; 613 margin-bottom:30px; 614 padding-left:0px; 615 padding-right:0px 616 } 617 """ 618 cssfile.write(csscontents) 619 cssfile.close()
620
621 - def createIndex(self):
622 """ 623 create index.html file 624 INPUT: 625 class object 626 OUTPUT: 627 """ 628 indexpath=os.path.join(self.path,"index.html") 629 try: 630 indexfile=open(indexpath,'w') 631 except IOError,e: 632 print 'Error: %s' %e 633 else: 634 indexfile.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd\">\n") 635 indexfile.write("<html>\n") 636 indexfile.write("<head>\n") 637 indexfile.write("<title>Biomolecular Database Scheme</title>\n") 638 indexfile.write("<meta name=\"author\" content=\"abak\" lang=\"en\"\> \n") 639 indexfile.write("<meta name=\"keywords\" content=\"Biomolecular DataBase\" lang=\"en\"\>\n") 640 indexfile.write("<meta http-equiv=\"content-type\" content=\"text/html;charset=iso-8859-1\"\>\n") 641 indexfile.write("<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">\n") 642 indexfile.write("</head>\n") 643 indexfile.write("<body>\n") 644 indexfile.write("<div id=\"page\">\n") 645 indexfile.write("<div id=\"header\">\n") 646 indexfile.write("BIOMOLECULAR DATABASE SCHEME\n") 647 indexfile.write("</div>\n") 648 indexfile.write("<div id=\"label\">AUSTRIAN RESEARCH CENTERS - SEIBERSDORF\n") 649 indexfile.write("</div>\n") 650 indexfile.write("<div id=\"main_page\">\n") 651 indexfile.write("<h5>TABLE NAME:</h5>\n") 652 indexfile.write("<table valign=\"top\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">\n") 653 654 for tabname, tabdesc in self.dbquery.iteritems(): 655 indexfile.write("<tr>\n") 656 indexfile.write("<td valign=\"top\" align=\"center\" height=\"30\">\n") 657 indexfile.write("<div id=\"main_menu\">\n") 658 indexfile.write("<a href=\""+tabname+".html\">"+tabname+"</a>\n") 659 indexfile.write("</div>\n") 660 indexfile.write("</td>\n") 661 indexfile.write("</tr>\n") 662 self.createTablePage(tabname,tabdesc) 663 664 indexfile.write("<tr>\n") 665 indexfile.write("<td valign=\"top\" align=\"center\">\n") 666 indexfile.write("&nbsp\n") 667 indexfile.write("</td>\n") 668 indexfile.write("</tr>\n") 669 indexfile.write("</table>\n") 670 indexfile.write("</div>\n") 671 indexfile.write("<div id=\"footnote\">\n") 672 indexfile.write("</div>\n") 673 indexfile.write("</body>\n") 674 indexfile.write("</html>\n") 675 indexfile.close()
676
677 - def createTablePage(self,tabname,tabdesc):
678 """ 679 create table.html file 680 INPUT: 681 tabname - str - table name 682 tabdesc - str - table description 683 OUTPUT: 684 """ 685 tablepath=os.path.join(self.path,tabname+".html") 686 try: 687 tablefile=open(tablepath,'w') 688 except IOError,e: 689 print 'Error: %s' %e 690 else: 691 tablefile.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd\">\n") 692 tablefile.write("<html>\n") 693 tablefile.write("<head>\n") 694 tablefile.write("<title>Biomolecular Database Scheme</title>\n") 695 tablefile.write("<meta name=\"author\" content=\"abak\" lang=\"en\"\> \n") 696 tablefile.write("<meta name=\"keywords\" content=\"Biomolecular DataBase\" lang=\"en\"\>\n") 697 tablefile.write("<meta http-equiv=\"content-type\" content=\"text/html;charset=iso-8859-1\"\>\n") 698 tablefile.write("<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">\n") 699 tablefile.write("</head>\n") 700 tablefile.write("<body>\n") 701 tablefile.write("<div id=\"page\">\n") 702 tablefile.write("<div id=\"header\">\n") 703 tablefile.write("BIOMOLECULAR DATABASE SCHEME\n") 704 tablefile.write("</div>\n") 705 tablefile.write("<div id=\"label\">AUSTRIAN RESEARCH CENTERS - SEIBERSDORF\n") 706 tablefile.write("</div>\n") 707 tablefile.write("<div id=\"main_page\">\n") 708 tablefile.write("<div id=\"main_menu1\">\n") 709 tablefile.write("<a href=\"index.html\">MAIN PAGE</a>\n") 710 tablefile.write("</div>\n") 711 tablefile.write("<h5>TABLE NAME:</h5>\n") 712 if tabdesc!=[]: 713 tablefile.write("<table id=\"tables\" border=\"1\" cellpadding=\"5\" cellspacing=\"3\" align=\"center\">\n") 714 tablefile.write("<tr>\n") 715 tablefile.write("<td colspan=\"6\" align=\"center\" valign=\"top\">"+tabname+"</td>\n") 716 tablefile.write("</tr>\n") 717 tablefile.write("<tr>\n") 718 tablefile.write("<td> FIELD</td>\n") 719 tablefile.write("<td> TYPE</td>\n") 720 tablefile.write("<td> NULL</td>\n") 721 tablefile.write("<td> KEY</td>\n") 722 tablefile.write("<td> DEFAULT</td>\n") 723 tablefile.write("<td> EXTRA</td>\n") 724 tablefile.write("</tr>\n") 725 for coldesc in tabdesc: 726 tablefile.write("<tr>\n") 727 field=coldesc.get('Field','') 728 tablefile.write("<td>" +str(field)+"</td>\n") 729 type=coldesc.get('Type','') 730 tablefile.write("<td>"+str(type)+"</td>\n") 731 null=coldesc.get('Null','') 732 tablefile.write("<td>"+str(null)+"</td>\n") 733 key=coldesc.get('Key','') 734 tablefile.write("<td>"+str(key)+"</td>\n") 735 default=coldesc.get('Default','') 736 tablefile.write("<td>"+str(default)+"</td>\n") 737 extra=coldesc.get('Extra','') 738 tablefile.write("<td>"+str(extra)+"</td>\n") 739 tablefile.write("</tr>\n") 740 tablefile.write("</table>\n") 741 tablefile.write("</div>\n") 742 tablefile.write("<div id=\"footnote\"></div>\n") 743 tablefile.write("</div>\n") 744 tablefile.write("</body>\n") 745 tablefile.write("</html>\n") 746 tablefile.close()
747 748 ############## MAIN ############################################################# 749 ############ Example of usage ################################################## 750 if __name__=='__main__': 751 pass 752 # A=MoSTBioDatScheme(user='',passwd='',path='/tmp/Log', 753 # filename='dbScheme',db='ligand', 754 # scheme2file=True,log=True) 755 # b=A.geTableDesc(tablename='ChemComp',schemepath='/tmp/SchemeDB',schemefilename='dbscheme') 756 # print b 757 # c=A.geTablesDesc(schemepath='/tmp/SchemeDB',schemefilename='dbscheme') 758 # print c 759 # showdict(dictfullfilename='/tmp/SchemeDB/dbscheme',item='ChemComp') 760 761 # B=createHTML(dictfullfilename='/tmp/SchemeDB/dbscheme',path='/tmp/SchemeDB') 762 # A.closeDB() 763