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

3.7.  hasHomepage(): Test for the presence of a homepage

This function takes an account name and checks to see if the user has a top-level directory of the correct name (see Section 3.3.5, “WEB_DIR) that is world-readable and world-executable. (A former version of this program looked for a variety of homepage names, but the current Apache configuration will show a listing of the directory if there are no files whose names are considered homepages, so there is no point in looking at the contents of the directory.)

homelist.py
# - - -   h a s H o m e p a g e   - - -

def hasHomepage ( uid ):
    """Does this user have an HTML directory?

      [ uid is a string ->
          if uid is the account name of a user who has a
          homepage directory ->
            return 1
          else ->
            return 0 ]
    """

For a user account N, their home directory is at path “/u/N”, and their HTML directory must be a first-level directory whose name is given by Section 3.3.5, “WEB_DIR.

homelist.py
    #-- 1 --
    # [ webPath  :=  absolute path to the HTML directory for user
    #                uid ]
    webPath  =  "/u/%s/%s/" % (uid, WEB_DIR)

    #-- 2 --
    # [ if webPath names an existing path ->
    #     mode  :=  permissions word (mode bits) for webPath
    #   else -> return 0 ]
    try:
        statusTuple  =  os.stat ( webPath )
        mode  =  statusTuple [ stat.ST_MODE ]
    except OSError:
        return 0

    #-- 3 --
    # [ if mode has world read and world execute bits both set ->
    #     return 1
    #   else ->
    #     return 0 ]
    return bool ( (mode & stat.S_IROTH) and
                  (mode & stat.S_IXOTH) )