~widelands-dev/widelands-website/trunk

438.1.1 by GunChleoc
Added script to run pyformat over the code base.
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
438.1.6 by franku
run the script
5
"""This script runs pyformat over the code base."""
438.1.1 by GunChleoc
Added script to run pyformat over the code base.
6
7
import argparse
8
import os
9
import re
10
import sys
11
from subprocess import call
12
438.1.6 by franku
run the script
13
438.1.1 by GunChleoc
Added script to run pyformat over the code base.
14
def parse_args():
15
    p = argparse.ArgumentParser(
16
        description='Run pyformat over the code base.'
17
        ' Recurses over all relevant files.')
18
    return p.parse_args()
19
20
21
def find_files(startpath, extensions):
22
    for (dirpath, _, filenames) in os.walk(startpath):
23
        for filename in filenames:
24
            if os.path.splitext(filename)[-1].lower() in extensions:
25
                yield os.path.join(dirpath, filename)
26
27
28
def main():
29
    parse_args()
30
438.1.3 by GunChleoc
Addressed code review.
31
    if not os.path.isdir('pybb') or not os.path.isdir('_ops'):
438.1.1 by GunChleoc
Added script to run pyformat over the code base.
32
        print('CWD is not the root of the repository.')
33
        return 1
34
35
    sys.stdout.write('\nFormatting Python code ')
36
    for filename in find_files('.', ['.py']):
37
        sys.stdout.write('.')
38
        sys.stdout.flush()
39
        call(['pyformat', '-i', filename])
40
    print(' done.')
41
438.1.6 by franku
run the script
42
    print('Formatting finished.')
438.1.1 by GunChleoc
Added script to run pyformat over the code base.
43
    return 0
44
45
if __name__ == '__main__':
46
    sys.exit(main())