Add files via upload
Init
This commit is contained in:
51
properties-reorder.py
Normal file
51
properties-reorder.py
Normal file
@@ -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 <percorso_cartella>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
folder_path = sys.argv[1]
|
||||||
|
process_folder(folder_path)
|
||||||
28
properties-to-csv.py
Normal file
28
properties-to-csv.py
Normal file
@@ -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)
|
||||||
|
|
||||||
Reference in New Issue
Block a user