Commit 921fc7b5 authored by Tristan Gingold's avatar Tristan Gingold

module: refactoring.

parent 0d2c5746
......@@ -5,12 +5,12 @@ from __future__ import absolute_import
import logging
from hdlmake.fetch.git import Git
from hdlmake.util import path as path_mod
from .core import ModuleCore
from .core import ModuleConfig
import six
import os
class ModuleContent(ModuleCore):
class ModuleContent(ModuleConfig):
"""Class providing the HDLMake module content"""
......@@ -20,15 +20,32 @@ class ModuleContent(ModuleCore):
# Manifest Modules Properties
self.modules = {'local': [], 'git': [], 'gitsm': [], 'svn': []}
self.incl_makefiles = []
self.library = "work"
self.action = None
self.pool = None
self.top_manifest = None
self.manifest_dict = {}
super(ModuleContent, self).__init__()
def process_manifest(self):
"""Process the content section of the manifest_dic"""
super(ModuleContent, self).process_manifest()
self._process_manifest_universal()
self._process_manifest_files()
self._process_manifest_modules()
self._process_manifest_makefiles()
def _process_manifest_universal(self):
"""Method processing the universal manifest directives;
set library (inherited if not set) and action"""
# Libraries
if "library" in self.manifest_dict:
self.library = self.manifest_dict["library"]
elif self.parent:
self.library = self.parent.library
if "action" in self.manifest_dict:
self.action = self.manifest_dict["action"].lower()
def _process_manifest_files(self):
"""Process the files instantiated by the HDLMake module"""
from hdlmake.srcfile import SourceFileSet
......@@ -46,6 +63,10 @@ class ModuleContent(ModuleCore):
paths = self._make_list_of_paths(self.manifest_dict["files"])
self.files = self._create_file_list_from_paths(paths=paths)
def fetchto(self):
"""Get the fetchto folder for the module"""
return os.path.dirname(self.path)
def _get_fetchto(self):
"""Calculate the fetchto folder"""
if ("fetchto" in self.manifest_dict and
......
......@@ -40,21 +40,6 @@ class ModuleConfig(object):
self.path = None
self.isfetched = False
def process_manifest(self):
"""process_manifest does nothing for ModuleConfig"""
pass
def basename(self):
"""Get the basename for the module"""
if self.source == 'svn':
return path_mod.svn_basename(self.url)
else:
return path_mod.url_basename(self.url)
def fetchto(self):
"""Get the fetchto folder for the module"""
return os.path.dirname(self.path)
def init_config(self, module_args):
"""This initializes the module configuration.
The function is executed by Module constructor"""
......@@ -78,20 +63,19 @@ class ModuleConfig(object):
else:
if self.source == 'svn':
self.url, self.revision = path_mod.svn_parse(url)
basename = path_mod.svn_basename(self.url)
else:
self.url, self.branch, self.revision = path_mod.url_parse(url)
basename = self.basename()
path = path_mod.relpath(os.path.abspath(
basename = path_mod.url_basename(self.url)
self.path = path_mod.relpath(os.path.abspath(
os.path.join(fetchto, basename)))
# Check if the module dir exists and is not empty
if os.path.exists(path) and os.listdir(path):
self.path = path
if os.path.exists(self.path) and os.listdir(self.path):
self.isfetched = True
logging.debug("Module %s (parent: %s) is fetched.",
url, self.parent.path)
else:
self.path = path
self.isfetched = False
logging.debug("Module %s (parent: %s) is NOT fetched.",
url, self.parent.path)
......@@ -124,39 +108,3 @@ class ModuleConfig(object):
if self._check_filepath(filepath):
paths.append(path_mod.rel2abs(filepath, self.path))
return paths
class ModuleCore(ModuleConfig):
"""This is the class providing the module core functionality"""
def __init__(self):
# Universal Manifest Properties
self.library = "work"
self.action = None
self.pool = None
self.top_manifest = None
self.manifest_dict = {}
super(ModuleCore, self).__init__()
def set_pool(self, pool):
"""Set the associated pool for the module instance"""
self.pool = pool
self.top_manifest = pool.get_top_manifest()
def process_manifest(self):
"""Method that process the core manifest section"""
self._process_manifest_universal()
super(ModuleCore, self).process_manifest()
def _process_manifest_universal(self):
"""Method processing the universal manifest directives;
set library (inherited if not set) and action"""
# Libraries
if "library" in self.manifest_dict:
self.library = self.manifest_dict["library"]
elif self.parent:
self.library = self.parent.library
if "action" in self.manifest_dict:
self.action = self.manifest_dict["action"].lower()
......@@ -51,10 +51,11 @@ class Module(ModuleContent):
"""Calculate and initialize the origin attributes: path, source..."""
assert module_args.url is not None
assert module_args.source is not None
self.manifest_dict = {}
super(Module, self).__init__()
self.init_config(module_args)
self.set_pool(pool)
self.module_args = ModuleArgs()
self.pool = pool
self.top_manifest = pool.get_top_manifest()
self.module_args = module_args
def __str__(self):
......
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