Commit e50d46ae authored by Tristan Gingold's avatar Tristan Gingold

action: use composition instead of inheritance.

parent 24b0d92c
......@@ -34,13 +34,14 @@ from hdlmake import new_dep_solver as dep_solver
from hdlmake.srcfile import SourceFileSet, VHDLFile, VerilogFile, SVFile
from hdlmake.module.module import Module, ModuleArgs
class Action(list):
class Action(object):
"""This is the base class providing the common Action methods"""
def __init__(self, options):
super(Action, self).__init__()
self.top_manifest = None
self.manifests = []
self.parseable_fileset = SourceFileSet()
self.privative_fileset = SourceFileSet()
self._deps_solved = False
......@@ -98,8 +99,8 @@ class Action(list):
"""Build file set with all the files listed in the complete pool"""
logging.debug("Begin build complete file set")
all_manifested_files = SourceFileSet()
for module in self:
all_manifested_files.add(module.files)
for manifest in self.manifests:
all_manifested_files.add(manifest.files)
logging.debug("End build complete file set")
return all_manifested_files
......@@ -154,7 +155,7 @@ class Action(list):
def _get_config_dict(self):
"""Get the combined hierarchical Manifest dictionary from the pool"""
config_dict = {}
for mod in self:
for mod in self.manifests:
manifest_dict_tmp = mod.manifest_dict
if not manifest_dict_tmp == None:
if 'fetchto' in manifest_dict_tmp:
......@@ -173,12 +174,12 @@ class Action(list):
if new_module.isfetched:
for mod in new_module.submodules():
self._add(mod)
self.append(new_module)
self.manifests.append(new_module)
return True
def __contains(self, module):
"""Check if the pool contains the given module by checking the URL"""
for mod in self:
for mod in self.manifests:
if mod.url == module.url:
return True
return False
......
......@@ -51,7 +51,7 @@ class ActionCore(Action):
def _check_all_fetched(self):
"""Check if every module in the pool is fetched"""
if not len([m for m in self if not m.isfetched]) == 0:
if not len([m for m in self.manifests if not m.isfetched]) == 0:
raise Exception(
"Fetching should be done before continuing.\n"
"The following modules remains unfetched:\n"
......@@ -91,7 +91,7 @@ class ActionCore(Action):
new_modules.extend(module.modules[m])
return new_modules
fetch_queue = [m for m in self]
fetch_queue = [m for m in self.manifests]
while len(fetch_queue) > 0:
cur_mod = fetch_queue.pop()
......@@ -113,12 +113,12 @@ class ActionCore(Action):
def fetch(self):
"""Fetch the missing required modules from their remote origin"""
logging.info("Fetching needed modules.")
for mod in self:
for mod in self.manifests:
if mod.isfetched and not mod.manifest_dict == None:
if 'fetch_pre_cmd' in mod.manifest_dict:
os.system(mod.manifest_dict.get("fetch_pre_cmd", ''))
self._fetch_all()
for mod in self:
for mod in self.manifests:
if mod.isfetched and not mod.manifest_dict == None:
if 'fetch_post_cmd' in mod.manifest_dict:
os.system(mod.manifest_dict.get("fetch_post_cmd", ''))
......@@ -127,7 +127,7 @@ class ActionCore(Action):
def clean(self):
"""Delete the local copy of the fetched modules"""
logging.info("Removing fetched modules..")
remove_list = [mod_aux for mod_aux in self
remove_list = [mod_aux for mod_aux in self.manifests
if mod_aux.source in ['git', 'gitsm', 'svn']
and mod_aux.isfetched]
remove_list.reverse() # we will remove modules in backward order
......@@ -142,7 +142,7 @@ class ActionCore(Action):
def list_files(self):
"""List the files added to the design across the pool hierarchy"""
unfetched_modules = [mod_aux for mod_aux in self
unfetched_modules = [mod_aux for mod_aux in self.manifests
if not mod_aux.isfetched]
for mod_aux in unfetched_modules:
logging.warning(
......@@ -179,7 +179,7 @@ class ActionCore(Action):
def list_modules(self):
"""List the modules that are contained by the pool"""
for mod_aux in self:
for mod_aux in self.manifests:
if not mod_aux.isfetched:
logging.warning("Module not fetched: %s", mod_aux.url)
self._print_comment("# MODULE UNFETCHED! -> %s" % mod_aux.url)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment