import shutil
import sys
sys.dont_write_bytecode = True
import os
import json
def trans2list(x):
if x == None: return []
if type(x) == list: return x
if type(x) == set: return x
if type(x) == str: return [x]
raise ValueError('Unsupported type: "%s"' % type(x))
def unique_list(x):
""" Deduplicate the list. """
return list(dict.fromkeys(x))
def copy_file(src_file, dest_file, isCoverd=True):
if not os.path.exists(src_file):
raise FileNotFoundError('Src file not found: ' + src_file)
if os.path.exists(dest_file):
if isCoverd:
shutil.copy2(src_file, dest_file)
else:
shutil.copy2(src_file, dest_file)
def save_json_file(content, path):
with open(path, 'w') as f:
f.write(json.dumps(content, indent=4))