Next / Previous / Contents / Shipman's homepage

87.2. spec2004: Main

The main program uses the previous defined SpeciesSearcher object to do almost everything. The only differences among these three scripts is the name of the authority file.

spec2004
# - - -   m a i n   - - -

def main():
    '''spec2004 main program
    '''
    #-- 1 --
    # [ if sys.argv contains exactly one argument ->
    #     target  :=  that argument
    #   else ->
    #     sys.stderr  +:=  error message(s)
    #     stop execution ]
    argList = sys.argv[1:]
    if  len(argList) != 1:
        print >>sys.stderr, ("*** Takes one argument, the code "
            "or regular expression to be searched for.")
        sys.exit(1)
    else:
        target = argList[0]

    #-- 2 --
    # [ if the Maps2004SpeciesSet authority file is readable and
    #   valid ->
    #     speciesSet  :=  a new Maps2004SpeciesSet object
    #                     representing that file
    #   else ->
    #     sys.stderr  +:=  error message(s)
    #     stop execution ]
    try:
        speciesSet = Maps2004SpeciesSet()
    except IOError, detail:
        print >>sys.stderr,("*** Can't read the species authority "
            "file: %s" % detail)
        sys.exit(1)

    #-- 3 --
    # [ searcher  :=  a new SpeciesSearcher object that searches
    #       speciesSet for target ]
    searcher = SpeciesSearcher(speciesSet, target)

    #-- 4 --
    # [ sys.stdout  +:=  output of searcher ]
    searcher.run()