From b4c014dbcc9440c30e74c6fe2761a8cfc7b35ec6 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 20 Aug 2012 11:19:57 -0400 Subject: [PATCH] cc-4227: changed upgrade method. added test stubs for it --- .../media-monitor2/tests/test_upgrade2dot2.py | 5 +++ python_apps/media-monitor2/upgrade2.2.py | 37 ------------------- python_apps/media-monitor2/upgrade2dot2.py | 28 ++++++++++++++ 3 files changed, 33 insertions(+), 37 deletions(-) create mode 100644 python_apps/media-monitor2/tests/test_upgrade2dot2.py delete mode 100644 python_apps/media-monitor2/upgrade2.2.py create mode 100644 python_apps/media-monitor2/upgrade2dot2.py diff --git a/python_apps/media-monitor2/tests/test_upgrade2dot2.py b/python_apps/media-monitor2/tests/test_upgrade2dot2.py new file mode 100644 index 000000000..bad930478 --- /dev/null +++ b/python_apps/media-monitor2/tests/test_upgrade2dot2.py @@ -0,0 +1,5 @@ +import unittest +import upgrade2dot2 + +class TestUpgrade(unittest.TestCase): + pass diff --git a/python_apps/media-monitor2/upgrade2.2.py b/python_apps/media-monitor2/upgrade2.2.py deleted file mode 100644 index 4c243be85..000000000 --- a/python_apps/media-monitor2/upgrade2.2.py +++ /dev/null @@ -1,37 +0,0 @@ -import os -from configobj import ConfigObj -import traceback - -upgrades_config = { - '/etc/airtime/media-monitor.cfg' : - { - 'check_filesystem_events' : 5, - 'check_airtime_events' : 30, - 'touch_interval' : 5, - 'chunking_number' : 450, - 'request_max_wait' : 3.0, - 'rmq_event_wait' : 0.1, - 'logpath' : '/var/log/airtime/media-monitor/media-monitor.log', - 'index_path' : '/var/tmp/airtime/media-monitor/last_index', - }, - '/etc/airtime/api_client.cfg' : - { - 'reload_metadata_group' : - 'reload-metadata-group/format/json/api_key/%%api_key%%', - } -} - -def upgrade(upgrade_data): - for f, values in upgrade_data: - if not os.path.exists(f): - print("Cannot upgrade '%s'. Skipping this file" % f) - continue - try: - cfg = ConfigObj(f) - for k,v in values: - if k not in cfg: cfg[k] = v - except Exception: - print("Error upgrading") - print( traceback.format_exc() ) - -if __name__ == "__main__": upgrade(upgrades_config) diff --git a/python_apps/media-monitor2/upgrade2dot2.py b/python_apps/media-monitor2/upgrade2dot2.py new file mode 100644 index 000000000..88d910d10 --- /dev/null +++ b/python_apps/media-monitor2/upgrade2dot2.py @@ -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)