mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 20:56:35 +00:00
decode-config.py: Fix @v
filename template (#4609)
- fix restore filename auto extension
This commit is contained in:
parent
280df942e9
commit
20a4b1bdc3
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
VER = '2.1.0013'
|
VER = '2.1.0014'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
decode-config.py - Backup/Restore Sonoff-Tasmota configuration data
|
decode-config.py - Backup/Restore Sonoff-Tasmota configuration data
|
||||||
@ -1178,14 +1178,7 @@ def MakeFilename(filename, filetype, configmapping):
|
|||||||
if device_hostname is None:
|
if device_hostname is None:
|
||||||
device_hostname = ''
|
device_hostname = ''
|
||||||
|
|
||||||
filename = filename.replace('@v', config_version)
|
|
||||||
filename = filename.replace('@f', config_friendlyname )
|
|
||||||
filename = filename.replace('@h', config_hostname )
|
|
||||||
filename = filename.replace('@H', device_hostname )
|
|
||||||
|
|
||||||
|
|
||||||
dirname = basename = ext = ''
|
dirname = basename = ext = ''
|
||||||
name = filename
|
|
||||||
|
|
||||||
# split file parts
|
# split file parts
|
||||||
dirname = os.path.normpath(os.path.dirname(filename))
|
dirname = os.path.normpath(os.path.dirname(filename))
|
||||||
@ -1217,6 +1210,11 @@ def MakeFilename(filename, filetype, configmapping):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
filename = filename.replace('@v', config_version)
|
||||||
|
filename = filename.replace('@f', config_friendlyname )
|
||||||
|
filename = filename.replace('@h', config_hostname )
|
||||||
|
filename = filename.replace('@H', device_hostname )
|
||||||
|
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
||||||
@ -2371,7 +2369,6 @@ def Backup(backupfile, backupfileformat, encode_cfg, decode_cfg, configmapping):
|
|||||||
config data mapppings
|
config data mapppings
|
||||||
"""
|
"""
|
||||||
|
|
||||||
backupfileformat = args.backupfileformat
|
|
||||||
name, ext = os.path.splitext(backupfile)
|
name, ext = os.path.splitext(backupfile)
|
||||||
if ext.lower() == '.'+FileType.BIN.lower():
|
if ext.lower() == '.'+FileType.BIN.lower():
|
||||||
backupfileformat = FileType.BIN
|
backupfileformat = FileType.BIN
|
||||||
@ -2434,12 +2431,14 @@ def Backup(backupfile, backupfileformat, encode_cfg, decode_cfg, configmapping):
|
|||||||
message("Backup successful from {} '{}' to file '{}' ({} format)".format(srctype, src, backup_filename, fileformat), typ=LogType.INFO)
|
message("Backup successful from {} '{}' to file '{}' ({} format)".format(srctype, src, backup_filename, fileformat), typ=LogType.INFO)
|
||||||
|
|
||||||
|
|
||||||
def Restore(restorefile, encode_cfg, decode_cfg, configmapping):
|
def Restore(restorefile, backupfileformat, encode_cfg, decode_cfg, configmapping):
|
||||||
"""
|
"""
|
||||||
Restore from file
|
Restore from file
|
||||||
|
|
||||||
@param encode_cfg:
|
@param encode_cfg:
|
||||||
binary config data (encrypted)
|
binary config data (encrypted)
|
||||||
|
@param backupfileformat:
|
||||||
|
Backup file format
|
||||||
@param decode_cfg:
|
@param decode_cfg:
|
||||||
binary config data (decrypted)
|
binary config data (decrypted)
|
||||||
@param configmapping:
|
@param configmapping:
|
||||||
@ -2448,7 +2447,14 @@ def Restore(restorefile, encode_cfg, decode_cfg, configmapping):
|
|||||||
|
|
||||||
new_encode_cfg = None
|
new_encode_cfg = None
|
||||||
|
|
||||||
restorefilename = MakeFilename(restorefile, None, configmapping)
|
restorefileformat = None
|
||||||
|
if backupfileformat.lower() == 'bin':
|
||||||
|
restorefileformat = FileType.BIN
|
||||||
|
elif backupfileformat.lower() == 'dmp':
|
||||||
|
restorefileformat = FileType.DMP
|
||||||
|
elif backupfileformat.lower() == 'json':
|
||||||
|
restorefileformat = FileType.JSON
|
||||||
|
restorefilename = MakeFilename(restorefile, restorefileformat, configmapping)
|
||||||
filetype = GetFileType(restorefilename)
|
filetype = GetFileType(restorefilename)
|
||||||
|
|
||||||
if filetype == FileType.DMP:
|
if filetype == FileType.DMP:
|
||||||
@ -2817,7 +2823,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# restore from file
|
# restore from file
|
||||||
if args.restorefile is not None:
|
if args.restorefile is not None:
|
||||||
Restore(args.restorefile, encode_cfg, decode_cfg, configmapping)
|
Restore(args.restorefile, args.backupfileformat, encode_cfg, decode_cfg, configmapping)
|
||||||
|
|
||||||
# json screen output
|
# json screen output
|
||||||
if (args.backupfile is None and args.restorefile is None) or args.output:
|
if (args.backupfile is None and args.restorefile is None) or args.output:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user