-
Notifications
You must be signed in to change notification settings - Fork 4
/
document-files-in-README
executable file
·54 lines (47 loc) · 1.3 KB
/
document-files-in-README
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
#!/usr/bin/env python3
import sys
import os
import glob
DOC_FILE = 'README.md'
IGNORE_FILE = '.gitignore'
RCS_DIR = '.git'
def documented_files():
def f():
for i in open(DOC_FILE):
if not i.startswith('* '):
continue
t = i.split()[1]
# expand 'disk-{scan,deactivate}'
(s, e) = (t.find('{'), t.find('}'))
if s == -1 or e == -1:
yield t
continue
for j in t[s+1:e].split(','):
yield t[:s] + j + t[e+1:]
return set(f())
def files_in_dir():
s = set(os.listdir('.'))
s.remove(DOC_FILE)
s.remove(IGNORE_FILE)
s.remove(RCS_DIR)
for i in open(IGNORE_FILE):
pattern = i[:-1] # strip '\n'
try:
s -= set(glob.glob(pattern))
if pattern.startswith('*.'):
# '*.swp' -> '.*.swp'
s -= set(glob.glob('.' + pattern))
except KeyError:
pass
return s
def main(args):
d = documented_files()
f = files_in_dir()
added_files = sorted(list(f- d))
removed_files = sorted(list(d -f))
for i in added_files:
sys.stdout.write('A %s\n' % (i,))
for i in removed_files:
sys.stdout.write('R %s\n' % (i,))
if __name__ == '__main__':
main(sys.argv[1:])