# - - - - - m a i n
def main():
'''Main program.
[ if (the pycbc database is available) and
(PASS_FILE names a readable file containing the pycbc
database password) ->
sys.stdout +:= a web page that allows the user to select
a region index page out of the set of regions in pycbc
else ->
sys.stdout +:= an error web page ]
'''
The main is broken into three steps: create an empty page;
fill it with content, or an error page if there is any
problem; and write the completed page. See Section 6.5, “buildEmptyPage(): Set up an empty
page”.
#-- 1
# [ sys.stdout +:= CGI header for HTML output
# page := a tp.TCCPage instance ]
print "Content-type: text/html"
print
page = buildEmptyPage()
The page-building step is wrapped in a try-except block so that a ScriptError raised anywhere will exit
immediately to error page generation; see Section 15, “class ScriptError: Our exception”.
#-- 2
# [ if the pycbc database is available ->
# page := page modified to display a form for selecting a
# regional index page for one of the regions from that
# database
# else ->
# page := page modified to display an error page ]
try:
#-- 2.1
# [ if (PASS_FILE names a readable file containing the
# CBC database password) and (the pycbc database is
# available) ->
# db := a pycbc.CBCDatabase instance representing that
# database
# else -> raise ScriptError ]
try:
db = lib.openDatabase()
except IOError, x:
raise lib.ScriptError("Can't access the CBC database: %s" %
str(x))
See Section 6.6, “buildRegionsForm(): Build the table of
region radiobuttons” and Section 17, “buildErrorPage()”.
#-- 2.2
# [ page := page modified to display a form for selecting a
# regional index page for one of the regions from db ]
buildRegionsForm(page, db)
except lib.ScriptError, x:
#-- 2x
# [ page := page modified to show str(x) as an error ]
lib.buildErrorPage(page, x)
#-- 3
# [ sys.stdout +:= page, serialized as XHTML ]
lib.addDocLink(page.content)
page.write(sys.stdout)
See Section 19, “addDocLink(): Add a link to the
documentation”, which adds a pointer
to the documentation.