-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialization.py
52 lines (41 loc) · 1.46 KB
/
initialization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import tkinter as tk
from tkinter import filedialog
import re
from functools import partial
FILEPATH = ""
COPIED_FILEPATH = ""
def select_file(root):
global FILEPATH
file_path = filedialog.askopenfilename()
if file_path:
FILEPATH = file_path
root.destroy()
def close_window(root):
root.destroy()
def findDirectoryPath() -> str:
new_path=""
for i in range(len(re.split('/', FILEPATH))-1):
new_path+=re.split('/', FILEPATH)[i] + "/"
return new_path[:-1]
def copieFile(file_path : str):
source_file = file_path
destination_file =re.split(r'\.', file_path)[0] + r"_Copie." + re.split(r'\.', file_path)[1]
with open(source_file, 'rb') as src, open(destination_file, 'wb') as dest:
# Lire le contenu du fichier source et écrire dans le fichier de destination
dest.write(src.read())
return destination_file
#Now, we will create a copy of this file
def addCommandInOcli(cmd : str) :
with open(COPIED_FILEPATH, 'a') as file:
file.write('\n' + cmd + '\n')
def main():
root = tk.Tk()
root.update()
button = tk.Button(root, text="Open the OCLI file to work on", command=partial(select_file,root))
close_button = tk.Button(root, text="Exit", command=partial(close_window,root))
button.pack()
close_button.pack()
root.mainloop()
global COPIED_FILEPATH
COPIED_FILEPATH = copieFile(FILEPATH)
# addCommandInOcli(destination_file, "+bd:BATIMENT@[0,20]@d5d5fg5g")