File: expyriment_doc_serach.py

package info (click to toggle)
python-expyriment 0.7.0%2Bgit34-g55a4e7e-3.2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,504 kB
  • ctags: 2,094
  • sloc: python: 12,766; makefile: 150
file content (50 lines) | stat: -rw-r--r-- 1,459 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import expyriment
from pydoc import getdoc
x = None
y = None


def _get_doc_and_function(obj):
    rtn = []
    for var in dir(obj):
        if not var.startswith("_"):
            rtn.append(var)
    return getdoc(obj), rtn

def _read_module(mod, doc_dict):
    doc_dict[mod.__name__], classes = _get_doc_and_function(mod)
    for cl in classes:
        cl = "{0}.{1}".format(mod.__name__, cl)
        exec("x =" + cl)
        doc_dict[cl], functions = _get_doc_and_function(x)
        for fnc in functions:
            fnc = "{0}.{1}".format(cl, fnc)
            exec("y =" + fnc)
            doc_dict[fnc], _tmp = _get_doc_and_function(y)

def search_doc(search_str, doc_dict):

    for k in doc_dict.keys():
        if k.lower().find(search_str.lower()) > 0 or\
            doc_dict[k].lower().find(search_str.lower()) > 0:
            print "\n-------------------------------------------------------------------------------"
            print "[ {0} ]\n".format(k)
            #print "-------------------------------------------------------------------------------"
            print "{0}".format(doc_dict[k])



doc_dict = {}
_read_module(expyriment.io, doc_dict)
_read_module(expyriment.stimuli, doc_dict)
_read_module(expyriment.design, doc_dict)
_read_module(expyriment.misc, doc_dict)

while True:
    search = raw_input("New search (q=quit): ")
    if search == "q":
        break
    else:
        search_doc(search, doc_dict)
        print "\n"