forked from darrengarvey/procfs-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
26 lines (21 loc) · 779 Bytes
/
util.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
import logging
import re
logging.basicConfig(format='%(asctime)-15s %(levelname)s %(filename)s:%(lineno)d %(message)s')
LOGGER = logging.getLogger('stats-snapshot')
def find_all_subclasses(classType):
subclasses = dict()
stack = [classType]
while stack:
parent = stack.pop()
for child in parent.__subclasses__():
name = child.__name__
if not subclasses.has_key(name):
subclasses[name] = child
stack.append(child)
return subclasses
first_cap_re = re.compile('(.)([A-Z][a-z]+)')
all_cap_re = re.compile('([a-z0-9])([A-Z])')
def camel_case_to_underscore(name):
s1 = first_cap_re.sub(r'\1_\2', name)
s2 = all_cap_re.sub(r'\1_\2', s1).lower()
return re.sub(r'(_)\1+', r'\1', s2)