head	1.1;
access;
symbols;
locks; strict;
comment	@# @;


1.1
date	2006.12.18.15.54.02;	author kusung25;	state Exp;
branches;
next	;


desc
@@


1.1
log
@*** empty log message ***
@
text
@#!/usr/bin/env python
###########################################################################
#                                                                         #
# C O P Y R I G H T   N O T I C E                                         #
#  Copyright (c) 2002 by:                                                 #
#    * California Institute of Technology                                 #
#                                                                         #
#    All Rights Reserved.                                                 #
#                                                                         #
# Permission is hereby granted, free of charge, to any person             #
# obtaining a copy of this software and associated documentation files    #
# (the "Software"), to deal in the Software without restriction,          #
# including without limitation the rights to use, copy, modify, merge,    #
# publish, distribute, sublicense, and/or sell copies of the Software,    #
# and to permit persons to whom the Software is furnished to do so,       #
# subject to the following conditions:                                    #
#                                                                         #
# The above copyright notice and this permission notice shall be          #
# included in all copies or substantial portions of the Software.         #
#                                                                         #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,         #
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF      #
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND                   #
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS     #
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN      #
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN       #
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE        #
# SOFTWARE.                                                               #
###########################################################################
#
#       Authors: Brandon King
# Last Modified: $Date: 2003/02/19 01:36:04 $
#
rev = "$Revision: 1.5 $"
rev = rev.replace('$Revision: ', '')
rev = rev.replace(' $', '')

VERSION = 'v0.%s' % (rev)

try:
  from Tkinter import *
except:
  pass
import pymerase

PymVERSION = pymerase.VERSION

import sys
import os
import pickle
import types
import getopt

#####################
# Comand Line

def parseCommandLine():
  """
  Processes Command Line Arguments

  return (source, inputModule, destination, outputModule)
  """
  try:
    opts, args = getopt.getopt(sys.argv[1:], "s:i:d:o:htgv",
                               ["source=",
                                "inputModule=",
                                "destination=",
                                "outputModule=",
                                "help",
                                "translators",
                                "version",
                                "gui"])
  except getopt.GetoptError:
    print "-------------------------------"
    print "- Invalid Command Line Option -"
    print "-------------------------------"
    printUseage()
    sys.exit(2)
    
  if len(sys.argv) <= 1:
    printUseage()
    sys.exit(2)

  for arg, val in opts:
    if arg in ('-h', '--help'):
      printUseage()
      sys.exit()

    if arg in ('-v', '--version'):
      print "Pymerase %s" % (PymVERSION)
      print "Pymerase Command Line %s" % (VERSION)
      sys.exit()

    if arg in ('-g', '--gui'):
      loadGUI()
      sys.exit()

    if arg in ('-t', '--translators'):
      printTranslators()
      sys.exit()

    if arg in ('-s', '--source'):
      if len(val) > 0:
        source = val
      else:
        source = None
    
    if arg in ('-i', '--inputModule'):
      if len(val) > 0:
        inputModule = val
      else:
        inpurModule = None
        
    if arg in ('-d', '--destination'):
      if len(val) > 0:
        destination = val
      else:
        destination = None
        
    if arg in ('-o', '--outputModule'):
      if len(val) > 0:
        outputModule = val
      else:
        outputModule = None

  print ""
  
  try:
    print "source:       %s" % (source)
  except UnboundLocalError:
    source = None

  try:
    print "inputModule:  %s" % (inputModule)
  except UnboundLocalError:
    inputModule = None

  try:
    print "destination:  %s" % (destination)
  except UnboundLocalError:
    destination = None

  try:
    print "outputModule: %s" % (outputModule)
  except UnboundLocalError:
    outputModule = None
    
  print ""

  
  msg = ""
  if source is None:
    msg += "Error: No source provided"
    msg += os.linesep
  if inputModule is None:
    msg += "Error: No inputModule provided"
    msg += os.linesep
  if destination is None:
    msg += "Error: No destination provided"
    msg += os.linesep
  if outputModule is None:
    msg += "Error: No outputModule provided"
    msg += os.linesep
  if msg != "":
    msg += "Suggestion: see \'pymerase --help\'"
    msg += os.linesep
    print msg
    sys.exit(2)

  return (source, inputModule, destination, outputModule)

def printTranslators():
  text = """
Pymerase Translators:

  INPUT:
%s

  OUTPUT:
%s
  """ % (pymerase.getInputTranslatorVerbose(),
         pymerase.getOutputTranslatorVerbose())

  print text


def printUseage():
  useage = """
  Welcome to Pymerase %s!
  
  Useage:
    pymerase -s [source] -i [inputModule]
      -d [destination] -o [outputModule]
  
    pymerase --source=[source] --inputModule=[inputModule]
      --destination=[destination] --outputModule=[outputModule]

  Options:
    -s, --source=[foo]         Location of input file or directory
    -i, --inputModule=[foo]    Name of PyMerase input translation module
    -d, --destination=[foo]    Location of output file or directory
    -o, --outputModule=[foo]   Name of PyMerase output module

    -g, --gui                  GUI Interface to Pymerase

    -t, --translators          Displays more info about translators
    -v, --version              Displays version numbers
    -h, --help                 Displays this help page

  Input Translators Available:
%s

  Output Translators Available:
%s
  """ % (pymerase.VERSION,
         pymerase.getInputTranslatorString(),
         pymerase.getOutputTranslatorString())
  
  print useage

def loadGUI():
  import pymerasegui
  root = Tk()
  root.title('Pymerase GUI %s' % pymerasegui.VERSION)
  pymApp = pymerasegui.tkPymerase(root)
  root.mainloop()

if __name__ == '__main__':  
  source, inputModule, destination, outputModule = \
          parseCommandLine()
  parser = pymerase.run(source, inputModule, destination, outputModule)
@
