3
"""Generate an "INDEX" file based on the content of "meta" files
4
in all sub-directories. The index summarizes what tags are relevant
5
to which projects, to help people find relevant projects.
10
from pprint import pprint
17
for root, dirs, files in os.walk('.'):
18
#print 'Scanning "%s"...' % (root)
19
# ignore hidden dirs like '.bzr' and '.git'
25
#print 'Removing %s' % (d)
29
path = os.path.join(root, 'meta')
30
descriptions.append(parse(path, results))
32
# Warn if there's no meta in a leaf dir
34
print 'No "meta" file in %s' % (root)
37
'This file lists the tags used by projects in this repository, and a list',
38
'of projects associated with each tag. The purpose is to help people find',
39
'projects relevant to their needs, such as hardware or desired features.',
41
'Do not edit this file. Edit the "meta" files in sub-directories instead,',
42
'and run generate-index.py to rebuild this file.',
44
lines.extend(summarize(results, descriptions))
47
#print '\n'.join(lines)
48
fp = open(outfile, 'w')
49
fp.write('\n'.join(lines))
51
print 'Wrote %i lines to %s' % (len(lines), outfile)
53
def parse(path, results):
54
#print 'Parsing "%s"...' % (path)
55
msg = email.message_from_file(open(path))
59
path = os.path.dirname(path)
60
if path.startswith('./'):
63
for k,v in msg.items():
64
if k.strip() in ('', 'Description', ):
67
for v2 in v.split(', '):
68
if v2.strip() in ('', ):
71
if key not in results:
73
results[key].append(path)
75
return (path, description)
77
def summarize(results, descriptions):
80
# Show a one-liner for each project.
82
lines.append('Summary of each project')
85
for path, desc in descriptions:
86
desc = desc.split('\n')[0]
88
lines.append(' %s:' % (path,))
89
lines.append(' ' + desc)
92
# Show the tags for each project, sorted by tag
94
# TODO: move 'extras' section to bottom
100
lines.append('%s' % (lk))
103
lines.append(' %s:' % (rk))
104
for v in results[(lk,rk)]:
105
lines.append(' %s' % (v))
109
if __name__ == "__main__":