1
1
#!/usr/bin/env python
2
2
# -*- coding: utf-8 -*-
3
- VER = '2.1.0013 '
3
+ VER = '2.1.0014 '
4
4
5
5
"""
6
6
decode-config.py - Backup/Restore Sonoff-Tasmota configuration data
@@ -1178,14 +1178,7 @@ def MakeFilename(filename, filetype, configmapping):
1178
1178
if device_hostname is None :
1179
1179
device_hostname = ''
1180
1180
1181
- filename = filename .replace ('@v' , config_version )
1182
- filename = filename .replace ('@f' , config_friendlyname )
1183
- filename = filename .replace ('@h' , config_hostname )
1184
- filename = filename .replace ('@H' , device_hostname )
1185
-
1186
-
1187
1181
dirname = basename = ext = ''
1188
- name = filename
1189
1182
1190
1183
# split file parts
1191
1184
dirname = os .path .normpath (os .path .dirname (filename ))
@@ -1217,6 +1210,11 @@ def MakeFilename(filename, filetype, configmapping):
1217
1210
except :
1218
1211
pass
1219
1212
1213
+ filename = filename .replace ('@v' , config_version )
1214
+ filename = filename .replace ('@f' , config_friendlyname )
1215
+ filename = filename .replace ('@h' , config_hostname )
1216
+ filename = filename .replace ('@H' , device_hostname )
1217
+
1220
1218
return filename
1221
1219
1222
1220
@@ -2371,7 +2369,6 @@ def Backup(backupfile, backupfileformat, encode_cfg, decode_cfg, configmapping):
2371
2369
config data mapppings
2372
2370
"""
2373
2371
2374
- backupfileformat = args .backupfileformat
2375
2372
name , ext = os .path .splitext (backupfile )
2376
2373
if ext .lower () == '.' + FileType .BIN .lower ():
2377
2374
backupfileformat = FileType .BIN
@@ -2434,12 +2431,14 @@ def Backup(backupfile, backupfileformat, encode_cfg, decode_cfg, configmapping):
2434
2431
message ("Backup successful from {} '{}' to file '{}' ({} format)" .format (srctype , src , backup_filename , fileformat ), typ = LogType .INFO )
2435
2432
2436
2433
2437
- def Restore (restorefile , encode_cfg , decode_cfg , configmapping ):
2434
+ def Restore (restorefile , backupfileformat , encode_cfg , decode_cfg , configmapping ):
2438
2435
"""
2439
2436
Restore from file
2440
2437
2441
2438
@param encode_cfg:
2442
2439
binary config data (encrypted)
2440
+ @param backupfileformat:
2441
+ Backup file format
2443
2442
@param decode_cfg:
2444
2443
binary config data (decrypted)
2445
2444
@param configmapping:
@@ -2448,7 +2447,14 @@ def Restore(restorefile, encode_cfg, decode_cfg, configmapping):
2448
2447
2449
2448
new_encode_cfg = None
2450
2449
2451
- restorefilename = MakeFilename (restorefile , None , configmapping )
2450
+ restorefileformat = None
2451
+ if backupfileformat .lower () == 'bin' :
2452
+ restorefileformat = FileType .BIN
2453
+ elif backupfileformat .lower () == 'dmp' :
2454
+ restorefileformat = FileType .DMP
2455
+ elif backupfileformat .lower () == 'json' :
2456
+ restorefileformat = FileType .JSON
2457
+ restorefilename = MakeFilename (restorefile , restorefileformat , configmapping )
2452
2458
filetype = GetFileType (restorefilename )
2453
2459
2454
2460
if filetype == FileType .DMP :
@@ -2817,7 +2823,7 @@ def ParseArgs():
2817
2823
2818
2824
# restore from file
2819
2825
if args .restorefile is not None :
2820
- Restore (args .restorefile , encode_cfg , decode_cfg , configmapping )
2826
+ Restore (args .restorefile , args . backupfileformat , encode_cfg , decode_cfg , configmapping )
2821
2827
2822
2828
# json screen output
2823
2829
if (args .backupfile is None and args .restorefile is None ) or args .output :
0 commit comments