def testFantzTaskCases(self): binary_number, decimal_number = file_reader('data/fantz2.in') self.assertEqual(1, fantz_launcher(str(binary_number), int(decimal_number))) binary_number, decimal_number = file_reader('data/fantz3.in') self.assertEqual(3, fantz_launcher(str(binary_number), int(decimal_number))) binary_number, decimal_number = file_reader('data/fantz4.in') self.assertEqual(5, fantz_launcher(str(binary_number), 7))
def __init__(self, file_path): assert Path(file_path).exists(), f'{file_path} does not exits.' self._files = [ line.strip('\n').split(',') for line in file_reader(file_path) ] self._image_paths = [line[0] for line in self._files] self._anno_paths = [line[1:] for line in self._files]
def get_app_list(): results = [] file_name = utils.get_current_folder() + consts.Prefix["app_list_file"] if path.exists(file_name): results = utils.file_reader(file_name) else: raise Exception("app list file doesn't exists!") return results
def get_app_service_detail(svc_id): svc_detail = {} file_name = utils.get_current_folder() + consts.Prefix["app_service_detail_file"] + svc_id if path.exists(file_name): svc_detail = utils.file_reader(file_name) else: raise Exception("app service detail file {} doesn't exists!".format(file_name)) return svc_detail
def create_cm(): current_folder = utils.get_current_folder() print "begin create configMap " for filename in os.listdir(current_folder): if filename.startswith(consts.Prefix["cm_name_prefix"]): cm_file = filename print "find configMap file " + filename if not os.path.exists(current_folder + cm_file): raise "configMap file for {} not exists! please check task of init cm".format( current_folder + cm_file) cm_data = utils.file_reader(current_folder + cm_file) print "config map data for file {},{}".format( filename, json.dumps(cm_data)) is_app = False if filename.startswith(consts.Prefix["cm_name_prefix"] + consts.Prefix["app_cm_flag_file"]): is_app = True filename_pre = consts.Prefix["cm_name_prefix"] + consts.Prefix["app_cm_flag_file"] if is_app\ else consts.Prefix["cm_name_prefix"] service_uuid = filename.replace(filename_pre, "") print "find cm service uuid {}, type is {}".format( service_uuid, "app" if is_app else "service") svc_detail = applications.get_app_service_detail(service_uuid) if is_app \ else services.get_service_detail(service_uuid) data = { "apiVersion": "v1", "kind": "ConfigMap", "metadata": { "annotations": {}, "namespace": applications.get_app_svc_namespace(svc_detail) if is_app else svc_detail["space_name"], "name": filename.replace("_", "-") }, "data": cm_data } print "begin create configMap for {}".format(current_folder + filename) res = utils.send_request("POST", consts.URLS["create_cm"], data) if isinstance(res, list) and len(res) > 0: print "configMap {} create success,list".format( current_folder + filename) elif isinstance( res, dict) and "result" in res and len(res["result"]) > 0: print "create namespace for {} success".format(current_folder + filename) elif isinstance(res, dict) and "errors" in res and \ res["errors"][0]["message"].find("already exists") >= 0: print res["errors"][0]["message"] + ", will be skipped" else: print "configMap {} create ERROR!!!".format(current_folder + filename) exit(1)
def handle_pipeline(): print "\nbegin update pipeline data\n" current_folder = utils.get_current_folder() for filename in os.listdir(current_folder): if filename.startswith(consts.Prefix["pipeline_name_prefix"]): pipeline_file = filename if utils.no_task_record(pipeline_file): print "\nfind pipeline file " + filename if not os.path.exists(current_folder + pipeline_file): raise "pipeline file for {} not exists! please check task of init lb".format( pipeline_file) pipeline_data = utils.file_reader(current_folder + pipeline_file) pipeline_name = pipeline_data["name"] print "\nbegin handle pipeline {} \n".format(pipeline_name) transed_pipeline = trans_pipeline(pipeline_data) print "transed pipeline data is {}".format( json.dumps(transed_pipeline)) print "\n begin update pipeline {}".format( transed_pipeline["name"]) update_pipeline(transed_pipeline) utils.task_record(pipeline_file)
def get_cm(cm_file): return utils.file_reader(cm_file)
def get_svc_lb(svc_name): return utils.file_reader(utils.get_current_folder() + consts.Prefix["lb_name_prefix"] + svc_name)
def get_lb(lb_file): return utils.file_reader(utils.get_current_folder() + lb_file)
from fantz import * from utils.utils import file_reader, file_writer INPUT_FILE_LOCATION = 'data/fantz1.in' OUTPUT_FILE_LOCATION = 'fantz.out' if __name__ == '__main__': binary_number, decimal_number = file_reader(INPUT_FILE_LOCATION) result = fantz_launcher(str(binary_number), int(decimal_number)) print(f'Binary number: {binary_number} Decimal number: {decimal_number} \n' f'Replaces amount: {result}') file_writer(OUTPUT_FILE_LOCATION, result)