-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtlib.py
56 lines (51 loc) · 1.5 KB
/
rtlib.py
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
51
52
53
54
55
56
# -*- coding: utf-8 -*-
import fnmatch,os
from sys import modules
def delete_module(modname, paranoid=None):
try:
thismod = modules[modname]
except KeyError:
raise ValueError(modname)
these_symbols = dir(thismod)
if paranoid:
try:
paranoid[:] # sequence support
except:
raise ValueError('must supply a finite list for paranoid')
else:
these_symbols = paranoid[:]
del modules[modname]
for mod in modules.values():
try:
delattr(mod, modname)
except AttributeError:
pass
if paranoid:
for symbol in these_symbols:
if symbol[:2] == '__': # ignore special symbols
continue
try:
delattr(mod, symbol)
except AttributeError:
pass
def search_files(src,match) :
matches = []
for root, dirnames, filenames in os.walk(src):
for filename in fnmatch.filter(filenames, match):
matches.append(os.path.join(root, filename))
return matches
def reimport(modname) :
delete_module(modname)
import modname
def flatten(x):
result = []
for el in x:
if hasattr(el, "__iter__") and not isinstance(el, basestring):
result.extend(flatten(el))
else:
result.append(el)
return result
def main():
pass
if __name__ == '__main__':
main()