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

Refactoring.

parent 4258554e
...@@ -47,6 +47,29 @@ class Action(object): ...@@ -47,6 +47,29 @@ class Action(object):
self._deps_solved = False self._deps_solved = False
self.options = options 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): def load_top_manifest(self):
# Top level module. # Top level module.
assert self.top_manifest is None assert self.top_manifest is None
...@@ -82,20 +105,6 @@ class Action(object): ...@@ -82,20 +105,6 @@ class Action(object):
else: else:
raise Exception("Unknown requested action: {}".format(action)) 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): def build_complete_file_set(self):
"""Build file set with all the files listed in the complete pool""" """Build file set with all the files listed in the complete pool"""
logging.debug("Begin build complete file set") logging.debug("Begin build complete file set")
...@@ -158,7 +167,7 @@ class Action(object): ...@@ -158,7 +167,7 @@ class Action(object):
config_dict = {} config_dict = {}
for mod in self.manifests: for mod in self.manifests:
manifest_dict_tmp = mod.manifest_dict 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: if 'fetchto' in manifest_dict_tmp:
manifest_dict_tmp['fetchto'] = os.path.relpath(os.path.join( manifest_dict_tmp['fetchto'] = os.path.relpath(os.path.join(
mod.path, mod.path,
...@@ -167,17 +176,6 @@ class Action(object): ...@@ -167,17 +176,6 @@ class Action(object):
config_dict = manifest_dict_tmp config_dict = manifest_dict_tmp
return config_dict 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): def __contains(self, module):
"""Check if the pool contains the given module by checking the URL""" """Check if the pool contains the given module by checking the URL"""
for mod in self.manifests: for mod in self.manifests:
......
...@@ -246,7 +246,7 @@ types:[<type 'int'>] ...@@ -246,7 +246,7 @@ types:[<type 'int'>]
return [o.name for o in self.options if o is not None] return [o.name for o in self.options if o is not None]
def __parser_runner(self, content, extra_context): 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 = {} options = {}
try: try:
with capture_stdout() as stdout_aux: with capture_stdout() as stdout_aux:
...@@ -283,7 +283,8 @@ types:[<type 'int'>] ...@@ -283,7 +283,8 @@ types:[<type 'int'>]
return open(self.config_file, "r").read() return open(self.config_file, "r").read()
def parse(self, extra_context=None): 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 assert isinstance(extra_context, dict) or extra_context is None
# These HDLMake keys must not be inherited from parent module # These HDLMake keys must not be inherited from parent module
......
...@@ -10,24 +10,6 @@ import six ...@@ -10,24 +10,6 @@ import six
import os 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 ModuleContent(ModuleCore):
"""Class providing the HDLMake module content""" """Class providing the HDLMake module content"""
......
...@@ -9,6 +9,23 @@ from hdlmake import fetch ...@@ -9,6 +9,23 @@ from hdlmake import fetch
from hdlmake.util import path as path_mod 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): class ModuleConfig(object):
"""This class containt the base properties and methods that """This class containt the base properties and methods that
...@@ -49,7 +66,16 @@ class ModuleConfig(object): ...@@ -49,7 +66,16 @@ class ModuleConfig(object):
self.source = source self.source = source
self.parent = parent 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': if self.source == 'svn':
self.url, self.revision = path_mod.svn_parse(url) self.url, self.revision = path_mod.svn_parse(url)
else: else:
...@@ -69,15 +95,6 @@ class ModuleConfig(object): ...@@ -69,15 +95,6 @@ class ModuleConfig(object):
self.isfetched = False self.isfetched = False
logging.debug("Module %s (parent: %s) is NOT fetched.", logging.debug("Module %s (parent: %s) is NOT fetched.",
url, self.parent.path) 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): def _check_filepath(self, filepath):
"""Check the provided filepath against several conditions""" """Check the provided filepath against several conditions"""
...@@ -119,7 +136,7 @@ class ModuleCore(ModuleConfig): ...@@ -119,7 +136,7 @@ class ModuleCore(ModuleConfig):
self.action = None self.action = None
self.pool = None self.pool = None
self.top_manifest = None self.top_manifest = None
self.manifest_dict = None self.manifest_dict = {}
super(ModuleCore, self).__init__() super(ModuleCore, self).__init__()
def set_pool(self, pool): def set_pool(self, pool):
......
...@@ -35,7 +35,8 @@ import logging ...@@ -35,7 +35,8 @@ import logging
from hdlmake.util import path as path_mod from hdlmake.util import path as path_mod
from hdlmake.util import shell from hdlmake.util import shell
from hdlmake.manifest_parser.variables import ManifestParser from hdlmake.manifest_parser.variables import ManifestParser
from .content import ModuleContent, ModuleArgs from .content import ModuleContent
from .core import ModuleArgs
import six 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