mirror of
https://github.com/rpm-software-management/tito.git
synced 2025-02-23 20:22:46 +00:00
Allow get_class_by_name to do all the importing itself
Signed-off-by: Devan Goodwin <dgoodwin@rm-rf.ca>
This commit is contained in:
parent
5640436684
commit
83aba138ec
1 changed files with 3 additions and 16 deletions
|
@ -50,24 +50,11 @@ def get_class_by_name(name):
|
|||
a Class object.
|
||||
"""
|
||||
name = normalize_class_name(name)
|
||||
# Split name into module and class name:
|
||||
tokens = name.split(".")
|
||||
class_name = tokens[-1]
|
||||
module = ""
|
||||
|
||||
for s in tokens[0:-1]:
|
||||
if module:
|
||||
module = module + "."
|
||||
module = module + s
|
||||
module, class_name = name.rsplit(".", 1)
|
||||
|
||||
mod = __import__(tokens[0])
|
||||
components = name.split('.')
|
||||
for comp in components[1:-1]:
|
||||
mod = getattr(mod, comp)
|
||||
|
||||
debug("Importing %s" % name)
|
||||
c = getattr(mod, class_name)
|
||||
return c
|
||||
mod = __import__(module, fromlist=[class_name])
|
||||
return getattr(mod, class_name)
|
||||
|
||||
|
||||
def read_user_config():
|
||||
|
|
Loading…
Add table
Reference in a new issue