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

8. main(): The main program

Here is an intended function for the entire script. Not mentioned here is a blanket precondition that the LDAP server is available; if it isn't, nothing else is likely to be working.

homelist2
# - - -   m a i n

def main():
    '''Build a KWIC index to all TCC personal homepages.

      [ if (command line arguments are valid) and
        (directory specified on command line is writeable) ->
          directory specified on command line  :=  index.html
              top-level page and index_X.html subpages for
              every letter X of the alphabet
        else ->
          sys.stderr  +:=  error message(s) ]
    '''

See Section 9, “checkArguments(): Digest the command line arguments”.

homelist2
    #-- 1 --
    # [ if command line arguments are valid ->
    #     dirPath  :=  absolute pathname to directory specified on
    #                  command line
    #   else ->
    #     sys.stderr  +:=  error message(s)
    #     stop execution ]
    dirPath = checkArguments()

The work progresses in two main phases: accumulating the information for each user into a KwicIndex instance, and building the index pages.

homelist2
    #-- 2 --
    # [ kwicIndex  :=  a kwic.KwicIndex instance indexing the names of
    #       users in LDAP_SERVER who have a readable WEB_DIR
    #       subdirectory, with the user data for each user
    #       represented as a WebUser instance ]
    kwicIndex = buildKwic()

See Section 16, “buildAllPages(): Build the output pages”.

homelist2
    #-- 3 --
    # [ if directory (dirPath) is writeable ->
    #     directory (dirPath)  :=  (file INDEX_NAME containing links
    #         to letter pages) + (one page for each letter (X), named
    #         LETTER_PAGE_NAME+(X)+HTML_SUFFIX, displaying the
    #         entries in kwicIndex that start with (X)
    #   else ->
    #     sys.stderr  +:=  error message(s) ]
    buildAllPages(dirPath, kwicIndex)