Next / Previous / Contents / NM Tech homepage

7.5. staticloader: loadRegions()

staticloader
# - - -   l o a d R e g i o n s

def loadRegions ( db ):
    '''Load the regions table.

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

Quite similar to Section 7.3, “staticloader: loadNations().

staticloader
    #-- 1 --
    # [ inFile  :=  a readable file for REGIONS_FILE ]
    inFile = file ( REGIONS_FILE )

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

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