Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decode-config.py: Fix @v filename template (#4609) #4612

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions tools/decode-config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
VER = '2.1.0013'
VER = '2.1.0014'

"""
decode-config.py - Backup/Restore Sonoff-Tasmota configuration data
Expand Down Expand Up @@ -1178,14 +1178,7 @@ def MakeFilename(filename, filetype, configmapping):
if device_hostname is None:
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 = ''
name = filename

# split file parts
dirname = os.path.normpath(os.path.dirname(filename))
Expand Down Expand Up @@ -1217,6 +1210,11 @@ def MakeFilename(filename, filetype, configmapping):
except:
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


Expand Down Expand Up @@ -2371,7 +2369,6 @@ def Backup(backupfile, backupfileformat, encode_cfg, decode_cfg, configmapping):
config data mapppings
"""

backupfileformat = args.backupfileformat
name, ext = os.path.splitext(backupfile)
if ext.lower() == '.'+FileType.BIN.lower():
backupfileformat = FileType.BIN
Expand Down Expand Up @@ -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)


def Restore(restorefile, encode_cfg, decode_cfg, configmapping):
def Restore(restorefile, backupfileformat, encode_cfg, decode_cfg, configmapping):
"""
Restore from file

@param encode_cfg:
binary config data (encrypted)
@param backupfileformat:
Backup file format
@param decode_cfg:
binary config data (decrypted)
@param configmapping:
Expand All @@ -2448,7 +2447,14 @@ def Restore(restorefile, encode_cfg, decode_cfg, configmapping):

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)

if filetype == FileType.DMP:
Expand Down Expand Up @@ -2817,7 +2823,7 @@ def ParseArgs():

# restore from file
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
if (args.backupfile is None and args.restorefile is None) or args.output:
Expand Down