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

6.3. Web paths

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:

To assist us in keeping these relationships straight, here is a small helper class.

webstats.py
# - - - - -   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:

webstats.py
        .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.

webstats.py
# - - -   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.

webstats.py
# - - -   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:

webstats.py
NMT_WEB_PATH  =  WebPath ( "http://www.nmt.edu/",
                           "/u/www/docs/" )

The starting point for all official TCC pages:

webstats.py
TCC_WEB_PATH  =  NMT_WEB_PATH.relative ( "tcc/" )

All the files generated by this application are in or under this directory:

webstats.py
OUT_WEB_PATH  =  TCC_WEB_PATH.relative ( "webstats/" )

The subdirectories containing the report pages for personal and official users, respectively:

webstats.py
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:

webstats.py
HTML_EXT  =  ".html"

The generated index page:

webstats.py
INDEX_WEB_PATH  =  OUT_WEB_PATH.relative ( "index" + HTML_EXT )

The hit parade page:

webstats.py
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:

webstats.py
LETTER_PREFIX  =  "pers-"

Pathname of the institute homepage relative to the server:

webstats.py
INSTITUTE_HOMEPAGE  =  '/'