#!/usr/bin/python
""" Használat:  dirlista.py [-n <namespace>]  <minta>...
        vagy dirlista.py [-h] 
        vagy dirlista.py [--help] 

Kilistázza az adott namespace objektumai közül a mintát tartalmazóakat
ha lehet a leírásukkal együtt. A namespace alapérétke '__builtin__'.
A minta tetszöleges reguláris kifejezés lehet.
"""

import re
import sys
import getopt

opts, args= getopt.getopt(sys.argv[1:], "n:h", ['help'])
print args, opts

help = 0
namespace = None
for opt, value in opts:
    if opt == '-n':
        namespace = value
    elif opt in [ '--help', '-h']:
        help = 1

def list(pattern = '.', namespace = '__builtins__'):
    exec 'lista = dir(%s)' % namespace
    print lista, namespace
    for object in lista:
        if re.search(pattern, object):
            print "*** Név: %s" % object
            try:
                exec 'print %s.%s.__doc__' % (namespace, object)
            except AttributeError:
                pass

if len(sys.argv) == 1 or help:
    print __doc__
else:
    if not args:
        args.append('.')
    for pattern in args:
        print pattern, namespace
        list(pattern, namespace or '__builtins__')
