Ejemplo n.º 1
0
    def submit_numeric_value(self):

        number = float(self.numeric_value_spinbox.get())

        path = self.file_combobox.get()
        option = get.option_names_in_file(path)[
            self.select_setting_combobox.current()]

        value = get.possible_value_by_number(
            path, option, self.select_value_combobox.current())

        diff_from_step = check.diff_to_step(value['min'], value['max'],
                                            value['step'], number)

        if value['max'] != None and value['max'] != '' and number > float(
                value['max']):
            tk.messagebox.showwarning(title='Out of range',
                                      message="Number is bigger than max")
        elif value['min'] != None and value['min'] != '' and number < float(
                value['min']):
            tk.messagebox.showwarning(title='Out of range',
                                      message="Number is less than min")
        elif value['step'] != None and value[
                'step'] != '' and diff_from_step != 0:
            tk.messagebox.showwarning(
                title='Out of range',
                message='Number fails the step constraint by ' +
                str(diff_from_step))
        else:
            response = set.option_value(path, option, number)

            if response == 200:
                self.switch_to_before_set_value()
            elif response == 701:
                tk.messagebox.showwarning(title="Error", message="701 Error")
Ejemplo n.º 2
0
    def submit_generic_value(self):
        value = self.generic_value_entery.get()

        check_value = check.general_value(value)

        if check_value == 700:
            tk.messagebox.showwarning(title='Bad Input',
                                      message="Value must not contain ','")
        elif check_value == 701:
            tk.messagebox.showwarning(title='Bad Input',
                                      message="Error: Value includes new line")
        elif check_value != 200:
            tk.messagebox.showwarning(title="Unspecified Error",
                                      message="Unspecified Error")
        else:
            path = self.file_combobox.get()
            option = get.option_names_in_file(path)[
                self.select_setting_combobox.current()]

            response = set.option_value(path, option, value)

            if response == 200:
                self.switch_to_before_set_value()
            elif response == 701:
                tk.messagebox.showwarning(title="Error", message="701 Error")
Ejemplo n.º 3
0
    def switch_to_edit_file(self):
        self.edit_option_frame.pack_forget()
        self.new_option_frame.pack_forget()
        self.new_file_frame.pack_forget()
        self.main_frame.pack_forget()
        self.file_description_frame.pack_forget()

        file_description = get.file_description(self.current_path)

        if file_description != None:
            file_description = file_description.replace('\n', ' ')
            file_description = textwrap.fill(file_description, width=80)

        self.edit_file_description_label.configure(text=file_description)

        options_list = get.option_names_in_file(self.current_path)

        if options_list == []:
            self.edit_file_list_combobox.config(state="disabled")
            self.edit_file_edit_button.config(state="disabled")
            self.edit_file_remove_button.config(state="disabled")
        else:
            self.edit_file_list_combobox.config(state="normal")
            self.edit_file_edit_button.config(state="normal")
            self.edit_file_remove_button.config(state="normal")
            self.edit_file_list_combobox.configure(values=options_list)
            self.edit_file_list_combobox.current(0)

        self.edit_file_frame.pack(side='top')
Ejemplo n.º 4
0
    def switch_to_possible_values(self):
        path = self.file_combobox.get()
        option = get.option_names_in_file(path)[
            self.select_setting_combobox.current()]

        self.possible_values_current_label.configure(
            text=self.current_value_part_1 +
            extract.get_value(path, option)['Value'])

        self.possible_values = []

        self.inside_file_frame.pack_forget()

        if self.has_dot_xml:
            i = 1
            for value in get.option_values(path, option):
                comment = get.possible_value_by_number(path, option,
                                                       i - 1)['comment']
                if comment == None:
                    comment = ''
                else:
                    comment = ': ' + comment

                self.possible_values.append(value + comment)
                i += 1

            self.possible_values.append('Manual Value')

            self.select_value_combobox.configure(values=self.possible_values)
            self.select_value_combobox.current(0)
            self.possible_values_frame.pack(side='top')

        else:
            self.generic_value_entery.delete(0, 'end')
            self.generic_value_frame.pack(side='top')
Ejemplo n.º 5
0
    def select_possible_value_event(self):
        self.possible_values_frame.pack_forget()

        if self.select_value_combobox.current() == len(
                self.possible_values) - 1:
            self.generic_value_entery.delete(0, 'end')
            self.generic_value_frame.pack(side='top')
        else:

            path = self.file_combobox.get()
            option = get.option_names_in_file(path)[
                self.select_setting_combobox.current()]

            value = get.possible_value_by_number(
                path, option, self.select_value_combobox.current())

            if 'min' in value:  # Check if value is ranged
                self.numeric_value_spinbox.delete(0, 'end')

                min = max = step = initial = 0
                style = ''

                if value['min'] == None or value['min'] == '':
                    min = -sys.maxsize
                else:
                    initial = min = float(value['min'])

                if value['max'] == None or value['max'] == '':
                    max = sys.maxsize
                else:
                    max = float(value['max'])

                if value['step'] == None or value['step'] == '':
                    step = 1
                else:
                    step = float(value['step'])

                style = '% ' + str(len(str(step).split('.')[1])) + 'f'

                self.numeric_value_spinbox.configure(from_=min,
                                                     to=max,
                                                     format=style,
                                                     increment=step)
                self.numeric_value_spinbox.set(initial)
                self.numeric_value_frame.pack(side='top')

            elif 'name' in value:  # Value is a single choice
                response = set.option_value(path, option, value['name'])

                if response == 200:
                    self.switch_to_before_set_value()
                elif response == 701:
                    tk.messagebox.showwarning(title="Error",
                                              message="701 Error")
Ejemplo n.º 6
0
    def switch_to_inside_file(self):
        self.possible_values_frame.pack_forget()

        path = self.file_combobox.get()
        option_list = get.option_names_in_file(path)

        if len(option_list) == 0:
            tk.messagebox.showwarning(title='No options',
                                      message='This file has no options!')
        else:
            if os.path.isfile(path + '.xml'):
                self.has_dot_xml = True

                file_description = get.file_description(path)

                if file_description != None:
                    file_description = self.file_description_part_1 + file_description

                    file_description = file_description.replace('\n', ' ')
                    file_description = textwrap.fill(file_description,
                                                     width=75)

                else:
                    file_description = ''

                self.file_description_label.configure(text=file_description)

            else:
                self.file_description_label.configure(
                    text=
                    'Caution: .setting.xml file missing, no additional data is provided for this setting!'
                )

            self.frame1.pack_forget()

            for i in range(len(option_list)):
                comment = get.option_comment(path, option_list[i])

                if comment != None:
                    option_list[i] = option_list[i] + ': ' + comment

            self.select_setting_combobox.configure(values=option_list)
            self.select_setting_combobox.current(0)
            self.inside_file_frame.pack(side='top')
Ejemplo n.º 7
0
    def on_option_remove_event(self):
        response = tk.messagebox.askquestion(
            'Confirmation', 'Are you sure you want delete this option?')

        if response == 'yes':
            response = common.remove_option_from_file(
                self.current_path, self.edit_file_list_combobox.get())

            option_list = get.option_names_in_file(self.current_path)

            if option_list == []:
                self.edit_file_list_combobox.config(state="disabled")
                self.edit_file_edit_button.config(state="disabled")
                self.edit_file_remove_button.config(state="disabled")
            else:
                self.edit_file_list_combobox.config(state="normal")
                self.edit_file_edit_button.config(state="normal")
                self.edit_file_remove_button.config(state="normal")
                self.edit_file_list_combobox.configure(values=option_list)
                self.edit_file_list_combobox.current(0)
Ejemplo n.º 8
0
            print(str(i+1) + '. ' + approved_dot_setting_list[i])

        choice = input('\nEnter the number of file you want to edit (1 to ' + str(len(approved_dot_setting_list)) + ", 0 to exit): ").strip()

        if choice == '0' or choice == '':
            break

        elif choice.isdecimal():
            choice = int(choice)

            if choice < 1 or choice > len(approved_dot_setting_list):
                print('\nNumber is not in range!\n')
            else:
                path = approved_dot_setting_list[choice-1]

                option_list = get.option_names_in_file(path)

                if len(option_list) == 0:
                    print('\nThis file has no options\n')
                    continue

                has_dot_xml = True
                
                if not os.path.isfile(path + '.xml'):
                    has_dot_xml = False
                    print('\nCaution: .setting.xml file missing, no additional data is provided for this setting')

                description = get.file_description(path)

                if description != None:
                    print('\nSetting file description: ' +  description + '\n')
Ejemplo n.º 9
0
def edit(path_to_dot_setting):
    path = path_to_dot_setting

    print('\nThis file contains these options: ' +
          str(get.option_names_in_file(path)))

    while True:
        choice = input(
            "\nEnter '1' to edit a option\nEnter '2' to add a new option\n"
            "Enter '3' to remove a option\nEnter '4' to see the list of options in current file\n"
            "Enter '5' to set description for this file\nEnter 0 to get back\n\n->"
        ).strip()

        if choice == '0' or choice == '':
            break

        elif choice == '1':
            while True:
                name = input('Enter the option name: ').strip()

                name_check = check.option_name(name)

                if name_check == 701:
                    print("\nName must not contain ':'\n")
                elif name_check == 702:
                    print("\nName must not contain ','\n")
                elif name_check == 700:
                    break
                elif name_check == 703:
                    print("\nName cannot start with '#'\n")
                elif name_check == 704:
                    print("\nError: Name includes new line\n")
                elif name_check != 200:
                    print("\nUnspecified Error\n")
                elif not check.option_exists_in_file(path, name):
                    print('\nOption not found!\n')
                else:
                    while True:
                        choice = input(
                            "\nEnter '1' to change option name\nEnter '2' to change default value\n"
                            "Enter '3' to change comment\nEnter '4' to manage possible values for this option\n"
                            "Enter 0 to get back\n\n->").strip()

                        if choice == '0' or choice == '':
                            break

                        elif choice == '1':
                            while True:
                                new_name = input(
                                    'Enter new option name: ').strip()

                                name_check = check.option_name(new_name)

                                if name_check == 701:
                                    print("\nName must not contain ':'\n")
                                elif name_check == 702:
                                    print("\nName must not contain ','\n")
                                elif name_check == 703:
                                    print("\nName cannot start with '#'\n")
                                elif name_check == 704:
                                    print("\nError: Name includes new line\n")
                                elif name_check == 700:
                                    break
                                elif name_check != 200:
                                    print("\nUnspecified Error\n")
                                elif check.option_exists_in_file(
                                        path, new_name):
                                    print(
                                        '\nThis option name already exists!\n')
                                else:
                                    response = common.change_option_name(
                                        path, name, new_name)

                                    if response == 200:
                                        print('\nName changed successfully.\n')
                                    elif response == 201:
                                        print(
                                            '\nName changed successfully.\nCaution: Option name was not found in .setting.xml file, file could be corrupted\n'
                                        )
                                    break

                        elif choice == '2':
                            while True:
                                value = input('Enter default value: ').strip()

                                check_value = check.general_value(value)

                                if check_value == 700:
                                    print("\nValue must not contain ','\n")
                                elif check_value == 701:
                                    print("\nError: Value includes new line\n")
                                elif check_value != 200:
                                    print("\nUnspecified Error\n")
                                elif value == '':
                                    break
                                else:
                                    response = set.default(path, name, value)

                                    if response == 200:
                                        print(
                                            '\nDefault value set successfully.\n'
                                        )
                                    elif response == 201:
                                        print(
                                            '\nDefault value set successfully.\nCaution: Option name was not found in .setting.xml file, file could be corrupted\n'
                                        )
                                    break

                        elif choice == '3':
                            while True:
                                comment = input('Enter the comment: ').strip()

                                if '\n' in comment:
                                    print(
                                        "\nError: Comment includes new line\n")
                                elif comment == '':
                                    break
                                else:
                                    response = set.option_comment(
                                        path, name, comment)

                                    if response == 200:
                                        print('\nComment set successfully.\n')
                                    elif response == 201:
                                        print(
                                            '\nComment set successfully.\nCaution: Option name was not found in .setting.xml file, file could be corrupted\n'
                                        )

                                    break

                        elif choice == '4':
                            show_option_values(path, name)

                            while True:
                                choice = input(
                                    "\nEnter '1' to add a value\nEnter '2' to edit a value\n"
                                    "Enter '3' to remove a value\nEnter '4' to see a list of current values\n"
                                    "Enter 0 to get back\n\n->").strip()

                                if choice == '0' or choice == '':
                                    break

                                elif choice == '1':
                                    while True:
                                        choice = input(
                                            "\nEnter '1' for simple value\nEnter '2' for number range value\n"
                                            "Enter 0 to get back\n\n->")

                                        if choice == '0' or choice == '':
                                            break

                                        elif choice == '1':
                                            while True:
                                                value = input(
                                                    'Enter the value: ').strip(
                                                    )

                                                check_value = check.general_value(
                                                    value)

                                                if check_value == 700:
                                                    print(
                                                        "\nValue must not contain ','\n"
                                                    )
                                                elif check_value == 701:
                                                    print(
                                                        "\nError: Value includes new line\n"
                                                    )
                                                elif check_value != 200:
                                                    print(
                                                        "\nUnspecified Error\n"
                                                    )
                                                elif value == '':
                                                    break
                                                elif check.option_simple_value_exists(
                                                        path, name, value):
                                                    print(
                                                        '\nThis value already exists!\n'
                                                    )
                                                else:
                                                    while True:
                                                        comment = input(
                                                            'Enter the single line comment for option: '
                                                        ).strip()

                                                        if '\n' in comment:
                                                            print(
                                                                "\nError: Comment includes new line\n"
                                                            )
                                                        else:
                                                            response = common.add_simple_value(
                                                                path, name,
                                                                value, comment)

                                                            if response == 200:
                                                                print(
                                                                    '\nValue added successfully\n'
                                                                )
                                                            else:
                                                                print(
                                                                    '\nSome error occured\n'
                                                                )
                                                            break
                                                    break

                                        elif choice == '2':
                                            while True:
                                                min = input(
                                                    'Enter the minimum (Enter nothing to skip): '
                                                ).strip()

                                                if min == '':
                                                    break

                                                try:
                                                    float(min)
                                                    break
                                                except:
                                                    print(
                                                        '\n' + min +
                                                        ' is not a number!\n')

                                            while True:
                                                max = input(
                                                    'Enter the maximum (Enter nothing to skip): '
                                                ).strip()

                                                if max == '':
                                                    break

                                                try:
                                                    float(max)
                                                    break
                                                except:
                                                    print(
                                                        '\n' + max +
                                                        ' is not a number!\n')

                                            while True:
                                                step = input(
                                                    'Enter the step (Enter nothing to skip): '
                                                ).strip()

                                                if step == '':
                                                    break

                                                try:
                                                    float(step)
                                                    break
                                                except:
                                                    print(
                                                        '\n' + step +
                                                        ' is not a number!\n')

                                            if min == max == step == '':
                                                continue

                                            elif check.option_renage_value_exists(
                                                    path, name, min, max,
                                                    step):
                                                print(
                                                    '\nThis range is already added!\n'
                                                )
                                            else:
                                                while True:
                                                    comment = input(
                                                        'Enter the single line comment for option: '
                                                    ).strip()

                                                    if '\n' in comment:
                                                        print(
                                                            "\nError: Comment includes new line\n"
                                                        )
                                                    else:
                                                        response = common.add_range_value(
                                                            path, name, min,
                                                            max, step, comment)

                                                        if response == 200:
                                                            print(
                                                                '\nRange added successfully\n'
                                                            )
                                                        else:
                                                            print(
                                                                '\nSome error occured\n'
                                                            )
                                                        break

                                        else:
                                            print('\nCommand not found!\n')

                                elif choice == '2':
                                    number_of_values = len(
                                        get.option_values(path, name))

                                    if number_of_values == 0:
                                        print('\nOption has no values\n')
                                    else:
                                        choice = input(
                                            '\nEnter the number of value you want to edit (1 to '
                                            + str(number_of_values) +
                                            '): ').strip()

                                        if choice.isdecimal():
                                            choice = int(choice)

                                            if choice < 1 or choice > number_of_values:
                                                print(
                                                    '\nNumber is not in range\n'
                                                )
                                            else:
                                                while True:
                                                    action = input(
                                                        "\nEnter '1' set comment\nEnter '2' edit value\n"
                                                        "Enter 0 to get back\n\n->"
                                                    )

                                                    if action == '0' or action == '':
                                                        break

                                                    elif action == '1':
                                                        while True:
                                                            comment = input(
                                                                'Enter the single line comment for option: '
                                                            ).strip()

                                                            if '\n' in comment:
                                                                print(
                                                                    "\nError: Comment includes new line\n"
                                                                )
                                                            else:
                                                                response = common.set_value_comment_by_number(
                                                                    path, name,
                                                                    choice - 1,
                                                                    comment)

                                                                if response == 200:
                                                                    print(
                                                                        '\nCommented is set\n'
                                                                    )
                                                                else:
                                                                    print(
                                                                        '\nSome error occured\n'
                                                                    )
                                                                break

                                                    elif action == '2':
                                                        value = get.possible_value_by_number(
                                                            path, name,
                                                            choice - 1)

                                                        if 'min' in value:  #Check if value is ranged
                                                            while True:
                                                                action = input(
                                                                    "\nEnter '1' to set min\nEnter '2' to set max\nEnter '3' to set step\n"
                                                                    "Enter 0 to get back\n\n->"
                                                                ).strip()

                                                                if action == '0' or action == '':
                                                                    break

                                                                elif action == '1':
                                                                    while True:
                                                                        min = input(
                                                                            'Enter the min (Enter nothing for empty): '
                                                                        ).strip(
                                                                        )

                                                                        if min != '':
                                                                            try:
                                                                                float(
                                                                                    min
                                                                                )
                                                                            except:
                                                                                print(
                                                                                    '\n'
                                                                                    +
                                                                                    min
                                                                                    +
                                                                                    ' is not a number!\n'
                                                                                )
                                                                                continue

                                                                        if min == value[
                                                                                'max'] == value[
                                                                                    'step'] == '':
                                                                            print(
                                                                                '\nCannot have min, max and step empty\n'
                                                                            )

                                                                        elif check.option_renage_value_exists(
                                                                                path,
                                                                                name,
                                                                                min,
                                                                                value[
                                                                                    'max'],
                                                                                value[
                                                                                    'step']
                                                                        ):
                                                                            print(
                                                                                '\nThis range is already added!\n'
                                                                            )
                                                                        else:
                                                                            response = common.set_ranged_possible_value_by_number(
                                                                                path,
                                                                                name,
                                                                                choice
                                                                                -
                                                                                1,
                                                                                min,
                                                                                value[
                                                                                    'max'],
                                                                                value[
                                                                                    'step']
                                                                            )

                                                                            if response == 200:
                                                                                print(
                                                                                    '\nValue is set\n'
                                                                                )
                                                                            else:
                                                                                print(
                                                                                    '\nSome error occured\n'
                                                                                )
                                                                            break
                                                                    break
                                                                elif action == '2':
                                                                    while True:
                                                                        max = input(
                                                                            'Enter the max (Enter nothing for empty): '
                                                                        ).strip(
                                                                        )

                                                                        if max != '':
                                                                            try:
                                                                                float(
                                                                                    max
                                                                                )
                                                                            except:
                                                                                print(
                                                                                    '\n'
                                                                                    +
                                                                                    max
                                                                                    +
                                                                                    ' is not a number!\n'
                                                                                )
                                                                                continue

                                                                        if value['min'] == max == value[
                                                                                'step'] == '':
                                                                            print(
                                                                                '\nCannot have min, max and step empty\n'
                                                                            )

                                                                        elif check.option_renage_value_exists(
                                                                                path,
                                                                                name,
                                                                                value[
                                                                                    'min'],
                                                                                max,
                                                                                value[
                                                                                    'step']
                                                                        ):
                                                                            print(
                                                                                '\nThis range is already added!\n'
                                                                            )
                                                                        else:
                                                                            response = common.set_ranged_possible_value_by_number(
                                                                                path,
                                                                                name,
                                                                                choice
                                                                                -
                                                                                1,
                                                                                value[
                                                                                    'min'],
                                                                                max,
                                                                                value[
                                                                                    'step']
                                                                            )

                                                                            if response == 200:
                                                                                print(
                                                                                    '\nValue is set\n'
                                                                                )
                                                                            else:
                                                                                print(
                                                                                    '\nSome error occured\n'
                                                                                )
                                                                            break
                                                                    break
                                                                elif action == '3':
                                                                    while True:
                                                                        step = input(
                                                                            'Enter the step (Enter nothing for empty): '
                                                                        ).strip(
                                                                        )

                                                                        if step != '':
                                                                            try:
                                                                                float(
                                                                                    step
                                                                                )
                                                                            except:
                                                                                print(
                                                                                    '\n'
                                                                                    +
                                                                                    step
                                                                                    +
                                                                                    ' is not a number!\n'
                                                                                )
                                                                                continue

                                                                        if value['min'] == value[
                                                                                'max'] == step == '':
                                                                            print(
                                                                                '\nCannot have min, max and step empty\n'
                                                                            )

                                                                        elif check.option_renage_value_exists(
                                                                                path,
                                                                                name,
                                                                                value[
                                                                                    'min'],
                                                                                value[
                                                                                    'max'],
                                                                                step
                                                                        ):
                                                                            print(
                                                                                '\nThis range is already added!\n'
                                                                            )
                                                                        else:
                                                                            response = common.set_ranged_possible_value_by_number(
                                                                                path,
                                                                                name,
                                                                                choice
                                                                                -
                                                                                1,
                                                                                value[
                                                                                    'min'],
                                                                                value[
                                                                                    'max'],
                                                                                step
                                                                            )

                                                                            if response == 200:
                                                                                print(
                                                                                    '\nValue is set\n'
                                                                                )
                                                                            else:
                                                                                print(
                                                                                    '\nSome error occured\n'
                                                                                )
                                                                            break
                                                                    break
                                                                else:
                                                                    print(
                                                                        '\nCommand not found!\n'
                                                                    )

                                                        elif 'name' in value:
                                                            while True:
                                                                value = input(
                                                                    'Enter the new value: '
                                                                ).strip()

                                                                check_value = check.general_value(
                                                                    value)

                                                                if check_value == 700:
                                                                    print(
                                                                        "\nValue must not contain ','\n"
                                                                    )
                                                                elif check_value == 701:
                                                                    print(
                                                                        "\nError: Value includes new line\n"
                                                                    )
                                                                elif check_value != 200:
                                                                    print(
                                                                        "\nUnspecified Error\n"
                                                                    )
                                                                elif value == '':
                                                                    break
                                                                elif check.option_simple_value_exists(
                                                                        path,
                                                                        name,
                                                                        value):
                                                                    print(
                                                                        '\nThis value already exists!\n'
                                                                    )
                                                                else:
                                                                    response = common.set_simple_possible_value_by_number(
                                                                        path,
                                                                        name,
                                                                        choice
                                                                        - 1,
                                                                        value)

                                                                    if response == 200:
                                                                        print(
                                                                            '\nName has changed\n'
                                                                        )
                                                                    else:
                                                                        print(
                                                                            '\nSome error occured\n'
                                                                        )
                                                                    break
                                                            break
                                                    else:
                                                        print(
                                                            '\nCommand not found!\n'
                                                        )

                                        else:
                                            print('\nInput must be a number\n')

                                elif choice == '3':

                                    number_of_values = len(
                                        get.option_values(path, name))

                                    if number_of_values == 0:
                                        print('\nOption has no values\n')
                                    else:
                                        choice = input(
                                            '\nEnter the number of value you want to be removed (1 to '
                                            + str(number_of_values) +
                                            '): ').strip()

                                        if choice.isdecimal():
                                            choice = int(choice)

                                            if choice < 1 or choice > number_of_values:
                                                print(
                                                    '\nNumber is not in range\n'
                                                )
                                            else:
                                                common.remove_possible_value_by_number(
                                                    path, name, choice - 1)
                                                print(
                                                    '\nValue removed successfully\n'
                                                )

                                        else:
                                            print('\nInput must be a number\n')

                                elif choice == '4':
                                    show_option_values(path, name)

                                else:
                                    print('\nCommand not found!\n')
                        else:
                            print('\nCommand not found!\n')

                    break

        elif choice == '2':
            while True:
                name = input('Enter the option name: ').strip()

                name_check = check.option_name(name)

                if name_check == 701:
                    print("\nName must not contain ':'\n")
                elif name_check == 702:
                    print("\nName must not contain ','\n")
                elif name_check == 700:
                    break
                elif name_check == 703:
                    print("\nName cannot start with '#'\n")
                elif name_check == 704:
                    print("\nError: Name includes new line\n")
                elif name_check != 200:
                    print("\nUnspecified Error\n")
                elif check.option_exists_in_file(path, name):
                    print('\nThis option name already exists!\n')
                else:
                    while True:
                        comment = input(
                            'Enter the single line comment for option: '
                        ).strip()

                        if '\n' in comment:
                            print("\nError: Comment includes new line\n")
                        else:
                            response = common.add_option_to_file(
                                path, name, comment)

                            if response == 200:
                                print('\nOption created successfully\n')
                            elif response == 201:
                                print(
                                    '\nCaution: Option created successfully! Definition for option '
                                    + name +
                                    ' already exists in setting.xml file\n')
                            break
                break

        elif choice == '3':
            while True:
                name = input('Enter the option name: ').strip()

                name_check = check.option_name(name)

                if name_check == 701:
                    print("\nName must not contain ':'\n")
                elif name_check == 702:
                    print("\nName must not contain ','\n")
                elif name_check == 700:
                    break
                elif name_check == 703:
                    print("\nName cannot start with '#'\n")
                elif name_check == 704:
                    print("\nError: Name includes new line\n")
                elif name_check != 200:
                    print("\nUnspecified Error\n")
                elif not check.option_exists_in_file(path, name):
                    print('\nOption with this name does not exist!\n')
                else:
                    response = common.remove_option_from_file(path, name)

                    if response == 200:
                        print('\nOption removed successfully\n')
                    elif response == 201:
                        print(
                            "\nCaution: Option removed successfully but Option '"
                            + name + "' didn't exist in setting.xml file.\n"
                            "It causes no problem in removing but means that your .setting.xml was corrupted.\n"
                        )
                    break

        elif choice == '4':
            print('\nThis file contains these options: ' +
                  str(get.option_names_in_file(path)))

        elif choice == '5':
            description = cli.get_multiline_input(
                '\nEnter any description you may have for this file')

            if description != '':
                set.file_description(path, description)

            print('\nDescription changed successfully\n')

        else:
            print('\nCommand not found!\n')
Ejemplo n.º 10
0
    def new_option_save_event(self):
        error_list = ''
        success_list = ''

        new_name = self.new_option_name_entry.get()

        name_check = check.option_name(new_name)

        if name_check == 701:
            error_list += "Option name must not contain ':'\n"
        elif name_check == 702:
            error_list += "Option name must not contain ','\n"
        elif name_check == 703:
            error_list += "Option name cannot start with '#'\n"
        elif name_check == 704:
            error_list += "Error: Option name includes new line\n"
        elif name_check == 700:
            error_list += 'Option name cannot be empty!\n'
        elif name_check != 200:
            error_list += 'Unspecified Option Name Error\n'
        elif check.option_exists_in_file(self.current_path, new_name):
            error_list += 'This option name already exists!\n'
        else:
            comment = self.new_option_comment_entry.get()

            if '\n' in comment:
                error_list += 'Error: Comment includes new line\n'
                comment = ''

            response = common.add_option_to_file(self.current_path, new_name,
                                                 comment)

            if response == 200:
                success_list += 'Option created successfully\n'
            elif response == 201:
                error_list += 'Caution: Option created successfully! Definition for option ' + new_name + ' already exists in setting.xml file\n'

            options_list = get.option_names_in_file(self.current_path)

            self.edit_file_list_combobox.config(state="normal")
            self.edit_file_edit_button.config(state="normal")
            self.edit_file_remove_button.config(state="normal")
            self.edit_file_list_combobox.configure(values=options_list)
            self.edit_file_list_combobox.current(len(options_list) - 1)

            new_default = self.new_option_default_value_entry.get()

            check_value = check.general_value(new_default)

            if check_value == 700:
                error_list += "Default must not contain ','\n"
            elif check_value == 701:
                error_list += "Error: Default includes new line\n"
            elif check_value != 200:
                error_list += 'Unspecified Default Error\n'
            else:
                response = set.default(self.current_path, new_name,
                                       new_default)

        if success_list != '':
            tk.messagebox.showinfo(title='Created Successfully',
                                   message=success_list)
        if error_list != '':
            tk.messagebox.showerror(title='Error', message=error_list)
        if success_list != '':
            self.switch_to_edit_option()