Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
This commit is contained in:
commit
4f7c8bf0db
11 changed files with 377 additions and 41 deletions
|
@ -14,12 +14,12 @@ def copy_dir(src_dir, dest_dir):
|
|||
shutil.copytree(src_dir, dest_dir)
|
||||
|
||||
PATH_INI_FILE = '/etc/airtime/api_client.cfg'
|
||||
|
||||
|
||||
current_script_dir = get_current_script_dir()
|
||||
|
||||
if not os.path.exists(PATH_INI_FILE):
|
||||
shutil.copy('%s/../api_client.cfg'%current_script_dir, PATH_INI_FILE)
|
||||
|
||||
|
||||
"""load config file"""
|
||||
try:
|
||||
config = ConfigObj("%s/../api_client.cfg" % current_script_dir)
|
||||
|
|
|
@ -273,6 +273,8 @@ def organized_path(old_path, root_path, orig_md):
|
|||
def default_f(dictionary, key):
|
||||
if key in dictionary: return len(dictionary[key]) == 0
|
||||
else: return True
|
||||
# We set some metadata elements to a default "unknown" value because we use
|
||||
# these fields to create a path hence they cannot be empty
|
||||
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'],
|
||||
|
|
51
python_apps/media-monitor2/tests/test_upgrade2dot2.py
Normal file
51
python_apps/media-monitor2/tests/test_upgrade2dot2.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
from configobj import ConfigObj
|
||||
import unittest
|
||||
import os
|
||||
import upgrade2dot2
|
||||
|
||||
|
||||
def create_cfg(cfg):
|
||||
config = ConfigObj()
|
||||
config.filename = cfg['path']
|
||||
for k,v in cfg['data'].iteritems(): config[k] = v
|
||||
return config
|
||||
|
||||
class TestUpgrade(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.source = 'ttt1.cfg'
|
||||
self.dest = 'ttt2.cfg'
|
||||
|
||||
def test_upgrade(self):
|
||||
cf = {
|
||||
'source' : {
|
||||
'path' : self.source,
|
||||
'data' : {
|
||||
'key1' : 'val1',
|
||||
'key2' : 'val2',
|
||||
'key3' : 5,
|
||||
'key4' : 10,},
|
||||
},
|
||||
'dest' : {
|
||||
'path' : self.dest,
|
||||
'data' : {
|
||||
'key1' : 'NEW_VAL',
|
||||
'key3' : 25, }
|
||||
}
|
||||
}
|
||||
config1, config2 = create_cfg(cf['source']), create_cfg(cf['dest'])
|
||||
for c in [config1,config2]: c.write()
|
||||
self.assertTrue( os.path.exists(cf['source']['path']) )
|
||||
self.assertTrue( os.path.exists(cf['dest']['path']) )
|
||||
# Finished preparing
|
||||
upgrade2dot2.upgrade(cf['source']['path'], cf['dest']['path'] )
|
||||
c1, c2 = ConfigObj(cf['source']['path']), ConfigObj(cf['dest']['path'])
|
||||
self.assertEqual( c2['key2'], 'val2')
|
||||
self.assertEqual( c2['key4'], '10')
|
||||
self.assertEqual( c2['key3'], '25')
|
||||
|
||||
def tearDown(self):
|
||||
for clean in [ self.source, self.dest ]:
|
||||
os.unlink(clean)
|
||||
|
||||
if __name__ == '__main__': unittest.main()
|
|
@ -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)
|
20
python_apps/media-monitor2/upgrade2dot2.py
Normal file
20
python_apps/media-monitor2/upgrade2dot2.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import os
|
||||
from configobj import ConfigObj
|
||||
import traceback
|
||||
|
||||
def upgrade(source, destination):
|
||||
"""
|
||||
Must be ran as sudo. will do upgrade of configuration files by filling in
|
||||
missing values according to upgrade_data
|
||||
"""
|
||||
if not os.path.exists(source):
|
||||
print("Cannot upgrade '%s'. Skipping this file" % source)
|
||||
return
|
||||
try:
|
||||
cfg_source, cfg_dest = ConfigObj(source), ConfigObj(destination)
|
||||
for key, val in cfg_source.iteritems():
|
||||
if key not in cfg_dest: cfg_dest[key] = val
|
||||
cfg_dest.write()
|
||||
except Exception:
|
||||
print("Error upgrading")
|
||||
print( traceback.format_exc() )
|
Loading…
Add table
Add a link
Reference in a new issue