Partially improve the Module code: focus on Module.py

parent ff83acf6
......@@ -29,7 +29,7 @@ class ModuleContent(ModulePlugin):
except AttributeError:
pass
else:
self.manifest_dict["files"] = self._flatten_list(self.manifest_dict["files"])
self.manifest_dict["files"] = ModulePlugin.flatten_list(self.manifest_dict["files"])
logging.debug("Files in %s: %s" % (self.path, str(self.manifest_dict["files"])))
paths = self._make_list_of_paths(self.manifest_dict["files"])
self.files = self._create_file_list_from_paths(paths=paths)
......@@ -52,7 +52,7 @@ class ModuleContent(ModulePlugin):
# Process required modules
if "local" in self.manifest_dict["modules"]:
local_paths = self._flatten_list(self.manifest_dict["modules"]["local"])
local_paths = ModulePlugin.flatten_list(self.manifest_dict["modules"]["local"])
local_mods = []
for path in local_paths:
if path_mod.is_abs_path(path):
......@@ -69,7 +69,7 @@ class ModuleContent(ModulePlugin):
self.local = []
if "svn" in self.manifest_dict["modules"]:
self.manifest_dict["modules"]["svn"] = self._flatten_list(self.manifest_dict["modules"]["svn"])
self.manifest_dict["modules"]["svn"] = ModulePlugin.flatten_list(self.manifest_dict["modules"]["svn"])
svn_mods = []
for url in self.manifest_dict["modules"]["svn"]:
svn_mods.append(self.pool.new_module(parent=self,
......@@ -81,7 +81,7 @@ class ModuleContent(ModulePlugin):
self.svn = []
if "git" in self.manifest_dict["modules"]:
self.manifest_dict["modules"]["git"] = self._flatten_list(self.manifest_dict["modules"]["git"])
self.manifest_dict["modules"]["git"] = ModulePlugin.flatten_list(self.manifest_dict["modules"]["git"])
git_mods = []
for url in self.manifest_dict["modules"]["git"]:
git_mods.append(self.pool.new_module(parent=self,
......
import os
import logging
from .plugin import ModulePlugin
from hdlmake.util import path as path_mod
from hdlmake import fetch
class ModuleCore(ModulePlugin):
def __init__(self):
......@@ -33,3 +38,43 @@ class ModuleCore(ModulePlugin):
self.target = self.manifest_dict["target"].lower()
self.action = self.manifest_dict["action"].lower()
def _set_origin(self, parent, url, source, fetchto):
"""Calculate and initialize the origin attributes: path, source..."""
self.source = source
self.parent = parent
self.fetchto = fetchto
self.raw_url = url
if source != fetch.LOCAL:
self.url, self.branch, self.revision = path_mod.url_parse(url)
if (
os.path.exists(
os.path.abspath(
os.path.join(fetchto, self.basename)
)
) and
os.listdir(
os.path.abspath(os.path.join(fetchto, self.basename))
)
):
self.path = os.path.abspath(
os.path.join(fetchto, self.basename))
self.isfetched = True
logging.debug("Module %s (parent: %s) is fetched.",
url, parent.path)
else:
self.path = None
self.isfetched = False
logging.debug("Module %s (parent: %s) is NOT fetched.",
url, parent.path)
else:
self.url, self.branch, self.revision = url, None, None
if not os.path.exists(url):
logging.error(
"Path to the local module doesn't exist:\n" + url
+ "\nThis module was instantiated in: " + str(parent))
quit()
self.path = url
self.isfetched = True
This diff is collapsed.
......@@ -3,4 +3,14 @@ class ModulePlugin(object):
def process_manifest(self):
pass
@staticmethod
def flatten_list(sth):
"""Convert the argument in a list, being an empty list if none"""
if sth is not None:
if not isinstance(sth, (list, tuple)):
sth = [sth]
else:
sth = []
return sth
......@@ -40,7 +40,7 @@ class ModuleSimulation(ModulePlugin):
if len(self.manifest_dict["sim_only_files"]) == 0:
self.sim_only_files = SourceFileSet()
else:
self.manifest_dict["sim_only_files"] = self._flatten_list(self.manifest_dict["sim_only_files"])
self.manifest_dict["sim_only_files"] = ModulePlugin.flatten_list(self.manifest_dict["sim_only_files"])
paths = self._make_list_of_paths(self.manifest_dict["sim_only_files"])
self.sim_only_files = self._create_file_list_from_paths(paths=paths)
......
......@@ -97,8 +97,8 @@ class ModulePool(list):
new_module = Module(parent=parent,
url=url, source=source,
fetchto=fetchto,
pool=self)
fetchto=fetchto)
new_module.set_pool(self)
self._add(new_module)
if not self.top_module:
self.top_module = new_module
......
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