Enhance the dummy configuration maker to be a little more workable
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import atexit
|
||||||
|
|
||||||
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
||||||
os.pardir,
|
os.pardir,
|
||||||
@@ -15,17 +17,51 @@ if os.path.exists(os.path.join(possible_topdir,
|
|||||||
'__init__.py')):
|
'__init__.py')):
|
||||||
sys.path.insert(0, possible_topdir)
|
sys.path.insert(0, possible_topdir)
|
||||||
|
|
||||||
from anvil.components.helpers.nova import ConfConfigurator
|
from anvil.components.helpers.nova import ConfConfigurator
|
||||||
from anvil.trace import TraceWriter
|
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):
|
class DummyInstaller(object):
|
||||||
def get_option(self, option, *options, **kwargs):
|
def get_option(self, option, *options, **kwargs):
|
||||||
if option == 'db':
|
if option == 'db':
|
||||||
return {'host': 'localhost',
|
src = {
|
||||||
|
option: {
|
||||||
|
'host': 'localhost',
|
||||||
'port': 3306,
|
'port': 3306,
|
||||||
'type': 'mysql',
|
'type': 'mysql',
|
||||||
'user': 'root'}
|
'user': 'root'
|
||||||
return "dummy"
|
},
|
||||||
|
}
|
||||||
|
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):
|
def get_bool_option(self, option, *options, **kwargs):
|
||||||
return False
|
return False
|
||||||
@@ -37,7 +73,9 @@ class DummyInstaller(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.tracewriter = TraceWriter("dummy-config-trace")
|
self.tracewriter = TraceWriter(DUMMY_FILE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
d = DummyInstaller()
|
d = DummyInstaller()
|
||||||
c = ConfConfigurator(d)
|
c = ConfConfigurator(d)
|
||||||
|
Reference in New Issue
Block a user