From 5f596e9ce5d40e6644f8f58d41c26bf529de4739 Mon Sep 17 00:00:00 2001 From: "fabrizio.pappolla" Date: Tue, 13 Feb 2024 18:48:48 +0100 Subject: [PATCH] Ultimo commit da windows --- .idea/misc.xml | 2 +- .idea/pythonProject.iml | 7 +++++++ .idea/vcs.xml | 6 ++++++ main.py | 27 ++++++++++++++++++--------- 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 .idea/pythonProject.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 71dadd6..de138e4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/pythonProject.iml b/.idea/pythonProject.iml new file mode 100644 index 0000000..9fe066a --- /dev/null +++ b/.idea/pythonProject.iml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.py b/main.py index 4f96bbc..16d66f8 100644 --- a/main.py +++ b/main.py @@ -5,20 +5,24 @@ from datetime import datetime path = '/srv/tftp/' -header_cfg = """#!version:1.0.0.1 + +def now_formatted(): + now = datetime.now() + return now.strftime("%d/%m/%Y, %H:%M:%S") + + +header_cfg = f"""#!version:1.0.0.1 #Tasti rapidi del tastierino esterno #ATTENZIONE: NON MODIFICARE QUESTO FILE #Questo file viene generato automaticamente a partire dal file #tastierino_esterno.csv, modificare quest'ultimo ed attendere qualche minuto - +#file generato ultima volta il : {now_formatted()} account.1.sip_server.1.address = 192.168.1.7""" def append_log(text): with open("error.txt", "a") as f: - now = datetime.now() - now_formatted = now.strftime("%d/%m/%Y, %H:%M:%S") - log = " ".join([now_formatted, text]) + log = " ".join([now_formatted(), text + "/n"]) f.write(log) @@ -32,6 +36,7 @@ except NotADirectoryError: except PermissionError: append_log("You do not have permissions to change to {0}".format(path)) + def main(ofile): with open(ofile, newline='') as csvfile: spamreader = csv.reader(csvfile, delimiter=',', quotechar='"') @@ -43,22 +48,24 @@ def main(ofile): idx_ext = row.index('extension') idx_name = row.index('name') else: - if 'idx_ext' not in locals() or 'idx_name' not in locals(): + if 'idx_ext' not in locals() or 'idx_name' not in locals(): append_log("Errore: file csv senza i campi 'extension' e/o 'name'") try: ext_n = int(row[idx_ext]) - except: + except ValueError: continue ext_name = row[idx_name] to_write = "\n".join([to_write, print_ext(line_count, ext_n, ext_name)]) line_count += 1 - write_f(to_write,"tastierino_esterno.cfg") + write_f(to_write, "tastierino_esterno.cfg") -def write_f(text,file_name): + +def write_f(text, file_name): with open(file_name, "w") as file: file.write(text) + def print_ext(n, n_ext, lbl_ext): spamrow = f"""expansion_module.1.key.{n}.extension = expansion_module.1.key.{n}.label = {n_ext} @@ -66,9 +73,11 @@ expansion_module.1.key.{n}.type = 16 expansion_module.1.key.{n}.value = {lbl_ext}""" return spamrow + def print_hotkeys(): exit + if __name__ == '__main__': ofile: str = 'tastierino_esterno.csv' try: