From a12f43b98ac4ede9818cb576dfe8c0458167055f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20K=C3=BCng?= <78618153+joekueng@users.noreply.github.com> Date: Wed, 3 Jul 2024 14:45:58 +0200 Subject: [PATCH] Add files via upload Init --- properties-reorder.py | 51 +++++++++++++++++++++++++++++++++++++++++++ properties-to-csv.py | 28 ++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 properties-reorder.py create mode 100644 properties-to-csv.py diff --git a/properties-reorder.py b/properties-reorder.py new file mode 100644 index 0000000..dcfe3e1 --- /dev/null +++ b/properties-reorder.py @@ -0,0 +1,51 @@ +import sys +import os + + +def sort_properties_file(file_path): + """Ordina un file .properties in base alle chiavi, mantenendo i commenti iniziali.""" + + comments = [] + properties = {} + with open(file_path, 'r', encoding='latin-1') as file: # Usa l'encoding corretto + for line in file: + line = line.strip() + if line.startswith('#'): + comments.append(line) + elif '=' in line: + key, value = line.split('=', 1) + properties[key] = value + + sorted_properties = sorted(properties.items()) + + with open(file_path, 'w', encoding='latin-1') as file: + for comment in comments: + file.write(f"{comment}\n") + for key, value in sorted_properties: + file.write(f"{key}={value}\n") + + +def process_folder(folder_path): + count = 0 + for root, _, files in os.walk(folder_path): + for filename in files: + if filename.endswith(".properties"): + file_path = os.path.join(root, filename) + try: + sort_properties_file(file_path) + count += 1 + print(f"'{count}'File '{file_path}' ordinato con successo.") + except FileNotFoundError: + print(f"Errore: File '{file_path}' non trovato.") + except Exception as e: + print(f"Errore durante l'elaborazione di '{file_path}': {e}") + + +if __name__ == '__main__': + if len(sys.argv) < 2: + print("Errore: Percorso della cartella mancante.") + print("Utilizzo: python script.py ") + sys.exit(1) + + folder_path = sys.argv[1] + process_folder(folder_path) diff --git a/properties-to-csv.py b/properties-to-csv.py new file mode 100644 index 0000000..e00a489 --- /dev/null +++ b/properties-to-csv.py @@ -0,0 +1,28 @@ +import csv +import os + +def convert_properties_to_excel(input_file): + + csv_filepath = 'temp.csv' + + with open(input_file, 'r', encoding='utf-8') as prop_file, \ + open(csv_filepath, 'w', newline='', encoding='utf-8') as csv_file: + + writer = csv.writer(csv_file, delimiter=';') + writer.writerow(['Chiave', 'Valore']) + + for line in prop_file: + line = line.strip() + if line and not line.startswith('#'): + key, value = line.split('=', 1) + writer.writerow([key, value]) + + + os.system(f'start excel "{csv_filepath}"') + input("Press Enter after saving the file") + os.remove(csv_filepath) + +if __name__ == '__main__': + input_file = 'C:\\work\\project\\opc\\hybris\\bin\\custom\\opc\\opccore\\resources\\localization\\opccore-locales_en.properties' + convert_properties_to_excel(input_file) +