Next / Previous / Contents / NM Tech homepage

7.3. staticloader: loadNations()

This function handles loading of the nations table. It is pretty straightforward: it opens the input file, converts each line of that file into a Nation object, and adds it to the database.

staticloader
# - - -   l o a d N a t i o n s

def loadNations ( db ):
    '''Load the nations table.

      [ (db is a CBCData instance) and
        (NATIONS_FILE names a readable, valid data file for
        the nations table) ->
          db  :=  db with the nations table populated from
                  the file named by NATIONS_FILE ]
    '''
    #-- 1 --
    # [ inFile  :=  a readable file for NATIONS_FILE ]
    inFile = file ( NATIONS_FILE )

    #-- 2 --
    # [ db.s  +:=  new nations rows made from the lines of inFile ]
    for rawLine in inFile:
        #-- 2 body --
        # [ rawLine is a valid nations file line ->
        #       db.s  +:=  a new nations row made from rawLine ]
        addNation ( db, rawLine )

    #-- 3 --
    # [ db  :=  db with the transaction in db.s committed ]
    db.s.commit()