Add ability to set theme globally

This commit is contained in:
Vladyslav Hroshev
2023-12-10 22:47:34 +02:00
parent bdd74f94bf
commit 253913ae40
5 changed files with 322 additions and 46 deletions

View File

@@ -145,3 +145,39 @@ def hex_to_rgba(hex_color):
int(hex_color[2:4], 16), \
int(hex_color[4:6], 16), \
int(hex_color[6:8], 16) / 255
def label_files(directory, label, *args):
"""
Add a label to all files in a directory
:param directory: folder where files are located
:param label: label to add
:param args: files to change links to labeled files
:return:
"""
# Open all files
files = [open(file, 'r+') for file in args]
read_files = [file.read() for file in files]
for filename in os.listdir(directory):
# Skip if the file is already labeled
if label in filename:
continue
# Split the filename into name and extension
name, extension = os.path.splitext(filename)
# Form the new filename and rename the file
new_filename = f"{name}-{label}{extension}"
os.rename(os.path.join(directory, filename), os.path.join(directory, new_filename))
# Replace the filename in all files
for file in read_files:
file.replace(filename, new_filename)
# Write the changes to the files and close them
for i, file in enumerate(files):
file.seek(0)
file.write(read_files[i])
file.close()