#!/usr/bin/env python3 import glob import os import sys paths = [ 'test/*.cpp', 'src/*.cpp', 'src/kademlia/*.cpp', 'include/libtorrent/*.hpp', 'include/libtorrent/kademlia/*.hpp', 'include/libtorrent/aux_/*.hpp', 'include/libtorrent/extensions/*.hpp'] os.system('(cd .. ; ctags %s 2>/dev/null)' % ' '.join(paths)) files = [] for p in paths: files.extend(glob.glob(os.path.join('..', p))) items = [] # keeps 20 non-comment lines, used to get more context around # todo-items context = [] priority_count = [0, 0, 0, 0, 0] def html_sanitize(s): ret = '' for i in s: if i == '<': ret += '<' elif i == '>': ret += '>' elif i == '&': ret += '&' else: ret += i return ret for f in files: h = open(f) state = '' line_no = 0 context_lines = 0 for orig_line in h: line_no += 1 line = orig_line.strip() if 'TODO:' in line and line.startswith('//'): line = line.split('TODO:')[1].strip() state = 'todo' items.append({}) items[-1]['location'] = '%s:%d' % (f, line_no) items[-1]['priority'] = 0 if line[0] in '0123456789': items[-1]['priority'] = int(line[0]) if int(line[0]) > 5: print('priority too high: ' + line) sys.exit(1) line = line[1:].strip() items[-1]['todo'] = line prio = items[-1]['priority'] if prio >= 0 and prio <= 4: priority_count[prio] += 1 continue if state == '': context.append(html_sanitize(orig_line)) if len(context) > 20: context.pop(0) continue if state == 'todo': if line.strip().startswith('//'): items[-1]['todo'] += '\n' items[-1]['todo'] += line[2:].strip() else: state = 'context' items[-1]['context'] = ''.join(context) + \ '
' + html_sanitize(orig_line) + '
' context_lines = 1 context.append(html_sanitize(orig_line)) if len(context) > 20: context.pop(0) continue if state == 'context': items[-1]['context'] += html_sanitize(orig_line) context_lines += 1 context.append(html_sanitize(orig_line)) if len(context) > 20: context.pop(0) if context_lines > 30: state = '' h.close() items.sort(key=lambda x: x['priority'], reverse=True) # for i in items: # print('\n\n', i['todo'], '\n') # print(i['location'], '\n') # print('prio: ', i['priority'], '\n') # if 'context' in i: # print(i['context'], '\n') out = open('todo.html', 'w+') out.write('''

libtorrent todo-list

%d urgent %d important %d relevant %d feasible %d notes ''' # noqa % (priority_count[4], priority_count[3], priority_count[2], priority_count[1], priority_count[0])) prio_colors = ['#ccc', '#ccf', '#cfc', '#fcc', '#f44'] index = 0 for i in items: if 'context' not in i: i['context'] = '' out.write(('' '') % (prio_colors[i['priority']], i['priority'], index, i['location'], i['todo'].replace('\n', ' '))) out.write( ('') % (index, i['todo'], i['location'], i['context'])) index += 1 out.write('
relevance %d%s%s
') out.close()