def inner_wrapper(*args, **kwargs): try: return func(*args, **kwargs), True except Exception as e: log.error("[Collection API Exception]%s: %s" % (str(func), str(e))) return e, False
def exist_check(param, _list): if param in _list: return True else: my_log.error("[EXIST_CHECK] Param(%s) is not in (%s)" % (param, _list)) return False
def number_check(num): if str(num).isdigit(): return True else: my_log.error("[NUMBER_CHECK] Number(%s) is not a numbers." % num) return False
def modify_file(file_name_list, input_content=""): if not isinstance(file_name_list, list): log.error("[modify_file] file is not a list.") for file_name in file_name_list: if not os.path.isfile(file_name): log.error("[modify_file] file(%s) is not exist." % file_name) with open(file_name, "r+") as f: f.seek(0) f.truncate() f.write(input_content) f.close() log.info("[modify_file] File(%s) modification is complete." % file_name_list)
def ip_check(ip): if ip == "localhost": return True if not isinstance(ip, str): my_log.error("[IP_CHECK] IP(%s) is not a string." % ip) return False _list = ip.split('.') if len(_list) != 4: my_log.error("[IP_CHECK] IP(%s) is wrong, please check manually." % ip) return False for i in _list: if not str(i).isdigit(): my_log.error("[IP_CHECK] IP(%s) is wrong, please check manually." % ip) return False return True