18
18
19
19
20
20
class LanguageManager :
21
+ def __init__ (self ):
22
+ super (LanguageManager , self ).__init__ ()
23
+ self .language_name_global = ""
24
+ self .key_global = ""
25
+
21
26
def get_key (self , language_name , key ):
22
27
""" Get a key in a language package """
28
+ self .language_name_global = language_name
29
+ self .key_global = key
23
30
package_path = f"language_manager/packages/{ language_name } .langpkg"
24
- with open (package_path , "r" ) as file :
25
- with open (f"temp.py" , "w" ) as temp_file :
26
- # Log ONLY IF the "debug" value in the settings == True
27
- self .__log__ (f"--- Call to LanguageManager.get_key(self, { language_name } , { key } ) ---\n "
28
- f"Copying file { package_path } to LanguageManager root/temp.py\n " )
29
- # Copy the language package into the file temp.py in the root of LanguageManager
30
- temp_file .write (file .read ())
31
- self .__log__ ("done.\n " )
31
+ if not self .__copy_check_same__ (package_path ):
32
+ self .__copy__ (package_path )
32
33
33
34
# Import the temp Python file coming out of the package
34
35
import temp
@@ -55,3 +56,21 @@ def __log__(self, val):
55
56
log_file = open (lm_settings ["logfile" ], "w" )
56
57
log_file .write (val )
57
58
log_file .close ()
59
+
60
+ def __copy_check_same__ (self , file ):
61
+ with open (file , "r" ) as package :
62
+ with open ("temp.py" , "r" ) as file :
63
+ if package .read () == file .read ():
64
+ return True
65
+ return False
66
+
67
+ def __copy__ (self , package ):
68
+ with open (package , "r" ) as file :
69
+ with open (f"temp.py" , "w" ) as temp_file :
70
+ # Log ONLY IF the "debug" value in the settings == True
71
+ self .__log__ (f"--- Call to LanguageManager.get_key(self, { self .language_name_global } , "
72
+ f"{ self .key_global } ) ---\n Copying file { package } to LanguageManager "
73
+ f"root/temp.py\n " )
74
+ # Copy the language package into the file temp.py in the root of LanguageManager
75
+ temp_file .write (file .read ())
76
+ self .__log__ ("done.\n " )
0 commit comments