comparison scripts/docs-headings.py @ 7499:a188803df37e

scripts: docs-headings: improve performance by grouping 'hg diff' invocations With SSD, this change reduces the execution time of this script from 8 to 0.5 seconds
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Sun, 30 Dec 2018 11:45:28 +0100
parents 665dfa112f2c
children 0a277465fddf
comparison
equal deleted inserted replaced
7498:e7d6373631c4 7499:a188803df37e
28 # match on a header line underlined with one of the valid characters 28 # match on a header line underlined with one of the valid characters
29 headermatch = re.compile(r'''\n*(.+)\n([][!"#$%&'()*+,./:;<=>?@\\^_`{|}~-])\2{2,}\n+''', flags=re.MULTILINE) 29 headermatch = re.compile(r'''\n*(.+)\n([][!"#$%&'()*+,./:;<=>?@\\^_`{|}~-])\2{2,}\n+''', flags=re.MULTILINE)
30 30
31 31
32 def main(): 32 def main():
33 for fn in subprocess.check_output(['hg', 'loc', 'set:**.rst+kallithea/i18n/how_to']).splitlines(): 33 filenames = subprocess.check_output(['hg', 'loc', 'set:**.rst+kallithea/i18n/how_to']).splitlines()
34 print 'processing %s:' % fn 34 for fn in filenames:
35 print 'processing %s' % fn
35 s = open(fn).read() 36 s = open(fn).read()
36 37
37 # find levels and their styles 38 # find levels and their styles
38 lastpos = 0 39 lastpos = 0
39 styles = [] 40 styles = []
70 # fix trailing space and spacing before link sections 71 # fix trailing space and spacing before link sections
71 s = s.strip() + '\n' 72 s = s.strip() + '\n'
72 s = re.sub(r'''\n+((?:\.\. _[^\n]*\n)+)$''', r'\n\n\n\1', s) 73 s = re.sub(r'''\n+((?:\.\. _[^\n]*\n)+)$''', r'\n\n\n\1', s)
73 74
74 open(fn, 'w').write(s) 75 open(fn, 'w').write(s)
75 print subprocess.check_output(['hg', 'diff', fn]) 76
76 print 77 print subprocess.check_output(['hg', 'diff'] + filenames)
77 78
78 if __name__ == '__main__': 79 if __name__ == '__main__':
79 main() 80 main()