@@ -10,30 +10,30 @@ def read_config_from_json(json_file_path):
1010 new_signkey = data .get ("new_signkey" )
1111
1212 if not file_path or not old_signkey or not new_signkey :
13- raise ValueError ("JSON-Datei muss 'file_path', 'old_signkey' und 'new_signkey' enthalten ." )
13+ raise ValueError ("JSON file must contain 'file_path', 'old_signkey', and 'new_signkey'." )
1414
1515 return file_path , old_signkey , new_signkey
1616
1717 except FileNotFoundError :
18- print (f"Die JSON-Datei { json_file_path } wurde nicht gefunden ." )
18+ print (f"The JSON file { json_file_path } was not found ." )
1919 raise
2020 except json .JSONDecodeError :
21- print (f"Fehler beim Parsen der JSON-Datei { json_file_path } ." )
21+ print (f"Error parsing the JSON file { json_file_path } ." )
2222 raise
2323
2424def replace_signkey_in_file (file_path , old_signkey , new_signkey ):
2525 if len (old_signkey ) != len (new_signkey ):
26- raise ValueError ("Der neue Hex-String muss die gleiche Länge haben wie der alte Hex-String ." )
26+ raise ValueError ("The new signkey must be the same length as the old signkey ." )
2727
2828 if old_signkey .startswith ("0x" ):
2929 old_signkey = old_signkey [2 :]
3030 if new_signkey .startswith ("0x" ):
3131 new_signkey = new_signkey [2 :]
3232
3333 if not re .fullmatch (r'[0-9a-fA-F]+' , old_signkey ):
34- raise ValueError ("Der alte Hex-String ist nicht gültig ." )
34+ raise ValueError ("The old signkey is not valid ." )
3535 if not re .fullmatch (r'[0-9a-fA-F]+' , new_signkey ):
36- raise ValueError ("Der neue Hex-String ist nicht gültig ." )
36+ raise ValueError ("The new signkey is not valid ." )
3737
3838 try :
3939 with open (file_path , 'rb' ) as file :
@@ -42,22 +42,30 @@ def replace_signkey_in_file(file_path, old_signkey, new_signkey):
4242 old_signkey_bytes = bytes .fromhex (old_signkey )
4343 new_signkey_bytes = bytes .fromhex (new_signkey )
4444
45- content = content .replace (old_signkey_bytes , new_signkey_bytes )
45+ if old_signkey_bytes not in content :
46+ print (f"The old signkey '{ old_signkey } ' was not found in the file." )
47+ else :
48+ print (f"The old signkey '{ old_signkey } ' was found. Replacing..." )
4649
47- with open (file_path , 'wb' ) as file :
48- file .write (content )
49-
50- print ("Hex-String erfolgreich ersetzt." )
50+ content = content .replace (old_signkey_bytes , new_signkey_bytes )
51+
52+ with open (file_path , 'wb' ) as file :
53+ file .write (content )
54+
55+ if old_signkey_bytes in content :
56+ print ("Error: The old signkey is still present in the file." )
57+ else :
58+ print ("Signkey successfully replaced." )
5159
5260 except FileNotFoundError :
53- print (f"Die Datei { file_path } wurde nicht gefunden ." )
61+ print (f"The file ' { file_path } ' was not found ." )
5462 except Exception as e :
55- print (f"Ein Fehler ist aufgetreten : { e } " )
63+ print (f"An error occurred : { e } " )
5664
5765json_file_path = 'hex.json'
5866
5967try :
6068 file_path , old_signkey , new_signkey = read_config_from_json (json_file_path )
6169 replace_signkey_in_file (file_path , old_signkey , new_signkey )
6270except Exception as e :
63- print (f"Fehler : { e } " )
71+ print (f"Error : { e } " )
0 commit comments