Small code cleanups

This commit is contained in:
Joshua Harlow
2012-08-28 15:05:49 -07:00
parent 9f664f18cd
commit 6f66a9e899
4 changed files with 20 additions and 24 deletions

View File

@@ -569,17 +569,13 @@ class PythonRuntime(ProgramRuntime):
self.tracereader = tr.TraceReader(self.trace_files['start'])
def start(self):
# Anything to start?
am_started = 0
# Select how we are going to start it
run_type = self.get_option("run_type", default_value='anvil.runners.fork:ForkRunner')
starter_cls = importer.import_entry_point(run_type)
starter = starter_cls(self)
for i, app_info in enumerate(self.apps_to_start):
starter = importer.construct_entry_point(run_type, self)
for (i, app_info) in enumerate(self.apps_to_start):
self._start_app(app_info, run_type, starter)
am_started = i + 1
self._post_app_start(app_info)
return am_started
return i + 1
def _start_app(self, app_info, run_type, starter):
app_name = app_info["name"]
@@ -604,19 +600,15 @@ class PythonRuntime(ProgramRuntime):
investigator_created = {}
to_investigate = []
for (app_name, _trace_fn, run_type) in apps_started:
inv_cls = None
try:
inv_cls = importer.import_entry_point(run_type)
except RuntimeError as e:
LOG.warn("Could not load class %s which should be used to investigate %s: %s",
colorizer.quote(run_type), colorizer.quote(app_name), e)
continue
investigator = None
if inv_cls in investigator_created:
investigator = investigator_created[inv_cls]
else:
investigator = inv_cls(self)
investigator_created[inv_cls] = investigator
investigator = investigator_created.get(run_type)
if investigator is None:
try:
investigator = importer.construct_entry_point(run_type, self)
investigator_created[run_type] = investigator
except RuntimeError as e:
LOG.warn("Could not load class %s which should be used to investigate %s: %s",
colorizer.quote(run_type), colorizer.quote(app_name), e)
continue
to_investigate.append((app_name, investigator))
return to_investigate

View File

@@ -26,8 +26,8 @@ class Initializer(object):
def __init__(self, service_token, admin_uri):
# Late load since its using a client lib that is only avail after install...
client_cls = importer.import_entry_point("keystoneclient.v2_0.client:Client")
self.client = client_cls(token=service_token, endpoint=admin_uri)
self.client = importer.construct_entry_point("keystoneclient.v2_0.client:Client",
token=service_token, endpoint=admin_uri)
def _create_tenants(self, tenants):
tenants_made = dict()

View File

@@ -22,6 +22,11 @@ from anvil import log as logging
LOG = logging.getLogger(__name__)
def construct_entry_point(fullname, *args, **kwargs):
cls = import_entry_point(fullname)
return cls(*args, **kwargs)
def partition(fullname):
"""
The name should be in dotted.path:ClassName syntax.

View File

@@ -17,8 +17,7 @@
import abc
import weakref
from anvil.components import (STATUS_INSTALLED, STATUS_STARTED,
STATUS_STOPPED, STATUS_UNKNOWN)
from anvil.components import STATUS_UNKNOWN
class Runner(object):