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

9. checkArguments(): Digest the command line arguments

Command line processing is straightforward. There should be exactly one argument, the directory path where the files are to be built.

homelist2
# - - -   c h e c k A r g u m e n t s

def checkArguments():
    '''Check and return the command line argument.

      [ if command line arguments are valid ->
          return the absolute pathname to the directory specified on
          the command line
        else ->
          sys.stderr  +:=  error message(s)
          stop execution ]
    '''
    #-- 1 --
    print "=== %s %s ===" % (PROGRAM_NAME, PROGRAM_VERSION)
    argList = sys.argv[1:]

    #-- 2 --
    if len(argList) != 1:
        fatal("Takes one argument, the path to the output directory.")
    else:
        rawPath = argList[0]

Because the argument is to be interpreted as a path relative to http://www.nmt.edu/, it must not start with a slash, but it must end with one. Consider also the degenerate case where the operator provided "/" as the argument: do not overwrite http://www.nmt.edu/tcc/index.html!

homelist2
    #-- 3 --
    # [ if rawPath starts with '/' ->
    #     return rawPath[1:]
    #   else ->
    #     return rawPath ]
    if rawPath.startswith('/'): relPath = rawPath[1:]
    else:                       relPath = rawPath

    if len(relPath) == 0:
        fatal("Path '%s' is not long enough." % rawPath)
    if not relPath.endswith('/'):
        relPath = relPath + '/'
    return relPath