Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

Commit 6356c8e

Browse files
authored
Merge pull request #38 from ohitstom/dev
(release): v3.1 Release Merge
2 parents d51d381 + 9cc60f0 commit 6356c8e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

modules/utils.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,33 @@
2222

2323
# >[Config Management]<
2424

25-
def replace_config_line(file_name, line_num, text, encoding): # replace_config_line("pathto\\config.txt", 5, "new text") <- Example Usage | Last stage of set_config_entry.
25+
def replace_config_line(file_name, line_num, text): # replace_config_line("pathto\\config.txt", 5, "new text") <- Example Usage | Last stage of set_config_entry.
2626
'''
2727
Replace a line in a text file
2828
2929
:param file_name: The path to the file you want to edit
3030
:param line_num: The line number you want to replace
3131
:param text: The text that you want to replace the line with
3232
'''
33-
lines = open(file_name, "r", encoding=encoding).readlines()
33+
lines = open(file_name, "r").readlines()
3434
lines[line_num] = f"{text}\n"
3535
with open(file_name, "w") as out:
3636
out.writelines(lines)
3737

3838

39-
def find_config_data(entry, replacement=None, config=f"{globals.spice_config}\\config-xpui.ini", encoding="utf-8", splitchar=" = "): # find_config_data("extensions") <- Example usage | Optional var: "replacement" [Used for set_config_entry].
39+
def find_config_data(entry, replacement=None, config=f"{globals.spice_config}\\config-xpui.ini", splitchar=" = "): # find_config_data("extensions") <- Example usage | Optional var: "replacement" [Used for set_config_entry].
4040
'''
4141
Finds a config entry and returns the data of it
4242
4343
:param entry: The entry you want to find
4444
:param replacement: If you want to change the value of a config entry, you can use this parameter
4545
:param config: The config file to be used
46-
:param encoding: If you want to use a different encoding, you can use this parameter
4746
:return: a tuple of three values.
4847
'''
4948
if not os.path.isfile(config):
5049
return "config NULL"
5150

52-
with open(config, "r", encoding=encoding) as file:
51+
with open(config, "r") as file:
5352
count = 0
5453
line = ""
5554
for line in file:
@@ -65,7 +64,7 @@ def find_config_data(entry, replacement=None, config=f"{globals.spice_config}\\c
6564
a = found_line_str.split(splitchar, 1)[0]
6665

6766
final_write_data = f"{a}{splitchar}{replacement}"
68-
return config, found_line_int, final_write_data, encoding
67+
return config, found_line_int, final_write_data
6968

7069
else:
7170
found_line_str = line.strip("\n")
@@ -83,10 +82,10 @@ def set_config_entry(entry, replacement, **kwargs): # set_config_entry("current
8382
'''
8483
data = find_config_data(
8584
entry,
86-
replacement if replacement is not None else "", # Checking for the need to empty the value
85+
replacement if replacement is not None else "", # statement important for wiping entries ("" is the equivelant to nothing)
8786
**kwargs,
8887
)
89-
replace_config_line(data[0], data[1], data[2], data[3])
88+
replace_config_line(data[0], data[1], data[2])
9089

9190

9291
def list_config_available(selection, theme=None): # selection: themes, colorschemes, extensions, custom_apps | Lists out available configurations.

0 commit comments

Comments
 (0)