Next / Previous / Contents / Shipman's homepage

6.5. argsCheck(): Process the command line arguments and open the input file. This section title was made artificially ridiculously long in order to demonstrate what happens when long titles wrap around for two or even more lines.

docbook5index
# - - -   a r g s C h e c k

def argsCheck():
    '''Check sys.argv and open the input.

      [ if the command line names a readable, valid DocBook file ->
          return (that file as an et.ElementTree, the file's modification
          timestamp in ISO-8601 form)
        else ->
          sys.stderr  +:=  error message(s)
          stop execution ]
    '''
    #-- 1
    # [ if sys.argv has length 2 ->
    #     inFileName  :=  sys.argList[1]
    #   else ->
    #     sys.stderr  +:=  error message(s)
    #     stop execution ]
    argList = sys.argv[1:]
    if len(argList) == 1:
        inFileName = argList[0]
    else:
        usage("Incorrect number of arguments.")

See Section 6.8, “getModTime(): Get the file's modification timestamp”.

docbook5index
    #-- 2
    # [ if inFileName names a readable file ->
    #     timestamp  :=  modification time 
    #   else ->
    #     sys.stderr  +:=  error message(s)
    #     stop execution ]
    timestamp = getModTime(inFileName)

    #-- 3
    # [ if inFileName names a readable, valid DocBook file ->
    #     inDoc  :=  that file as an et.ElementTree
    #   else ->
    #     sys.stderr  +:=  error message(s)
    #     stop execution ]
    try:
        inDoc = et.parse(inFileName)
    except IOError, detail:
        fatal("Can't open the input file '%s': %s" %
              (inFileName, detail))
    except et.XMLSyntaxError, detail:
        fatal("Input file '%s' is not well-formed: %s" %
              (inFileName, detail))

    #-- 4
    return (inDoc, timestamp)