cc-4227: changed upgrade method. added test stubs for it
This commit is contained in:
parent
37aa879ed0
commit
b4c014dbcc
3 changed files with 33 additions and 37 deletions
28
python_apps/media-monitor2/upgrade2dot2.py
Normal file
28
python_apps/media-monitor2/upgrade2dot2.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import os
|
||||
from configobj import ConfigObj
|
||||
import traceback
|
||||
|
||||
upgrades_config = {
|
||||
'/etc/airtime/media-monitor.cfg' : '../media-monitor/media-monitor.cfg',
|
||||
'/etc/airtime/api_client.cfg' : '../api_clients/api_client.cfg',
|
||||
}
|
||||
|
||||
def upgrade(upgrade_data):
|
||||
"""
|
||||
Must be ran as sudo. will do upgrade of configuration files by filling in
|
||||
missing values according to upgrade_data
|
||||
"""
|
||||
for source, destination in upgrade_data:
|
||||
if not os.path.exists(source):
|
||||
print("Cannot upgrade '%s'. Skipping this file" % source)
|
||||
continue
|
||||
try:
|
||||
cfg_source, cfg_dest = ConfigObj(source), ConfigObj(destination)
|
||||
for key, val in cfg_source:
|
||||
if key not in cfg_dest: cfg_dest[key] = val
|
||||
cfg_dest.write()
|
||||
except Exception:
|
||||
print("Error upgrading")
|
||||
print( traceback.format_exc() )
|
||||
|
||||
if __name__ == "__main__": upgrade(upgrades_config)
|
Loading…
Add table
Add a link
Reference in a new issue