Commit 4dabda15 authored by Tristan Gingold's avatar Tristan Gingold

Refactoring.

parent 8a765caa
...@@ -228,10 +228,6 @@ types:[<type 'int'>] ...@@ -228,10 +228,6 @@ types:[<type 'int'>]
Note that this is only allowed when the option's value is a dict!!""" Note that this is only allowed when the option's value is a dict!!"""
self[name].add_key(key) self[name].add_key(key)
def add_config_file(self, config_file):
"""Add the Manifest to be processed by the parser"""
self.config_file = config_file
def add_prefix_code(self, code): def add_prefix_code(self, code):
"""Add the arbitrary Python to be executed just before the Manifest""" """Add the arbitrary Python to be executed just before the Manifest"""
self.prefix_code += code + '\n' self.prefix_code += code + '\n'
...@@ -282,11 +278,13 @@ types:[<type 'int'>] ...@@ -282,11 +278,13 @@ types:[<type 'int'>]
assert self.config_file is not None assert self.config_file is not None
return open(self.config_file, "r").read() return open(self.config_file, "r").read()
def parse(self, extra_context=None): def parse(self, config_file, extra_context=None):
"""Parse the stored manifest plus arbitrary code. Return a dictionnary """Parse the stored manifest plus arbitrary code. Return a dictionnary
of variables defined in the manifest.""" 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
self.config_file = config_file
# These HDLMake keys must not be inherited from parent module # These HDLMake keys must not be inherited from parent module
key_purge_list = ["modules", "files", "include_dirs", key_purge_list = ["modules", "files", "include_dirs",
"inc_makefiles", "library"] "inc_makefiles", "library"]
......
...@@ -267,32 +267,6 @@ class ManifestParser(ConfigParser): ...@@ -267,32 +267,6 @@ class ManifestParser(ConfigParser):
help=option["help"], help=option["help"],
type=option["type"]) type=option["type"])
def add_manifest(self, path):
"""Add to configuration the Manifest at directory (path) if exists"""
def _search_for_manifest(path):
"""
Look for manifest in the given folder and create a Manifest object
"""
logging.debug("Looking for manifest in " + path)
dir_files = os.listdir(path)
if "manifest.py" in dir_files and "Manifest.py" in dir_files:
raise Exception(
"Both manifest.py and Manifest.py" +
"found in the module directory: %s",
path)
for filename in dir_files:
if filename == "manifest.py" or filename == "Manifest.py":
if not os.path.isdir(filename):
logging.debug("Found manifest for module %s: %s",
path, filename)
return os.path.join(path, filename)
return None
manifest = _search_for_manifest(path)
if manifest is None:
raise Exception("No manifest found in path: {}".format(path))
logging.debug("Parse manifest in: %s", manifest)
self.add_config_file(manifest)
def print_help(self): def print_help(self):
"""Print the help for the Manifest parser object""" """Print the help for the Manifest parser object"""
self.help() self.help()
...@@ -73,6 +73,24 @@ class Module(ModuleContent): ...@@ -73,6 +73,24 @@ class Module(ModuleContent):
command_tmp = shell.rmdir_command() + " " + self.path command_tmp = shell.rmdir_command() + " " + self.path
shell.run(command_tmp) shell.run(command_tmp)
def _search_for_manifest(self):
"""Look for manifest in the given folder and create a Manifest object
"""
logging.debug("Looking for manifest in " + self.path)
dir_files = os.listdir(self.path)
if "manifest.py" in dir_files and "Manifest.py" in dir_files:
raise Exception(
"Both manifest.py and Manifest.py" +
"found in the module directory: %s",
self.path)
for filename in dir_files:
if filename == "manifest.py" or filename == "Manifest.py":
if not os.path.isdir(filename):
logging.debug("Found manifest for module %s: %s",
self.path, filename)
return os.path.join(self.path, filename)
raise Exception("No manifest found in path: {}".format(self.path))
def parse_manifest(self): def parse_manifest(self):
""" """
Create a dictionary from the module Manifest.py and assign it Create a dictionary from the module Manifest.py and assign it
...@@ -95,6 +113,9 @@ class Module(ModuleContent): ...@@ -95,6 +113,9 @@ class Module(ModuleContent):
return return
assert self.path is not None assert self.path is not None
filename = self._search_for_manifest()
logging.debug("Parse manifest in: %s", filename)
logging.debug(""" logging.debug("""
*********************************************************** ***********************************************************
PARSE START: %s PARSE START: %s
...@@ -105,9 +126,6 @@ PARSE START: %s ...@@ -105,9 +126,6 @@ PARSE START: %s
manifest_parser.add_prefix_code(self.pool.options.prefix_code) manifest_parser.add_prefix_code(self.pool.options.prefix_code)
manifest_parser.add_suffix_code(self.pool.options.suffix_code) manifest_parser.add_suffix_code(self.pool.options.suffix_code)
# Look for the Manifest.py file
manifest_parser.add_manifest(self.path)
# Parse and extract variables from it. # Parse and extract variables from it.
if self.parent is None: if self.parent is None:
extra_context = {} extra_context = {}
...@@ -118,7 +136,7 @@ PARSE START: %s ...@@ -118,7 +136,7 @@ PARSE START: %s
# The parse method is where most of the parser action takes place! # The parse method is where most of the parser action takes place!
opt_map = None opt_map = None
try: try:
opt_map = manifest_parser.parse(extra_context=extra_context) opt_map = manifest_parser.parse(config_file=filename, extra_context=extra_context)
except NameError as name_error: except NameError as name_error:
raise Exception( raise Exception(
"Error while parsing {0}:\n{1}: {2}.".format( "Error while parsing {0}:\n{1}: {2}.".format(
......
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