File: prettify_TEST_FILES.py

package info (click to toggle)
cp2k 6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 204,532 kB
  • sloc: fortran: 835,196; f90: 59,605; python: 9,861; sh: 7,882; cpp: 4,868; ansic: 2,807; xml: 2,185; lisp: 733; pascal: 612; perl: 547; makefile: 497; csh: 16
file content (55 lines) | stat: -rwxr-xr-x 1,622 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python
# -*- coding: utf-8 -*-

# author: Ole Schuett

import sys
from os import path

#===============================================================================
def main():
    if(len(sys.argv) != 2):
        print("Usage prettify_TEST_FILES.py <tests-dir>")
        sys.exit(1)

    tests_dir = sys.argv[1]
    assert(tests_dir.endswith("/"))

    lines = open(tests_dir+"TEST_DIRS").readlines()
    test_subdirs = [l.split()[0] for l in lines if l[0]!="#"]
    for d in test_subdirs:
        fn = tests_dir+d+"/TEST_FILES"
        print("Working on: "+fn)
        content = open(fn).read()
        output = ""
        for line in content.strip().split("\n"):
            line = line.strip()
            if(line == "#EOF"):
                continue
            if(line.startswith("#")):
                output += line + "\n"
                continue
            parts = line.split()
            assert(len(parts) < 5)
            assert(len(parts[0]) < 50)
            assert(len(parts[1]) < 5)
            output += "%-50s %5s" %(parts[0], parts[1])
            if(len(parts) > 2):
                assert(len(parts[2]) < 10)
                output += " %10s" %parts[2]
            if(len(parts) > 3):
                assert(len(parts[3]) < 30)
                output += " %30s" %parts[3]
            output += "\n"
        output += "#EOF\n"

        f = open(fn, "w")
        f.write(output)
        f.close()

#===============================================================================
if(len(sys.argv)==2 and sys.argv[-1]=="--selftest"):
    pass #TODO implement selftest
else:
    main()
#EOF