Next / Previous / Contents / TCC Help System / NM Tech homepage

10.2. addArchImage(): Add all forms for one image

This function examines the catalog information in one ArchImage instance, and for each form name cataloged, adds that ArchImage to the tree rooted in rootTaxon.

catweb
# - - -   a d d A r c h I m a g e

def addArchImage(txny, archImage, rootTaxon):
    '''Catalog all forms in one image.

      [ (txny is a txnyModule.Txny) and
        (archImage is an archindex.ArchImage) and
        (rootTaxon is a TaxonPhotoSet) ->
          rootTaxon  :=  rootTaxon with archImage added under
              each form cataloged in archImage ]
    '''

Inside the archImage instance, the .original attribute is a birdimages.Original catalog object. The Original.ab6 attribute is a space-separated list of “bird ID” strings, generally a six-letter code, but possibly a longer code giving information about hybrids, species pairs, and whether the ID was questionable.

We take this string and break it on spaces, converting each one to a txnyModule.BirdId instance that links that form to a specific taxon. Then, for each form, we use the TaxonPhotoSet.addArchImage() method to catalog that image under that taxon and form name.

catweb
    #-- 1
    # [ birdIdList  :=  list of bird codes from
    #       archImage.original.ab6, split at spaces ]
    birdIdList = archImage.original.ab6.split()

    #-- 2
    # [ rootTaxon  :=  rootTaxon with archImage added under
    #       each form code from birdIdList ]
    for rawBirdId in birdIdList:
        #-- 2 body
        # [ if rawBirdId is defined in txny ->
        #     rootTaxon  :=  rootTaxon with archImage added
        #                    under rawBirdId ]

        #-- 2.1
        # [ if rawBirdId is defined in txny ->
        #     birdId  :=  an abbrModule.BirdId instance representing
        #                 rawBirdId
        #   else -> raise Exception ]
        try:
            birdId = abbrModule.BirdId.parse(txny, rawBirdId)
        except Exception, detail:
            print >>sys.stderr,("*** Invalid bird ID '%s': %s" %
                                  (rawBirdId, detail))
            continue
    
        #-- 2.2
        # [ rootTaxon  :=  rootTaxon with archImage added under birdID ]
        try:
            rootTaxon.addArchImage(birdId, archImage)
        except KeyError, detail:
            print >>sys.stderr, "***", detail