forked from ffnord/mesh-announce
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
28 lines (22 loc) · 841 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
27
import os
def _file_name_filter(fname):
return not (fname.startswith('__') or fname.startswith('.'))
def source_dirs(dir):
dirs = next(os.walk(dir))[1]
return filter(_file_name_filter, dirs)
def modules(dir):
return [os.path.splitext(f)[0] for f in next(os.walk(dir))[2]
if f.endswith('.py') and _file_name_filter(f)]
def find_modules(base, *path):
path_files = []
dir_abs = base
dir_abs = os.path.join(base, *path)
dirs = source_dirs(dir_abs)
for dir in dirs:
# Ugly hack because python < 3.5 does not support arguments after asterisk expression
path_files += find_modules(base, *(list(path) + [dir]))
files = list(modules(dir_abs))
if len(files) > 0:
lpath = list(map(os.path.basename, path))
path_files.append((lpath, files))
return path_files