def do_create_repo_rev_file(self): if "REPO_REV_FILE_VARS" not in var_list: raise ValueError("REPO_REV_FILE_VARS must be defined") repo_rev_vars = var_list.resolve_to_list("$(REPO_REV_FILE_VARS)") var_list.set_var("REPO_REV").append("$(TARGET_REPO_REV)") # override the repo rev from the config file dangerous_intersection = set(repo_rev_vars).intersection(set(("AWS_ACCESS_KEY_ID","AWS_SECRET_ACCESS_KEY", "PRIVATE_KEY", "PRIVATE_KEY_FILE"))) if dangerous_intersection: print("found", str(dangerous_intersection), "in REPO_REV_FILE_VARS, aborting") raise ValueError("file REPO_REV_FILE_VARS "+str(dangerous_intersection)+" and so is forbidden to upload") info_map_file = var_list.resolve("$(ROOT_LINKS_FOLDER_REPO)/$(TARGET_REPO_REV)/instl/info_map.txt") info_map_sigs = self.create_sig_for_file(info_map_file) var_list.set_var("INFO_MAP_SIG").append(info_map_sigs["SHA-512_rsa_sig"]) var_list.set_var("INFO_MAP_CHECKSUM").append(info_map_sigs["sha1_checksum"]) var_list.set_var("INDEX_URL").append("$(SYNC_BASE_URL)/$(REPO_REV)/instl/index.yaml") index_file = var_list.resolve("$(ROOT_LINKS_FOLDER_REPO)/$(TARGET_REPO_REV)/instl/index.yaml") index_file_sigs = self.create_sig_for_file(index_file) var_list.set_var("INDEX_SIG").append(index_file_sigs["SHA-512_rsa_sig"]) var_list.set_var("INDEX_CHECKSUM").append(index_file_sigs["sha1_checksum"]) for var in repo_rev_vars: if var not in var_list: raise ValueError(var+" is missing cannot write repo rev file") repo_rev_yaml = YamlDumpDocWrap(var_list.repr_for_yaml(repo_rev_vars, include_comments=False), '!define', "", explicit_start=True, sort_mappings=True) safe_makedirs(var_list.resolve("$(ROOT_LINKS_FOLDER)/admin")) local_file = var_list.resolve("$(ROOT_LINKS_FOLDER)/admin/$(REPO_REV_FILE_NAME).$(TARGET_REPO_REV)") with open(local_file, "w") as wfd: writeAsYaml(repo_rev_yaml, out_stream=wfd, indentor=None, sort=True) print("created", local_file)
def do_list_imp(self, what = None, stream=sys.stdout): if what is None: augmentedYaml.writeAsYaml(self, stream) list_to_do = list() if isinstance(what, str): list_to_do.append(what) elif isinstance(what, list): list_to_do.extend(what) whole_sections_to_write = list() individual_items_to_write = list() for item_to_do in list_to_do: if guid_re.match(item_to_do): whole_sections_to_write.append({item_to_do: iids_from_guid(self.install_definitions_index, item_to_do)}) elif item_to_do == "define": whole_sections_to_write.append(augmentedYaml.YamlDumpDocWrap(var_list, '!define', "Definitions", explicit_start=True, sort_mappings=True)) elif item_to_do == "index": whole_sections_to_write.append(augmentedYaml.YamlDumpDocWrap(self.install_definitions_index, '!index', "Installation index", explicit_start=True, sort_mappings=True)) elif item_to_do == "guid": guid_dict = dict() for lic in guid_list(self.install_definitions_index): guid_dict[lic] = iids_from_guid(self.install_definitions_index, lic) whole_sections_to_write.append(augmentedYaml.YamlDumpDocWrap(guid_dict, '!guid', "guid to IID", explicit_start=True, sort_mappings=True)) else: individual_items_to_write.append(item_to_do) augmentedYaml.writeAsYaml(whole_sections_to_write+self.repr_for_yaml(individual_items_to_write), stream)
def write_history(self): selected_tab = self.notebook.tab(self.notebook.select(), option='text') var_stack.set_var("SELECTED_TAB").append(selected_tab) the_list_yaml_ready= var_stack.repr_for_yaml(which_vars=var_stack.resolve_var_to_list("__GUI_CONFIG_FILE_VARS__"), include_comments=False, resolve=False, ignore_unknown_vars=True) the_doc_yaml_ready = augmentedYaml.YamlDumpDocWrap(the_list_yaml_ready, '!define', "Definitions", explicit_start=True, sort_mappings=True) with open(var_stack.resolve_var("INSTL_GUI_CONFIG_FILE_NAME"), "w") as wfd: make_open_file_read_write_for_all(wfd) augmentedYaml.writeAsYaml(the_doc_yaml_ready, wfd)
def write_require_file(self, file_path): require_dict = dict() for IID in sorted(self.install_definitions_index.iterkeys()): if len(self.install_definitions_index[IID].required_by) > 0: require_dict[IID] = sorted(self.install_definitions_index[IID].required_by) with open(file_path, "w") as wfd: make_open_file_read_write_for_all(wfd) require_dict = augmentedYaml.YamlDumpDocWrap(require_dict, '!require', "requirements", explicit_start=True, sort_mappings=True) augmentedYaml.writeAsYaml(require_dict, wfd)
def create_instl_history_file(self): var_stack.set_var("__BATCH_CREATE_TIME__").append(time.strftime("%Y/%m/%d %H:%M:%S")) yaml_of_defines = augmentedYaml.YamlDumpDocWrap(var_stack, '!define', "Definitions", explicit_start=True, sort_mappings=True) # write the history file, but only if variable LOCAL_REPO_BOOKKEEPING_DIR is defined # and the folder actually exists. if os.path.isdir(var_stack.resolve("$(LOCAL_REPO_BOOKKEEPING_DIR)", default="")): with open(var_stack.resolve("$(INSTL_HISTORY_TEMP_PATH)"), "w") as wfd: make_open_file_read_write_for_all(wfd) augmentedYaml.writeAsYaml(yaml_of_defines, wfd) self.batch_accum += self.platform_helper.append_file_to_file("$(INSTL_HISTORY_TEMP_PATH)", "$(INSTL_HISTORY_PATH)")
def do_listindex(self, params): if params: params = shlex.split(params) params_not_in_index = list() for param in params: if param in self.client_prog_inst.install_definitions_index: self.client_prog_inst.install_definitions_index[param].resolve_inheritance(self.client_prog_inst.install_definitions_index) augmentedYaml.writeAsYaml({param: self.client_prog_inst.install_definitions_index[param].repr_for_yaml()}) else: params_not_in_index.append(param) if params_not_in_index: print("Not found in index:\n ", "\n ".join(params_not_in_index))
def create_instl_history_file(self): var_list.set_var("__BATCH_CREATE_TIME__").append(time.strftime("%Y/%m/%d %H:%M:%S")) yaml_of_defines = augmentedYaml.YamlDumpDocWrap(var_list, '!define', "Definitions", explicit_start=True, sort_mappings=True) with open(var_list.resolve("$(INSTL_HISTORY_TEMP_PATH)"), "w") as wfd: augmentedYaml.writeAsYaml(yaml_of_defines, wfd) self.batch_accum += self.platform_helper.append_file_to_file("$(INSTL_HISTORY_TEMP_PATH)", "$(INSTL_HISTORY_PATH)")
def write_program_state(self): from utils import write_to_file_or_stdout state_file = var_stack.resolve("$(__MAIN_STATE_FILE__)", raise_on_fail=True) with write_to_file_or_stdout(state_file) as fd: augmentedYaml.writeAsYaml(self, fd)