| 1 |
#! /usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# @creator (C) 2003 Guido U. Draheim |
| 4 |
# @license http://creativecommons.org/licenses/by-nc-sa/2.0/de/ |
| 5 |
|
| 6 |
from zzipdoc.match import Match |
| 7 |
|
| 8 |
# use as o.optionname to check for commandline options. |
| 9 |
class Options: |
| 10 |
var = {} |
| 11 |
def __getattr__(self, name): |
| 12 |
if not name in self.var: return None |
| 13 |
return self.var[name] |
| 14 |
def __setattr__(self, name, value): |
| 15 |
self.var[name] = value |
| 16 |
def scan(self, optionstring): # option-name or None |
| 17 |
x = Match() |
| 18 |
if optionstring & x(r"^--?(\w+)=(.*)"): |
| 19 |
self.var[x[1]] = x[2] ; return x[1] |
| 20 |
if optionstring & x(r"^--?no-(\w+)$"): |
| 21 |
self.var[x[1]] = "" ; return x[1] |
| 22 |
if optionstring & x(r"^--?(\w+)$"): |
| 23 |
self.var[x[1]] = "*"; return x[1] |
| 24 |
return None |
| 25 |
#end Options |
| 26 |
|
| 27 |
if False: |
| 28 |
o = Options() |
| 29 |
o.help = """ |
| 30 |
scans for options |
| 31 |
""" |