From 364f3e777a7399ce9b2fc1fac307cd0c51450ecf Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 17 Aug 2012 16:40:41 -0400 Subject: [PATCH 1/2] cc-4227: added simple script to upgrade the config --- python_apps/media-monitor2/upgrade2.2.py | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 python_apps/media-monitor2/upgrade2.2.py diff --git a/python_apps/media-monitor2/upgrade2.2.py b/python_apps/media-monitor2/upgrade2.2.py new file mode 100644 index 000000000..9fadbfec7 --- /dev/null +++ b/python_apps/media-monitor2/upgrade2.2.py @@ -0,0 +1,48 @@ +import os +from configobj import ConfigObj +import traceback + +defaults = { + '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', +} + +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) From 37aa879ed02891bda9be69dbf82d8e485bcb78ff Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 17 Aug 2012 17:37:39 -0400 Subject: [PATCH 2/2] cc-4227: fix of bad fix regarding normalized data --- python_apps/media-monitor2/media/monitor/pure.py | 6 ++++-- python_apps/media-monitor2/upgrade2.2.py | 11 ----------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index 70136f730..2657ec2d7 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -270,8 +270,10 @@ def organized_path(old_path, root_path, orig_md): ext = extension(old_path) # The blocks for each if statement look awfully similar. Perhaps there is a # way to simplify this code - normal_md = default_to_f(orig_md, path_md, unicode_unknown, - lambda dictionary, key: len(dictionary[key]) == 0) + def default_f(dictionary, key): + if key in dictionary: return len(dictionary[key]) == 0 + else: return True + normal_md = default_to_f(orig_md, path_md, unicode_unknown, default_f) if is_airtime_recorded(normal_md): fname = u'%s-%s-%s.%s' % ( normal_md['MDATA_KEY_YEAR'], normal_md['MDATA_KEY_TITLE'], diff --git a/python_apps/media-monitor2/upgrade2.2.py b/python_apps/media-monitor2/upgrade2.2.py index 9fadbfec7..4c243be85 100644 --- a/python_apps/media-monitor2/upgrade2.2.py +++ b/python_apps/media-monitor2/upgrade2.2.py @@ -2,17 +2,6 @@ import os from configobj import ConfigObj import traceback -defaults = { - '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', -} - upgrades_config = { '/etc/airtime/media-monitor.cfg' : {