-
Notifications
You must be signed in to change notification settings - Fork 1
/
cat.py
27 lines (22 loc) · 778 Bytes
/
cat.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
#!/usr/bin/env python
from __future__ import print_function, unicode_literals
import os
import fnmatch
# noinspection PyShadowingBuiltins
def file(name, indent=0):
ind = ' ' * indent
with open(name, 'rt') as fin:
for ln in fin:
yield '{0}{1}'.format(ind, ln.rstrip('\r\n'))
return
def directory(name, recurse=False, indent=0, file_filter='*', dir_filter='*'):
for root, dirs, files in os.walk(name):
root_base = os.path.basename(root)
if fnmatch.fnmatch(root_base, dir_filter):
for fn in files:
if fnmatch.fnmatch(fn, file_filter):
for ln in file(os.path.join(root, fn), indent=indent):
yield ln
if not recurse:
break
return