31 righe
877 B
Python
Executable File
31 righe
877 B
Python
Executable File
#!/bin/python3
|
|
#
|
|
import re
|
|
import sys
|
|
|
|
try:
|
|
src_file = sys.argv[1]
|
|
dst_file = sys.argv[2]
|
|
except IndexError:
|
|
print(sys.argv[0], "<src> <dst>")
|
|
sys.exit(17)
|
|
|
|
try:
|
|
with open(src_file, 'r') as fh:
|
|
s = fh.read()
|
|
except (PermissionError, FileNotFoundError) as e:
|
|
print("Unable to open", '"' + src_file + '"')
|
|
sys.exit(18)
|
|
|
|
n = re.sub('^.*server: .*', ' server: mqtt://<mqtt_smarthome_hostname>', s, flags=re.MULTILINE)
|
|
n = re.sub('^.*user: .*', ' user: <mqtt_smarthome_username>', n, flags=re.MULTILINE)
|
|
n = re.sub('^.*password: .*', ' password: <mqtt_smarthome_password>', n, flags=re.MULTILINE)
|
|
n = re.sub('^.*auth_token: .*', ' auth_token: <zigbee_auth_token>', n, flags=re.MULTILINE)
|
|
|
|
try:
|
|
with open(dst_file, 'w') as fh:
|
|
fh.write(n)
|
|
except PermissionError:
|
|
print("Unable to write", '"' + dst_file + '"')
|
|
sys.exit(19)
|