[Bio] / BioSimScratch / InitializeDb.py Repository:
ViewVC logotype

View of /BioSimScratch/InitializeDb.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Mon Jul 12 20:39:11 2004 UTC (15 years, 5 months ago) by efrank
Branch: MAIN
sets fid info and top catalog node name in database

#########################################################################
#
# Puts foundryId and name of top node into the database.  This should
# only be done once and should be done immediately after loading the
# schema
#
#########################################################################

import sys
from FaST.DbManager import DbManager

#########################################################################

if (__name__ == "__main__" ):
    connectStr = raw_input( "Give connect string: " )
    dbType     = raw_input( "Give database type ('oracle' or 'postgres' ): " )
    name       = raw_input( "Give unique name for database (name others will see): ")

    ##
    # Get a connection and cursor
    ##
    
    try:
        mgr = DbManager.getTxMgr( connectStr, dbType )
        c   = mgr.getCursor()
    except:
        print "Could not connect to database or get cursor", connectStr
        sys.exit()

    ##
    # Establish the foundryId for the database via the KahDatabaseInfo
    # table
    ##

    try:
        q = "SELECT * from KahDatabaseInfo"
        c.execute( q )
        row = c.fetchone()
    except:
        print "Could not test status of KahDatabaseInfo table"
        mgr.rollback()
        mgr.close()
        sys.exit()


    if (not None == row ):
        print "Database already has KahdatabaseInfo initialized to ", row
        q = "UPDATE KahDatabaseInfo SET foundryType='%s', " \
            " foundryURL='%s'" % ( "KahDb", name)
    else:
        q = "INSERT into KahDatabaseInfo VALUES ( '%s', '%s' )" % ( "KahDb", name)

    try:
        print q
        c.execute( q )
    except:
        print "Could not insert info into KahDatabaseInfo"
        mgr.rollback()
        mgr.close()
        sys.exit()


    ##
    # Initialize the top catalogEntry node.
    ##

        
    try:
        q = "SELECT * from KahCatDirEntry where CatDirEntId=0"
        c.execute( q )
        row = c.fetchone()
    except:
        print "Could not test status of KahCatDirEntry table."
        sys.exit()

    if (not None == row ):
        print "Database already has top catalog entry initialized to ", row[0]
        q = "UPDATE KahCatDirEntry SET CatName='%s', FullPathName='/%s' "\
            " WHERE CatDirEntId=0" % (name, name)
    else:
        q = "INSERT INTO KahCatDirEntry values ('%s', 0, 0, 0, '%s')" % (name, name)

    try:
        print q
        c.execute( q )
    except:
        print "Could not create top catalogEntry node"
        sys.exit()


    mgr.commit()
    mgr.close()
    print "Done."
    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3