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

8. buildPages(): Build all Web pages

This is the top-level function for building all the output Web pages.

hwscan3.py
# - - -   b u i l d P a g e s

def buildPages ( reportInfo, clientSet ):
    '''Build all output Web pages

      [ (reportInfo is a ReportInfo instance) and
        (clientSet is a ClientSet instance) ->
          start page  :=  (table of servers from clientSet) +
              (list of open lab rooms from reportInfo with links to
              open lab room pages from clientSet) +
              (table of classrooms from reportInfo with links to
              classroom room pages from clientSet)
          room pages for all open labs and classrooms  := 
              tables of clients in each room from clientSet ]
    '''

Page generation interacts with the existing PyStyler web:

Generation of the body content of the start page follows the outline described in Section 3.1, “XHTML for the start page”.

hwscan3.py
    #-- 1 --
    # [ div  :=  a new et.Element of type 'div' ]
    div  =  et.Element ( 'div' )

For the generation of the server table, see Section 9, “buildServerTable(): Build the table of servers”.

hwscan3.py
    #-- 2 --
    # [ div  +:=  a table showing servers named in reportInfo,
    #             with configuration data from clientSet ]
    buildServerTable ( div, reportInfo, clientSet )

For the generation of the open labs list, see Section 12, “buildOpenLabsList(): Bullet list of open labs”.

hwscan3.py
    #-- 3 --
    # [ div  +:=  bullet list of open labs named in reportInfo,
    #             with configuration data from clientSet, as
    #             links to room pages for those labs
    #   room pages for open labs  +:=  tables of clients in
    #                                    those labs ]
    buildOpenLabsList ( div, reportInfo, clientSet )

For the generation of the classroom table, see Section 21, “buildClassroomTable(): Build the table of classrooms”.

hwscan3.py
    #-- 4 --
    # [ div  +:=  table of classrooms named in reportInfo, with
    #             configuration data from clientSet, as links
    #             to room pages for those rooms
    #   room pages for classrooms  +:=  tables of clients in
    #                                     those rooms ]
    buildClassroomTable ( div, reportInfo, clientSet )

Finally, write the resulting XHTML to the start page. We must also give it world execute permission so that the server-side include will work; this change was made necessary in January 2009 when the infohost server was upgraded.

hwscan3.py
    #-- 5 --
    # [ start file  :=  div, serialized as XHTML ]
    try:
        startFile  =  open ( START_PATH, 'w' )
    except IOError, detail:
        print >>sys.stderr, ( "*** Can't open the start page file, "
            "'%s': %s" % (START_PATH, detail) )
        raise SystemExit
    print >>startFile, et.tostring ( div, pretty_print=True )
    startFile.close()
    os.chmod ( START_PATH,
        stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
        stat.S_IRGRP | stat.S_IXGRP |
        stat.S_IROTH | stat.S_IXOTH )