Enhance the dummy configuration maker to be a little more workable
This commit is contained in:
parent
0ebaa81efb
commit
f0de6f3dbd
|
@ -5,6 +5,8 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import atexit
|
||||
|
||||
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
||||
os.pardir,
|
||||
|
@ -18,14 +20,48 @@ if os.path.exists(os.path.join(possible_topdir,
|
|||
from anvil.components.helpers.nova import ConfConfigurator
|
||||
from anvil.trace import TraceWriter
|
||||
|
||||
from anvil import utils
|
||||
from anvil import shell as sh
|
||||
|
||||
DUMMY_FILE = tempfile.mktemp()
|
||||
|
||||
|
||||
def at_exit_cleaner():
|
||||
sh.unlink(DUMMY_FILE)
|
||||
|
||||
atexit.register(at_exit_cleaner)
|
||||
|
||||
|
||||
def make_fakey(all_opts, last='dummy'):
|
||||
src = {}
|
||||
tmp = src
|
||||
last_opt = all_opts[-1]
|
||||
for opt in all_opts[0:-1]:
|
||||
tmp[opt] = {}
|
||||
tmp = tmp[opt]
|
||||
tmp[last_opt] = last
|
||||
return src
|
||||
|
||||
|
||||
class DummyInstaller(object):
|
||||
def get_option(self, option, *options, **kwargs):
|
||||
if option == 'db':
|
||||
return {'host': 'localhost',
|
||||
src = {
|
||||
option: {
|
||||
'host': 'localhost',
|
||||
'port': 3306,
|
||||
'type': 'mysql',
|
||||
'user': 'root'}
|
||||
return "dummy"
|
||||
'user': 'root'
|
||||
},
|
||||
}
|
||||
elif option == 'ip':
|
||||
return utils.get_host_ip()
|
||||
elif utils.has_any(option, 'extra_flags', 'extra_opts', 'instances_path'):
|
||||
return ''
|
||||
else:
|
||||
# Make a fake dictionary hierachy
|
||||
src = make_fakey([option] + list(options))
|
||||
return utils.get_deep(src, [option] + list(options))
|
||||
|
||||
def get_bool_option(self, option, *options, **kwargs):
|
||||
return False
|
||||
|
@ -37,7 +73,9 @@ class DummyInstaller(object):
|
|||
return None
|
||||
|
||||
def __init__(self):
|
||||
self.tracewriter = TraceWriter("dummy-config-trace")
|
||||
self.tracewriter = TraceWriter(DUMMY_FILE)
|
||||
|
||||
|
||||
|
||||
d = DummyInstaller()
|
||||
c = ConfConfigurator(d)
|
||||
|
|
Loading…
Reference in New Issue