mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-13 01:58:22 +00:00
Added script that checks configuration and may auto-fix it + added missing field in config.cfg.sample
This commit is contained in:
parent
3261eca836
commit
e225090e07
3 changed files with 84 additions and 1 deletions
|
@ -183,7 +183,7 @@ islogged=`screen -ls | awk '/\.Logging\t/ {print strtonum($1)}'`
|
||||||
isqueued=`screen -ls | awk '/\.Queue\t/ {print strtonum($1)}'`
|
isqueued=`screen -ls | awk '/\.Queue\t/ {print strtonum($1)}'`
|
||||||
isscripted=`screen -ls | awk '/\.Script\t/ {print strtonum($1)}'`
|
isscripted=`screen -ls | awk '/\.Script\t/ {print strtonum($1)}'`
|
||||||
|
|
||||||
options=("Redis" "LevelDB" "Logs" "Queues" "Scripts" "Killall" "Shutdown")
|
options=("Redis" "LevelDB" "Logs" "Queues" "Scripts" "Killall" "Shutdown" "Update-config")
|
||||||
|
|
||||||
menu() {
|
menu() {
|
||||||
echo "What do you want to Launch?:"
|
echo "What do you want to Launch?:"
|
||||||
|
@ -252,6 +252,9 @@ for i in ${!options[@]}; do
|
||||||
Shutdown)
|
Shutdown)
|
||||||
bash -c "./Shutdown.py"
|
bash -c "./Shutdown.py"
|
||||||
;;
|
;;
|
||||||
|
Update-config)
|
||||||
|
bash -c "./Update-conf.py"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
79
bin/Update-conf.py
Executable file
79
bin/Update-conf.py
Executable file
|
@ -0,0 +1,79 @@
|
||||||
|
#!/usr/bin/env python2
|
||||||
|
# -*-coding:UTF-8 -*
|
||||||
|
|
||||||
|
import ConfigParser
|
||||||
|
from ConfigParser import RawConfigParser
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
configfile = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg')
|
||||||
|
if not os.path.exists(configfile):
|
||||||
|
raise Exception('Unable to find the configuration file. \
|
||||||
|
Did you set environment variables? \
|
||||||
|
Or activate the virtualenv.')
|
||||||
|
configfileSample = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg.sample')
|
||||||
|
|
||||||
|
cfg = ConfigParser.ConfigParser()
|
||||||
|
cfg.read(configfile)
|
||||||
|
cfgSample = ConfigParser.ConfigParser()
|
||||||
|
cfgSample.read(configfileSample)
|
||||||
|
|
||||||
|
sections = RawConfigParser.sections(cfg)
|
||||||
|
sectionsSample = RawConfigParser.sections(cfgSample)
|
||||||
|
|
||||||
|
missingSection = []
|
||||||
|
dicoMissingSection = {}
|
||||||
|
missingItem = []
|
||||||
|
dicoMissingItem = {}
|
||||||
|
|
||||||
|
for sec in sectionsSample:
|
||||||
|
if sec not in sections:
|
||||||
|
missingSection += [sec]
|
||||||
|
dicoMissingSection[sec] = RawConfigParser.items(cfgSample, sec)
|
||||||
|
else:
|
||||||
|
setSample = set(RawConfigParser.options(cfgSample, sec))
|
||||||
|
setNormal = set(RawConfigParser.options(cfg, sec))
|
||||||
|
if setSample != setNormal:
|
||||||
|
missing_items = list(setSample.difference(setNormal))
|
||||||
|
missingItem += [sec]
|
||||||
|
list_items = []
|
||||||
|
for i in missing_items:
|
||||||
|
list_items.append( (i, cfgSample.get(sec, i)) )
|
||||||
|
dicoMissingItem[sec] = list_items
|
||||||
|
|
||||||
|
if len(missingSection) == 0 and len(missingItem) == 0:
|
||||||
|
print("Configuration up-to-date")
|
||||||
|
return
|
||||||
|
print("/!\\ Configuration not complete. Missing following configuration: /!\\")
|
||||||
|
print("+--------------------------------------------------------------------+")
|
||||||
|
for section in missingSection:
|
||||||
|
print("["+section+"]")
|
||||||
|
for item in dicoMissingSection[section]:
|
||||||
|
print(" - "+item[0])
|
||||||
|
for section in missingItem:
|
||||||
|
print("["+section+"]")
|
||||||
|
for item in dicoMissingItem[section]:
|
||||||
|
print(" - "+item[0])
|
||||||
|
print("+--------------------------------------------------------------------+")
|
||||||
|
resp = raw_input("Do you want to auto fix it? [y/n] ")
|
||||||
|
|
||||||
|
if resp != 'y':
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
for section in missingSection:
|
||||||
|
cfg.add_section(section)
|
||||||
|
for item, value in dicoMissingSection[section]:
|
||||||
|
cfg.set(section, item, value)
|
||||||
|
for section in missingItem:
|
||||||
|
for item, value in dicoMissingItem[section]:
|
||||||
|
cfg.set(section, item, value)
|
||||||
|
|
||||||
|
with open(configfile, 'w') as f:
|
||||||
|
cfg.write(f)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
@ -123,6 +123,7 @@ cc_tld = r'\.de$'
|
||||||
[Indexer]
|
[Indexer]
|
||||||
type = whoosh
|
type = whoosh
|
||||||
path = indexdir
|
path = indexdir
|
||||||
|
register = indexdir/all_index.txt
|
||||||
#size in Mb
|
#size in Mb
|
||||||
index_max_size = 2000
|
index_max_size = 2000
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue