This is the top-level function for building all the output Web pages.
# - - - 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:
The actual start page is under the control of the
PyStyler system at www.nmt.edu/tcc/hw/index.html. Here, we
generate only the content inside the body element. It will be included inside the PyStyler
page using a server-side include.
Eventually, when PyStyler is redesigned so that it uses a separate namespace for PyStyler commands, and it supports dynamic generation of pages using PyStyler templates, this page generation will be reworked to generate the start page directly from the template.
Room pages will use the tccpage2
module so that they look like PyStyler pages.
Generation of the body content of the start
page follows the outline described in Section 3.1, “XHTML for the start page”.
#-- 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”.
#-- 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”.
#-- 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”.
#-- 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.
#-- 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 )