summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/referrer-policy/generic/tools/clean.py
blob: 715e1d6ae4b53461a99b3789a5200e4cb6456f4c (plain)
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
#!/usr/bin/env python

import os, json
from common_paths import *
import spec_validator

def rmtree(top):
    top = os.path.abspath(top)
    assert top != os.path.expanduser("~")
    assert len(top) > len(os.path.expanduser("~"))
    assert "web-platform-tests" in top
    assert "referrer-policy" in top

    for root, dirs, files in os.walk(top, topdown=False):
        for name in files:
            os.remove(os.path.join(root, name))
        for name in dirs:
            os.rmdir(os.path.join(root, name))

    os.rmdir(top)

def main():
    spec_json = load_spec_json();
    spec_validator.assert_valid_spec_json(spec_json)

    for spec in spec_json['specification']:
        generated_dir = os.path.join(spec_directory, spec["name"])
        if (os.path.isdir(generated_dir)):
            rmtree(generated_dir)

    if (os.path.isfile(generated_spec_json_filename)):
        os.remove(generated_spec_json_filename)

if __name__ == '__main__':
    main()