The constants in this section describe the locations of the various files to be generated.
For each generate file, we need to know its address in two different namespaces:
When we generate files, we use their absolute path names, so that the script does not need to be run in any particular place.
Every generated page must display its absolute URL in order to conform to the TCC style guide.
To assist us in keeping these relationships straight, here is a small helper class.
# - - - - - c l a s s W e b P a t h
class WebPath:
'''Represents an absolute path accessible via the Web.
Exports:
WebPath ( url, absPath ):
[ (url is a URL as a string) and
(absPath is the equivalent absolute path as a string) ->
return a new WebPath instance with those values ]
.url: [ as passed to constructor, read-only ]
.absPath: [ as passed to constructor, read-only ]
To generate a new WebPath instance that is a
subdirectory or file under an existing WebPath instance, use this method:
.relative(relPath):
[ relPath is a relative path as a string ->
return a new WebPath instance representing relPath
relative to self ]
'''
The class constructor does nothing but save its arguments.
# - - - W e b P a t h . _ _ i n i t _ _
def __init__ ( self, url, absPath ):
'''Constructor
'''
self.url = url
self.absPath = absPath
Computation of a new path relative to self
uses the standard Python os.path module. The .join() function handles concatenation of two pieces of a file
name.
# - - - W e b P a t h . r e l a t i v e
def relative ( self, relPath ):
'''Return a new WebPath relative to self.
'''
return WebPath ( os.path.join ( self.url, relPath ),
os.path.join ( self.absPath, relPath ) )
Here are the constant paths for this application.
First, the starting point for all files hosted on
the infohost.nmt.edu server:
NMT_WEB_PATH = WebPath ( "http://www.nmt.edu/",
"/u/www/docs/" )
The starting point for all official TCC pages:
TCC_WEB_PATH = NMT_WEB_PATH.relative ( "tcc/" )
All the files generated by this application are in or under this directory:
OUT_WEB_PATH = TCC_WEB_PATH.relative ( "webstats/" )
The subdirectories containing the report pages for personal and official users, respectively:
PERSONAL_WEB_PATH = OUT_WEB_PATH.relative ( "p/" ) OFFICIAL_WEB_PATH = OUT_WEB_PATH.relative ( "o/" )
The suffix to be used on all generated web pages:
HTML_EXT = ".html"
The generated index page:
INDEX_WEB_PATH = OUT_WEB_PATH.relative ( "index" + HTML_EXT )
The hit parade page:
BY_HITS_WEB_PATH = OUT_WEB_PATH.relative ( "byhits" + HTML_EXT )
The prefix for the pages for each unique initial letter of personal account names:
LETTER_PREFIX = "pers-"
Pathname of the institute homepage relative to the server:
INSTITUTE_HOMEPAGE = '/'