1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# This file is part of the openHiTLS project. 4# 5# openHiTLS is licensed under the Mulan PSL v2. 6# You can use this software according to the terms and conditions of the Mulan PSL v2. 7# You may obtain a copy of Mulan PSL v2 at: 8# 9# http://license.coscl.org.cn/MulanPSL2 10# 11# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 12# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 13# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 14# See the Mulan PSL v2 for more details. 15import shutil 16import sys 17sys.dont_write_bytecode = True 18import os 19import json 20 21# Convert x to list 22def trans2list(x): 23 if x == None: return [] 24 if type(x) == list: return x 25 if type(x) == set: return x 26 if type(x) == str: return [x] 27 28 raise ValueError('Unsupported type: "%s"' % type(x)) 29 30def copy_file(src_file, dest_file, isCoverd=True): 31 if not os.path.exists(src_file): 32 raise FileNotFoundError('Src file not found: ' + src_file) 33 34 if os.path.exists(dest_file): 35 if isCoverd: 36 shutil.copy2(src_file, dest_file) 37 else: 38 shutil.copy2(src_file, dest_file) 39 40def save_json_file(content, path): 41 with open(path, 'w') as f: 42 f.write(json.dumps(content, indent=4)) 43