# - - - - - m a i n
def main():
'''Main program: Copy MySQL CBC database to Postgresql.
[ (MY_PASS and PS_PASS name files containing passwords) and
(MySQL and Postgresql CBC databases are available) and
(all Postgresql tables except regions and nations are
empty) ->
Postgresql CBC database := MySQL CBC database ]
'''
For the function that reads passwords from a file, see Section 9.3, “transloader: readPassword()”.
#-- 1 --
# [ myPassword := first line of file MY_PASS, stripped
# psPassword := first line of file PS_PASS, stripped ]
tTotal = Timer("Entire database loaded")
t0 = Timer("Connect to mysql")
myPassword = readPassword(MY_PASS)
psPassword = readPassword(PS_PASS)
#-- 2 --
# [ my := a mycbc.MyCBC instance representing the MySQL
# CBC database with password (myPassword)
# db := a pycbc.CBCData instance representing the
# Postgresql CBC database with password (psPassword) ]
my = mycbc.MyCBC(myPassword)
print t0
t1 = Timer("Connect to postgresql")
db = pycbc.CBCData(psPassword)
print t1
The main copying and reformatting logic is in Section 9.4, “transloader: dbCopy()”.
#-- 3 --
# [ db := db with all data added from my ]
dbCopy(my, db)
print tTotal