# - - - m a i n def main(): '''Main program. [ (the Postgresql server is available) and (PASS_FILE names a readable file containing the database password for the CBC database) and (NATIONS_FILE names a readable, valid data file for the nations table) and (REGIONS_FILE names a readable, valid data file for the regions table whose nation codes are all defined in NATIONS_FILE) -> that database := that database with the nations table and regions table dropped and recreated with data from NATIONS_FILE and REGIONS_FILE, respectively ] '''
The main program starts by connecting to the database. The password is stored in a file readable only by the author, so that it does not appear here.
#-- 1 -- # [ (the Postgresql server is available) and # (PASS_FILE names a readable file containing the database # password for the CBC database) -> # db := a pycbc.py.CBCData instance connected # to that database ] t0 = Timer('Connecting') passFile = file ( PASS_FILE ) password = passFile.readline().strip() passFile.close() db = pycbc.CBCData(password) print t0
Next we drop all the tables and recreate them according to the schema.
#-- 2 -- # [ db := db with all tables dropped ] t1 = Timer('Dropping and recreating tables') db.meta.drop_all(checkfirst=True) #-- 3 -- # [ db := db with all tables created according to db.meta ] db.meta.create_all() print t1
#-- 4 -- # [ db := db with the nations table populated from the # file named by NATIONS_FILE ] t2 = Timer('Loading static tables') loadNations ( db ) #-- 5 -- # [ db := db with the regions table populated from the file # named by REGIONS_FILE ] loadRegions ( db ) #-- 6 -- # [ db := db with the physios table populated from the file # named by PHYSIOS_FILE ] loadPhysios ( db) print t2
To check that the database was properly loaded,
Section 7.9, “
check()” prints a
report showing all the nations and regions.
#-- 7 -- # [ sys.stdout +:= report showing nation and region # tables from db ] check ( db )