disable.py 1.41 KB
Newer Older
Mitar's avatar
Mitar committed
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
#!/usr/bin/env python3

# A simple script to help disable a failing primitive annotation. It moves a primitive annotation
# to "failed" directory. The script can be called in two ways:
#
#  - with primitive ID as reported by the validation script (e.g., v2018.1.26/d3m.primitives.dsbox.MultiTableFeaturization/0.1.3)
#  - with path to failing primitive annotation file (e.g., ./v2018.1.26/ISI/d3m.primitives.dsbox.RandomProjectionTimeSeriesFeaturization/0.1.3/primitive.json)

import argparse
import glob
import os
import os.path
import shutil

parser = argparse.ArgumentParser(description="Disable primitives by moving them to 'failed' directory.")
parser.add_argument('primitive_names', metavar='primitive', nargs='+', help="primitive name to disable")
arguments = parser.parse_args()

for primitive_name in arguments.primitive_names:
    if os.path.exists(primitive_name):
        path = os.path.join('failed', primitive_name)
        shutil.rmtree(path, ignore_errors=True)
        os.renames(primitive_name, path)
    else:
        interface_version, python_path, version = primitive_name.split('/')

        for globbed_file_path in glob.glob('{interface_version}/*/{python_path}/{version}'.format(interface_version=interface_version, python_path=python_path, version=version)):
            path = os.path.join('failed', globbed_file_path)
            shutil.rmtree(path, ignore_errors=True)
            os.renames(globbed_file_path, path)