45 lines
565 B
Python
45 lines
565 B
Python
#! /usr/bin/python
|
|
|
|
__author__="bjschuma"
|
|
__date__ ="$Mar 13, 2010 4:37:46 PM$"
|
|
|
|
|
|
import sys
|
|
import re
|
|
|
|
# option -> number of times passed
|
|
global opts
|
|
opts = dict()
|
|
|
|
global args
|
|
args = []
|
|
|
|
|
|
def has(opt):
|
|
global opts
|
|
return (opt in opts)
|
|
|
|
|
|
def parseOpt(opt):
|
|
if has(opt) == False:
|
|
opts[opt] = 1
|
|
else:
|
|
opts[opt] += 1
|
|
|
|
|
|
def parseShort(opt):
|
|
for l in opt:
|
|
parseOpt(l)
|
|
|
|
|
|
def parse():
|
|
global args
|
|
for arg in sys.argv[1:]:
|
|
if re.match("-(?!-)(.*?)",arg):
|
|
parseShort(arg[1:])
|
|
elif re.match("--(.*?)",arg):
|
|
parseOpt(arg[2:])
|
|
else:
|
|
args += [arg]
|
|
|