-#!/bin/env python
+#!/usr/bin/env python
import os
import sys
import readline
from StringIO import StringIO
from optparse import OptionParser
+
+from sfa.util.version import version_tag
from sfa.util.config import Config
def validator(validated_variables):
"SFA_AGGREGATE_HOST",
"SFA_SM_HOST",
"SFA_DB_HOST",
- "SFA_PLC_URL",
- "SFA_PLC_USER",
- "SFA_PLC_PASSWORD",
]
+flavour_xml_section_hash = { \
+ 'pl':'sfa_plc',
+ 'openstack':'sfa_nova',
+ 'fd':'sfa_federica',
+ 'nitos':'sfa_nitos',
+ 'dummy':'sfa_dummy',
+ }
configuration={ \
'name':'sfa',
'service':"sfa",
# GLOBAL VARIABLES
#
-release_id = "$Id$"
-release_rev = "$Revision$"
-release_url = "$URL$"
-
g_configuration=None
usual_variables=None
config_dir=None
else:
if cdef.validate_type(variable_type, answer):
cwrite.set(category_id, variable_id, answer)
+ return
else:
print "Not a valid value"
global service
while True:
try:
- answer = raw_input("Enter command (u for usual changes, w to save, ? for help) ").strip(" ")
+ answer = raw_input("Enter command (u for usual changes, w to save, ? for help) ").strip()
except EOFError:
answer =""
except KeyboardInterrupt:
(service,service))
elif command in "uU":
global usual_variables
+ global flavour_xml_section_hash
try:
for varname in usual_variables:
(category,variable) = cdef.locate_varname(varname)
if not (category is None and variable is None):
prompt_variable(cdef, cread, cwrite, category, variable, False)
+
+ # set the driver variable according to the already set flavour
+ generic_flavour = cwrite.items('sfa')[0][1]
+ for section in cdef.sections():
+ if generic_flavour in flavour_xml_section_hash and flavour_xml_section_hash[generic_flavour] == section:
+ for item in cdef.items(section):
+ category = section
+ variable = item[0]
+ prompt_variable(cdef, cread, cwrite, category, variable, False)
+ break
+
except Exception, inst:
if (str(inst) != 'BailOut'):
raise
####################
def optParserSetup(configuration):
- parser = OptionParser(usage=usage(), version="%prog " + release_rev + release_url )
+ parser = OptionParser(usage=usage(), version="%prog " + version_tag )
parser.set_defaults(config_dir=configuration['config_dir'],
service=configuration['service'],
usual_variables=configuration['usual_variables'])
# local settings only, will be modified & saved
config_filename = "%s/sfa_config" % config.config_dir
- try:
- cwrite=Config(config_filename)
- except ConfigParser.MissingSectionHeaderError:
- # remove legacy config
- os.unlink(config_filename)
- cwrite=Config(config_filename)
-
+ cwrite=Config(config_filename)
try:
cread.load(site_config)
+ cwrite.load(default_config)
cwrite.load(site_config)
except:
cwrite = Config()