Personal tools
You are here: Home How To Python CLI Program Skeleton
Document Actions

CLI Program Skeleton

by James Stroud last modified 2007-09-28 04:42
#! /usr/bin/env python


import sys
from optparse import OptionParser
from textwrap import dedent


__version__ = '0.1'

def header(width=70):
  hline = "=" * width
  print hline
  print (" make-surveys v.%s " % __version__).center(width)
  print hline

def doopts():
  usage = 'usage: make-survey [-i inputsdir] texfile'
  parser = OptionParser(usage)
  parser.add_option("-i", "--inputs", dest="inputs",
           default='Inputs',
           help="directory where inputs are",
           metavar="INPUTS")
  return parser

def usage(parser, msg=None, width=70):
  err = ' ERROR '.center(width, '#')
  errbar = '#' * width
  hline = '=' * width
  if msg is not None:
     print '\n'.join(('', err, msg, errbar, ''))
  print hline
  print
  print parser.format_help()
  sys.exit(0)

def main():
  header()
  parser = doopts()
  (options, args) = parser.parse_args()

  try:
    texfile = args[0]
  except IndexError:
    usage(parser, 'No texfile specified.')

  '\newcommnand{\version}{version-0%s}'


if __name__ == "__main__":
  main()


« January 2009 »
Su Mo Tu We Th Fr Sa
123
45678910
11121314151617
18192021222324
25262728293031
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: