Clean up some fetch related methods

parent 3915253c
...@@ -76,7 +76,8 @@ class Action(list): ...@@ -76,7 +76,8 @@ class Action(list):
def check_all_fetched_or_quit(self): def check_all_fetched_or_quit(self):
"""Check if every module in the pool is fetched""" """Check if every module in the pool is fetched"""
if not self.is_everything_fetched():
if not len([m for m in self if not m.isfetched]) == 0:
logging.error( logging.error(
"Fetching must be done before continuing.\n" "Fetching must be done before continuing.\n"
"The following modules remains unfetched:\n" "The following modules remains unfetched:\n"
...@@ -142,51 +143,6 @@ class Action(list): ...@@ -142,51 +143,6 @@ class Action(list):
return module return module
return None return None
def is_everything_fetched(self):
"""Check if every module is already fetched"""
if len([m for m in self if not m.isfetched]) == 0:
return True
else:
return False
def fetch_all(self):
"""Fetch all the modules declared in the design"""
def fetch_module(module):
"""Fetch the given module from the remote origin"""
new_modules = []
logging.debug("Fetching module: %s", str(module))
backend = fetch.FETCH_TYPE_LOOKUP.get_backend(module)
fetcher = backend()
result = fetcher.fetch(module)
if result is False:
logging.error("Unable to fetch module %s", str(module.url))
sys.exit("Exiting")
module.parse_manifest()
new_modules.extend(module.local)
new_modules.extend(module.svn)
new_modules.extend(module.git)
return new_modules
fetch_queue = [m for m in self]
while len(fetch_queue) > 0:
cur_mod = fetch_queue.pop()
new_modules = []
if cur_mod.isfetched:
new_modules = cur_mod.submodules()
else:
new_modules = fetch_module(cur_mod)
for mod in new_modules:
if not mod.isfetched:
logging.debug("Appended to fetch queue: "
+ str(mod.url))
self._add(mod)
fetch_queue.append(mod)
else:
logging.debug("NOT appended to fetch queue: "
+ str(mod.url))
def _add(self, new_module): def _add(self, new_module):
"""Add the given new module if this is not already in the pool""" """Add the given new module if this is not already in the pool"""
from hdlmake.module import Module from hdlmake.module import Module
......
...@@ -43,12 +43,50 @@ class ActionCore(Action): ...@@ -43,12 +43,50 @@ class ActionCore(Action):
def __init__(self, *args): def __init__(self, *args):
super(ActionCore, self).__init__(*args) super(ActionCore, self).__init__(*args)
def _fetch_all(self):
"""Fetch all the modules declared in the design"""
def _fetch_module(module):
"""Fetch the given module from the remote origin"""
new_modules = []
logging.debug("Fetching module: %s", str(module))
backend = fetch.FETCH_TYPE_LOOKUP.get_backend(module)
fetcher = backend()
result = fetcher.fetch(module)
if result is False:
logging.error("Unable to fetch module %s", str(module.url))
sys.exit("Exiting")
module.parse_manifest()
new_modules.extend(module.local)
new_modules.extend(module.svn)
new_modules.extend(module.git)
return new_modules
fetch_queue = [m for m in self]
while len(fetch_queue) > 0:
cur_mod = fetch_queue.pop()
new_modules = []
if cur_mod.isfetched:
new_modules = cur_mod.submodules()
else:
new_modules = _fetch_module(cur_mod)
for mod in new_modules:
if not mod.isfetched:
logging.debug("Appended to fetch queue: "
+ str(mod.url))
self._add(mod)
fetch_queue.append(mod)
else:
logging.debug("NOT appended to fetch queue: "
+ str(mod.url))
def fetch(self): def fetch(self):
"""Fetch the missing required modules from their remote origin""" """Fetch the missing required modules from their remote origin"""
top_module = self.get_top_module() top_module = self.get_top_module()
logging.info("Fetching needed modules.") logging.info("Fetching needed modules.")
os.system(top_module.manifest_dict["fetch_pre_cmd"]) os.system(top_module.manifest_dict["fetch_pre_cmd"])
self.fetch_all() self._fetch_all()
os.system(top_module.manifest_dict["fetch_post_cmd"]) os.system(top_module.manifest_dict["fetch_post_cmd"])
logging.info("All modules fetched.") logging.info("All modules fetched.")
......
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