Exemplo n.º 1
0
    def project_update_variable_sets(self, project_literal_name, remove_suffix,
                                     add_suffix):
        if not project_literal_name:
            raise ValueError("project name must not be empty")
        if not add_suffix and not remove_suffix:
            raise ValueError(
                "add_suffix and remove_suffix can not be both empty")
        self.common.log_info_print(
            local_logger=self.logger,
            msg=
            f"===== updating {self.config.space_id}'s project {project_literal_name}'s variable sets by the "
            f"following operation(s)")
        if remove_suffix:
            self.common.log_info_print(
                local_logger=self.logger,
                msg=f"removing a suffix {remove_suffix}")
        if add_suffix:
            self.common.log_info_print(local_logger=self.logger,
                                       msg=f"adding a suffix {add_suffix}")

        all_variable_sets = self.common.get_one_type_ignore_error(
            item_type=item_type_library_variable_sets)
        library_variable_sets = self.common.get_list_items_from_all_items(
            all_items=all_variable_sets)
        project = self.get_project(project_literal_name)
        project_variable_sets_ids = project.get(
            included_library_variable_set_ids_key, [])
        self.logger.info("original variable sets id:")
        self.logger.info(project_variable_sets_ids)
        mapped_ids = copy.deepcopy(project_variable_sets_ids)
        for index, variable_sets_id in enumerate(project_variable_sets_ids):
            variable_set = find_item(lst=library_variable_sets,
                                     key=id_key,
                                     value=variable_sets_id)
            variable_set_name = variable_set.get(name_key)
            variable_set_name_updated = self.process_suffix(
                name=variable_set_name,
                remove_suffix=remove_suffix,
                add_suffix=add_suffix)
            new_variable_set_in_library_variable_sets = \
                find_item(lst=library_variable_sets, key=name_key, value=variable_set_name_updated)
            if new_variable_set_in_library_variable_sets:
                self.logger.info(
                    f"{new_variable_set_in_library_variable_sets.get(id_key)} found in variable sets"
                )
                mapped_ids[
                    index] = new_variable_set_in_library_variable_sets.get(
                        id_key)
        self.logger.info("mapped variable sets id:")
        self.logger.info(mapped_ids)
        no_change = compare_lists(project_variable_sets_ids, mapped_ids)
        if no_change:
            self.logger.info(f"The variable sets have no change")
            return project
        project[included_library_variable_set_ids_key] = mapped_ids
        return self.common.put_single_item_save(item_type=item_type_projects,
                                                payload=project)
Exemplo n.º 2
0
 def _get_url_prefix(self, set_name):
     info_service_list_variables = self._common.get_list_variables_by_set_name_or_id(set_name=set_name)
     if info_service_list_variables:
         url_prefix_variable = find_item(lst=info_service_list_variables, key=name_key, value=url_prefix_key)
         if url_prefix_variable:
             return url_prefix_variable.get(value_key)
     return ""
 def set_radio_channels_frame(self):
     channels_list = self.server.get_list_items_by_conditional_id(
         item_type=item_type_channels,
         condition_key=project_id_key,
         condition_id=self.server.config.project_id)
     default_channel = find_item(lst=channels_list,
                                 key=Constants.IS_DEFAULT,
                                 value=True)
     if default_channel:
         default_channel_id = default_channel.get(id_key)
     else:
         default_channel_id = self.server.config.channel_id
     self.channel_id_var = CommonWidgets.set_radio_items_frame(
         parent=self,
         list_items=channels_list,
         default_id=default_channel_id,
         title=f"Select a channel (default one is pre-selected):")
 def set_combobox_items_frame(self, items_list: list, common: Common,
                              bind_func):
     default_item = find_item(lst=items_list,
                              key=id_key,
                              value=common.config.item_id)
     default_text = SubmitWidgets.construct_item_name_id_text(
         item=default_item)
     texts_list = [
         SubmitWidgets.construct_item_name_id_text(item=item)
         for item in items_list
     ]
     self.combobox_var = CommonWidgets.set_combobox_items_frame(
         parent=self,
         texts_list=texts_list,
         bind_func=bind_func,
         default_text=default_text,
         title=
         f"Select an item for type {self.server.config.type} (item name|id, or version|id or id only:"
     )
 def set_radio_items_frame(parent, list_items: list, default_id: str = None, title="Select one: "):
     items_frame = tk.Frame(parent)
     tk.Label(items_frame, text=title, bd=2) \
         .grid(row=CommonWidgets.ROW_0, columnspan=CommonWidgets.ROW_SIZE, sticky=tk.W)
     id_var = tk.StringVar()
     list_items_copy = copy.deepcopy(list_items)
     list_items_copy.sort(key=lambda one_item: one_item.get(name_key).lower())
     item = find_item(lst=list_items_copy, key=id_key, value=default_id)
     if item:
         id_var.set(default_id)
     else:
         id_var.set(list_items_copy[0].get(id_key))
     for index, item in enumerate(list_items_copy):
         tk.Radiobutton(items_frame, text=f"{item.get(name_key)}", variable=id_var, value=item.get(id_key),
                        justify=tk.LEFT, command=lambda *args: None) \
             .grid(row=CommonWidgets.ROW_1 + int(index / CommonWidgets.ROW_SIZE),
                   column=index % CommonWidgets.ROW_SIZE, sticky=tk.W)  # , columnspan=1
     items_frame.grid(sticky=tk.W)
     return id_var
Exemplo n.º 6
0
 def clone_process_step(self,
                        project_literal_name,
                        step_name,
                        base_step_name,
                        prev_step_name=None):
     if not project_literal_name or not step_name or not base_step_name:
         raise ValueError(
             'Project literal name or step or base step names must not be empty'
         )
     self.common.log_info_print(
         local_logger=self.logger,
         msg=
         f"clone project {project_literal_name} step from base step {base_step_name} to new step "
         f"{step_name} and place it after step {prev_step_name}")
     process = self.common.get_child_item(
         parent_name=project_literal_name,
         parent_type=item_type_projects,
         child_id_key=deployment_process_id_key,
         child_type=item_type_deployment_processes)
     steps = process[steps_key]
     step = copy.deepcopy(
         find_item(lst=steps, key=name_key, value=base_step_name))
     step[name_key] = step_name
     step[id_key] = ""
     for action in step[actions_key]:
         action[name_key] = step_name
         action[id_key] = ""
     if prev_step_name:
         prev_step_name_index = find_index(lst=steps,
                                           key=name_key,
                                           value=prev_step_name)
         if prev_step_name_index < 0:
             log_raise_value_error(
                 local_logger=self.logger,
                 err=f"previous step {prev_step_name} does not exist")
         steps.insert(prev_step_name_index + 1, step)
     else:
         steps.append(step)
     child_item = self.common.put_child_item_save(
         parent_name=project_literal_name,
         child_type=item_type_deployment_processes,
         payload=process)
     return child_item