Commit 09a1ab5b authored by Tristan Gingold's avatar Tristan Gingold

Deplete fetch/__init__.py, remove fetch/constants.py

parent 9e378856
......@@ -31,8 +31,9 @@ import os.path
import hdlmake.fetch as fetch
import hdlmake.new_dep_solver as dep_solver
from hdlmake.util import path as path_mod
from hdlmake.fetch import Svn, Git, GitSM, Local
from hdlmake.fetch import SVN, GIT, GITSM, LOCAL
from hdlmake.fetch.svn import Svn
from hdlmake.fetch.git import Git, GitSM
from hdlmake.fetch.local import Local
from .action import Action
......@@ -75,13 +76,13 @@ class ActionCore(Action):
"""Fetch the given module from the remote origin"""
new_modules = []
logging.debug("Fetching module: %s", str(module))
if module.source is SVN:
if module.source == 'svn':
result = self.svn_backend.fetch(module)
elif module.source is GIT:
elif module.source == 'git':
result = self.git_backend.fetch(module)
elif module.source is GITSM:
elif module.source == 'gitsm':
result = self.gitsm_backend.fetch(module)
elif module.source is LOCAL:
elif module.source == 'local':
result = self.local_backend.fetch(module)
if result is False:
raise Exception("Unable to fetch module %s", str(module.url))
......@@ -129,7 +130,7 @@ class ActionCore(Action):
"""Delete the local copy of the fetched modules"""
logging.info("Removing fetched modules..")
remove_list = [mod_aux for mod_aux in self
if mod_aux.source in [fetch.GIT, fetch.GITSM, fetch.SVN]
if mod_aux.source in ['git', 'gitsm', 'svn']
and mod_aux.isfetched]
remove_list.reverse() # we will remove modules in backward order
if len(remove_list):
......@@ -180,34 +181,22 @@ class ActionCore(Action):
def list_modules(self):
"""List the modules that are contained by the pool"""
def _convert_to_source_name(source_code):
"""Private function that returns a string with the source type"""
if source_code == fetch.GIT:
return "git"
elif source_code == fetch.GITSM:
return "gitsm"
elif source_code == fetch.SVN:
return "svn"
elif source_code == fetch.LOCAL:
return "local"
for mod_aux in self:
if not mod_aux.isfetched:
logging.warning("Module not fetched: %s", mod_aux.url)
self._print_comment("# MODULE UNFETCHED! -> %s" % mod_aux.url)
else:
self._print_comment("# MODULE START -> %s" % mod_aux.url)
if mod_aux.source in [fetch.SVN, fetch.GIT, fetch.GITSM]:
if mod_aux.source in ['svn', 'git', 'gitsm']:
self._print_comment("# * URL: " + mod_aux.url)
if (mod_aux.source
in [fetch.SVN, fetch.GIT, fetch.GITSM, fetch.LOCAL]
in ['svn', 'git', 'gitsm', 'local']
and mod_aux.parent):
self._print_comment("# * The parent for this module is: %s"
% mod_aux.parent.url)
else:
self._print_comment("# * This is the root module")
print("%s\t%s" % (mod_aux.path,
_convert_to_source_name(mod_aux.source)))
print("%s\t%s" % (mod_aux.path, mod_aux.source))
if self.options.withfiles:
self._print_file_list(mod_aux.files)
self._print_comment("# MODULE END -> %s" % mod_aux.url)
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013 CERN
# Author: Pawel Szostek (pawel.szostek@cern.ch)
#
# This file is part of Hdlmake.
#
# Hdlmake is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hdlmake is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Hdlmake. If not, see <http://www.gnu.org/licenses/>.
"""This package provides stuff to handle local and remote repositories"""
from .constants import (GIT, GITSM, SVN, LOCAL)
from .git import Git, GitSM
from .svn import Svn
from .local import Local
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2015 CERN
# Author: Pawel Szostek (pawel.szostek@cern.ch)
#
# This file is part of Hdlmake.
#
# Hdlmake is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hdlmake is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Hdlmake. If not, see <http://www.gnu.org/licenses/>.
# Note that the order here is important. The constants must be
# defined first! If they are not, there will likely be an obscure error
# when doing the imports within the imports that come afterwards.
"""Module providing the constants required for the fetch process"""
GIT = 1
GITSM = 2
SVN = 3
LOCAL = 4
......@@ -3,7 +3,7 @@ from files to required submodules"""
from __future__ import absolute_import
import logging
from hdlmake import fetch
from hdlmake.fetch.git import Git
from hdlmake.util import path as path_mod
from .core import ModuleCore
import six
......@@ -17,14 +17,14 @@ class ModuleArgs(object):
def __init__(self):
self.parent = None
self.url = None
self.source = fetch.LOCAL
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 fetch.LOCAL
self.source = source or 'local'
self.fetchto = fetchto
......@@ -80,70 +80,71 @@ class ModuleContent(ModuleCore):
def _process_manifest_modules(self):
"""Process the submodules required by the HDLMake module"""
# Process required modules
if "modules" not in self.manifest_dict:
return
fetchto = self._get_fetchto()
if "modules" in self.manifest_dict:
if "local" in self.manifest_dict["modules"]:
local_paths = path_mod.flatten_list(
self.manifest_dict["modules"]["local"])
local_mods = []
for path in local_paths:
if path_mod.is_abs_path(path):
raise Exception("Found an absolute path (" + path +
") in a manifest(" + self.path + ")")
path = path_mod.rel2abs(path, self.path)
local_mods.append(self.pool.new_module(parent=self,
url=path,
source=fetch.LOCAL,
fetchto=fetchto))
self.local = local_mods
else:
self.local = []
if "svn" in self.manifest_dict["modules"]:
self.manifest_dict["modules"]["svn"] = path_mod.flatten_list(
self.manifest_dict["modules"]["svn"])
svn_mods = []
for url in self.manifest_dict["modules"]["svn"]:
svn_mods.append(self.pool.new_module(parent=self,
url=url,
source=fetch.SVN,
fetchto=fetchto))
self.svn = svn_mods
else:
self.svn = []
if "git" in self.manifest_dict["modules"]:
self.manifest_dict["modules"]["git"] = path_mod.flatten_list(
self.manifest_dict["modules"]["git"])
git_mods = []
for url in self.manifest_dict["modules"]["git"]:
git_mods.append(self.pool.new_module(parent=self,
url=url,
source=fetch.GIT,
fetchto=fetchto))
self.git = git_mods
else:
self.git = []
if "gitsm" in self.manifest_dict["modules"]:
self.manifest_dict["modules"]["gitsm"] = path_mod.flatten_list(
self.manifest_dict["modules"]["gitsm"])
gitsm_mods = []
for url in self.manifest_dict["modules"]["gitsm"]:
gitsm_mods.append(self.pool.new_module(parent=self,
url=url,
source=fetch.GITSM,
fetchto=fetchto))
self.gitsm = gitsm_mods
else:
self.gitsm = []
if "local" in self.manifest_dict["modules"]:
local_paths = path_mod.flatten_list(
self.manifest_dict["modules"]["local"])
local_mods = []
for path in local_paths:
if path_mod.is_abs_path(path):
raise Exception("Found an absolute path (" + path +
") in a manifest(" + self.path + ")")
path = path_mod.rel2abs(path, self.path)
local_mods.append(self.pool.new_module(parent=self,
url=path,
source='local',
fetchto=fetchto))
self.local = local_mods
else:
self.local = []
if "svn" in self.manifest_dict["modules"]:
self.manifest_dict["modules"]["svn"] = path_mod.flatten_list(
self.manifest_dict["modules"]["svn"])
svn_mods = []
for url in self.manifest_dict["modules"]["svn"]:
svn_mods.append(self.pool.new_module(parent=self,
url=url,
source='svn',
fetchto=fetchto))
self.svn = svn_mods
else:
self.svn = []
if "git" in self.manifest_dict["modules"]:
self.manifest_dict["modules"]["git"] = path_mod.flatten_list(
self.manifest_dict["modules"]["git"])
git_mods = []
for url in self.manifest_dict["modules"]["git"]:
git_mods.append(self.pool.new_module(parent=self,
url=url,
source='git',
fetchto=fetchto))
self.git = git_mods
else:
self.git = []
if "gitsm" in self.manifest_dict["modules"]:
self.manifest_dict["modules"]["gitsm"] = path_mod.flatten_list(
self.manifest_dict["modules"]["gitsm"])
gitsm_mods = []
for url in self.manifest_dict["modules"]["gitsm"]:
gitsm_mods.append(self.pool.new_module(parent=self,
url=url,
source='gitsm',
fetchto=fetchto))
self.gitsm = gitsm_mods
else:
self.gitsm = []
def process_git_submodules(self):
"""Get the submodules if found in the Manifest path"""
if not self.source == fetch.GITSM:
if not self.source == 'gitsm':
return
git_submodule_dict = fetch.Git.get_git_submodules(self)
git_toplevel = fetch.Git.get_git_toplevel(self)
git_submodule_dict = Git.get_git_submodules(self)
git_toplevel = Git.get_git_toplevel(self)
for submodule_key in git_submodule_dict.keys():
url = git_submodule_dict[submodule_key]["url"]
path = git_submodule_dict[submodule_key]["path"]
......@@ -152,7 +153,7 @@ class ModuleContent(ModuleCore):
self.git.append(self.pool.new_module(parent=self,
url=url,
fetchto=fetchto,
source=fetch.GIT))
source='git'))
def _process_manifest_makefiles(self):
"""Get the extra makefiles defined in the HDLMake module"""
......
......@@ -29,7 +29,7 @@ class ModuleConfig(object):
def basename(self):
"""Get the basename for the module"""
if self.source == fetch.SVN:
if self.source == 'svn':
return path_mod.svn_basename(self.url)
else:
return path_mod.url_basename(self.url)
......@@ -49,13 +49,11 @@ class ModuleConfig(object):
self.source = source
self.parent = parent
if self.source != fetch.LOCAL:
if self.source == fetch.SVN:
self.url, self.revision = \
path_mod.svn_parse(url)
if self.source != 'local':
if self.source == 'svn':
self.url, self.revision = path_mod.svn_parse(url)
else:
self.url, self.branch, self.revision = \
path_mod.url_parse(url)
self.url, self.branch, self.revision = path_mod.url_parse(url)
basename = self.basename()
path = path_mod.relpath(os.path.abspath(
os.path.join(fetchto, basename)))
......
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