Skip to content

Commit

Permalink
Change settings in config on update
Browse files Browse the repository at this point in the history
Change settings in config on update
  • Loading branch information
BjoernSch committed Aug 15, 2018
1 parent 9ad0f2a commit 1b42a0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 1 addition & 4 deletions DEBIAN/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ fi
if [ -f /var/www/conf/WLANThermo.conf ]
then
echo Sichere alte Konfiguration
cp /var/www/conf/WLANThermo.conf /var/www/conf/WLANThermo.conf.old_
echo 'Patche alte Konfiguration ("pit_iterm_min")'
sudo sed -i.bak "s/pit_iterm_min = 35/pit_iterm_min = 0/g" /var/www/conf/WLANThermo.conf.old_
mv /var/www/conf/WLANThermo.conf.old_ /var/www/conf/WLANThermo.conf.old
cp /var/www/conf/WLANThermo.conf /var/www/conf/WLANThermo.conf.old
cp /var/www/conf/sensor.conf /var/www/conf/sensor.conf.old
else
echo Noch keine Konfiguration vorhanden!
Expand Down
13 changes: 12 additions & 1 deletion software/usr/bin/wlt_2_updateconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
import random
import string
import argparse
import re

setting_updates = {'Pitmaster':
{'pit_iterm_min':('^35$','0')},
}

def get_random_filename(filename):
return filename + '_' + ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(12))
Expand All @@ -38,7 +43,7 @@ def config_write(configfile, config, oldconfig):
new_ini.write(u'[{section_name}]\n'.format(section_name=section_name))
for (key, value) in config.items(section_name):
try:
new_ini.write(u'{key} = {value}\n'.format(key=key, value=oldconfig.get(section_name, key)))
new_ini.write(u'{key} = {value}\n'.format(key=key, value=update_settings(section_name, key, oldconfig.get(section_name, key))))
except (configparser.NoSectionError, configparser.NoOptionError):
new_ini.write(u'{key} = {value}\n'.format(key=key, value=value))
new_ini.write('\n')
Expand All @@ -47,6 +52,12 @@ def config_write(configfile, config, oldconfig):
new_ini.close()
os.rename(tmp_filename, configfile)

def update_settings(section_name, key, value):
if section_name in setting_updates:
if key in setting_updates[section_name]:
return re.sub(setting_updates[section_name][key][0], setting_updates[section_name][key][0][1], value)
return value

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Update current WLANThermo configuration from file')
parser.add_argument('oldconfigfile', metavar='filename', nargs='?',
Expand Down

0 comments on commit 1b42a0c

Please sign in to comment.