Commit 0d2c5746 authored by Tristan Gingold's avatar Tristan Gingold

Refactoring.

parent 4258554e
......@@ -47,6 +47,29 @@ class Action(object):
self._deps_solved = False
self.options = options
def _add(self, new_module):
"""Add the given new module if this is not already in the pool"""
assert isinstance(new_module, Module), "Expect a Module instance"
if self.__contains(new_module):
return
if new_module.isfetched:
for mod in new_module.submodules():
self._add(mod)
self.manifests.append(new_module)
def new_module(self, parent, url, source, fetchto):
"""Add new module to the pool.
This is the only way to add new modules to the pool
Thanks to it the pool can easily control its content
"""
self._deps_solved = False
args = ModuleArgs()
args.set_args(parent, url, source, fetchto)
new_module = Module(args, self)
self._add(new_module)
return new_module
def load_top_manifest(self):
# Top level module.
assert self.top_manifest is None
......@@ -82,20 +105,6 @@ class Action(object):
else:
raise Exception("Unknown requested action: {}".format(action))
def new_module(self, parent, url, source, fetchto):
"""Add new module to the pool.
This is the only way to add new modules to the pool
Thanks to it the pool can easily control its content
"""
self._deps_solved = False
new_module_args = ModuleArgs()
new_module_args.set_args(parent, url, source, fetchto)
new_module = Module(new_module_args, self)
if not self.__contains(new_module):
self._add(new_module)
return new_module
def build_complete_file_set(self):
"""Build file set with all the files listed in the complete pool"""
logging.debug("Begin build complete file set")
......@@ -158,7 +167,7 @@ class Action(object):
config_dict = {}
for mod in self.manifests:
manifest_dict_tmp = mod.manifest_dict
if not manifest_dict_tmp == None:
if manifest_dict_tmp is not None:
if 'fetchto' in manifest_dict_tmp:
manifest_dict_tmp['fetchto'] = os.path.relpath(os.path.join(
mod.path,
......@@ -167,17 +176,6 @@ class Action(object):
config_dict = manifest_dict_tmp
return config_dict
def _add(self, new_module):
"""Add the given new module if this is not already in the pool"""
assert isinstance(new_module, Module), "Expect a Module instance"
if self.__contains(new_module):
return False
if new_module.isfetched:
for mod in new_module.submodules():
self._add(mod)
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.manifests:
......
......@@ -246,7 +246,7 @@ types:[<type 'int'>]
return [o.name for o in self.options if o is not None]
def __parser_runner(self, content, extra_context):
"""method that acts as an 'exec' wraper to run the Python code"""
"""method that acts as an 'exec' wraper to run the Python code. Return the locals"""
options = {}
try:
with capture_stdout() as stdout_aux:
......@@ -283,7 +283,8 @@ types:[<type 'int'>]
return open(self.config_file, "r").read()
def parse(self, extra_context=None):
"""Parse the stored manifest plus arbitrary code"""
"""Parse the stored manifest plus arbitrary code. Return a dictionnary
of variables defined in the manifest."""
assert isinstance(extra_context, dict) or extra_context is None
# These HDLMake keys must not be inherited from parent module
......
......@@ -10,24 +10,6 @@ import six
import os
class ModuleArgs(object):
"""This class is just a container for the main Module args"""
def __init__(self):
self.parent = None
self.url = None
self.source = 'local'
self.fetchto = None
def set_args(self, parent, url, source, fetchto):
"""Set the module arguments"""
self.parent = parent
self.url = url
self.source = source or 'local'
self.fetchto = fetchto
class ModuleContent(ModuleCore):
"""Class providing the HDLMake module content"""
......
......@@ -9,6 +9,23 @@ from hdlmake import fetch
from hdlmake.util import path as path_mod
class ModuleArgs(object):
"""This class is just a container for the main Module args"""
def __init__(self):
self.parent = None
self.url = None
self.source = 'local'
self.fetchto = None
def set_args(self, parent, url, source, fetchto):
"""Set the module arguments"""
self.parent = parent
self.url = url
self.source = source or 'local'
self.fetchto = fetchto
class ModuleConfig(object):
"""This class containt the base properties and methods that
......@@ -49,7 +66,16 @@ class ModuleConfig(object):
self.source = source
self.parent = parent
if self.source != 'local':
if self.source == 'local':
self.url, self.branch, self.revision = url, None, None
if not os.path.exists(url):
raise Exception(
"Path to the local module doesn't exist:\n" + url
+ "\nThis module was instantiated in: " + str(self.parent))
self.path = path_mod.relpath(url)
self.isfetched = True
else:
if self.source == 'svn':
self.url, self.revision = path_mod.svn_parse(url)
else:
......@@ -69,15 +95,6 @@ class ModuleConfig(object):
self.isfetched = False
logging.debug("Module %s (parent: %s) is NOT fetched.",
url, self.parent.path)
else:
self.url, self.branch, self.revision = url, None, None
if not os.path.exists(url):
raise Exception(
"Path to the local module doesn't exist:\n" + url
+ "\nThis module was instantiated in: " + str(self.parent))
self.path = path_mod.relpath(url)
self.isfetched = True
def _check_filepath(self, filepath):
"""Check the provided filepath against several conditions"""
......@@ -119,7 +136,7 @@ class ModuleCore(ModuleConfig):
self.action = None
self.pool = None
self.top_manifest = None
self.manifest_dict = None
self.manifest_dict = {}
super(ModuleCore, self).__init__()
def set_pool(self, pool):
......
......@@ -35,7 +35,8 @@ import logging
from hdlmake.util import path as path_mod
from hdlmake.util import shell
from hdlmake.manifest_parser.variables import ManifestParser
from .content import ModuleContent, ModuleArgs
from .content import ModuleContent
from .core import ModuleArgs
import six
......
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