Supporters update.
[dcpomatic.git] / hacks / check_cout
1 #!/usr/bin/python
2
3 import os
4 import shutil
5
6 for root, dirs, files in os.walk('.'):
7     for name in files:
8         if name.endswith('.cc'):
9             include = False
10             using = False
11             with open(os.path.join(root, name)) as f:
12                 for l in f.readlines():
13                     l = l.strip()
14                     if l == 'using std::cout;':
15                         using = True
16                     if l == '#include <iostream>':
17                         include = True
18             if (not include) and using:
19                 g = open('tmp', 'w')
20                 with open(os.path.join(root, name)) as f:
21                     last_was_include = False
22                     done = False
23                     for l in f.readlines():
24                         if last_was_include and l == '\n' and not done:
25                             print>>g,'#include <iostream>'
26                             last_was_include = False
27                             done = True
28                         elif l.startswith('#include'):
29                             last_was_include = True
30                         print>>g,l,
31                 g.close()
32                 shutil.move('tmp', os.path.join(root, name))