cc-4227: updated install scripts for upgrade
This commit is contained in:
parent
abeef43a5b
commit
6c1e822b6a
|
@ -2,6 +2,7 @@ import os
|
|||
import shutil
|
||||
import sys
|
||||
from configobj import ConfigObj
|
||||
import upgrade2dot2
|
||||
|
||||
def get_current_script_dir():
|
||||
return os.path.dirname(os.path.realpath(__file__))
|
||||
|
@ -14,12 +15,14 @@ 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)
|
||||
|
||||
|
||||
upgrade2dot2.upgrade('%s/../api_client.cfg'% current_script_dir, PATH_INI_FILE)
|
||||
|
||||
"""load config file"""
|
||||
try:
|
||||
config = ConfigObj("%s/../api_client.cfg" % current_script_dir)
|
||||
|
|
|
@ -4,6 +4,7 @@ import sys
|
|||
import subprocess
|
||||
import random
|
||||
import string
|
||||
import upgrade2dot2
|
||||
from configobj import ConfigObj
|
||||
|
||||
if os.geteuid() != 0:
|
||||
|
@ -62,6 +63,9 @@ try:
|
|||
mm2_source = os.path.realpath(os.path.join(current_script_dir,
|
||||
"../../media-monitor2"))
|
||||
copy_dir(mm2_source, os.path.join( config["bin_dir"], "mm2" ))
|
||||
# upgrade mm2 config
|
||||
upgrade2dot2.upgrade(('%s/../media-monitor.cfg'%current_script_dir),
|
||||
PATH_INI_FILE)
|
||||
|
||||
#copy init.d script
|
||||
shutil.copy(config["bin_dir"]+"/airtime-media-monitor-init-d", "/etc/init.d/airtime-media-monitor")
|
||||
|
|
|
@ -38,7 +38,7 @@ class TestUpgrade(unittest.TestCase):
|
|||
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'] })
|
||||
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')
|
||||
|
|
|
@ -7,22 +7,21 @@ upgrades_config = {
|
|||
'/etc/airtime/api_client.cfg' : '../api_clients/api_client.cfg',
|
||||
}
|
||||
|
||||
def upgrade(upgrade_data):
|
||||
def upgrade(source, destination):
|
||||
"""
|
||||
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.iteritems():
|
||||
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.iteritems():
|
||||
if key not in cfg_dest: cfg_dest[key] = val
|
||||
cfg_dest.write()
|
||||
except Exception:
|
||||
print("Error upgrading")
|
||||
print( traceback.format_exc() )
|
||||
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() )
|
||||
|
||||
if __name__ == "__main__": upgrade(upgrades_config)
|
||||
|
|
Loading…
Reference in New Issue