A more straighforward way of using the fetcher's backends

parent f1c0bc62
......@@ -34,6 +34,8 @@ import hdlmake.new_dep_solver as dep_solver
from hdlmake.util import path as path_mod
from hdlmake.srcfile import VerilogFile, VHDLFile, NGCFile
from hdlmake.vlog_parser import VerilogPreprocessor
from hdlmake.fetch import Svn, Git, Local
from hdlmake.fetch import SVN, GIT, LOCAL
from .action import Action
......@@ -43,6 +45,9 @@ class ActionCore(Action):
def __init__(self, *args):
super(ActionCore, self).__init__(*args)
self.git_backend = Git()
self.svn_backend = Svn()
self.local_backend = Local()
def _fetch_all(self):
"""Fetch all the modules declared in the design"""
......@@ -51,9 +56,12 @@ class ActionCore(Action):
"""Fetch the given module from the remote origin"""
new_modules = []
logging.debug("Fetching module: %s", str(module))
backend = fetch.FETCH_TYPE_LOOKUP.get_backend(module)
fetcher = backend()
result = fetcher.fetch(module)
if module.source is SVN:
result = self.svn_backend.fetch(module)
elif module.source is GIT:
result = self.git_backend.fetch(module)
elif module.source is LOCAL:
result = self.local_backend.fetch(module)
if result is False:
logging.error("Unable to fetch module %s", str(module.url))
sys.exit("Exiting")
......
......@@ -21,7 +21,7 @@
"""This package provides stuff to handle local and remote repositories"""
from .constants import (GIT, SVN, LOCAL, FETCH_TYPE_LOOKUP)
from .constants import (GIT, SVN, LOCAL)
from .git import Git
from .svn import Svn
from .backend_factory import BackendFactory
from .local import Local
#!/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/>.
"""Module providing the BackendFactory, a mechanism to create fetchers"""
from __future__ import absolute_import
import logging
from .constants import (LOCAL)
import six
class BackendFactory(object):
"""Class providing instances that can be used to build fetchers
for the required source origin (Local, Git, SVN)"""
def __init__(self):
self.backend_table = {}
def register_backend(self, backend_id, backend):
"""Add a mapping: backend_id -> backend"""
self.backend_table[backend_id] = backend
def get_backend(self, module):
"""Get the appropriated source origin backend for the given module"""
try:
if module.source != LOCAL:
logging.info("Investigating module: " + str(module) +
"[parent: " + str(module.parent) + "]")
backend = self.backend_table[module.source]
except KeyError:
error_string = "No registered backend found for module: " +\
str(module) + "\n" +\
"Registered backends are:\n"
for backend_id in six.iterkeys(self.backend_table):
error_string += "\t%d" % (backend_id)
logging.error(error_string)
raise
return backend
......@@ -28,17 +28,3 @@
GIT = 1
SVN = 2
LOCAL = 3
from .svn import Svn
from .git import Git
from .local import Local
from .backend_factory import BackendFactory
# Initialize an instance of BackendFactory which will be made publicly
# available
FETCH_TYPE_LOOKUP = BackendFactory()
FETCH_TYPE_LOOKUP.register_backend(GIT, Git)
FETCH_TYPE_LOOKUP.register_backend(SVN, Svn)
FETCH_TYPE_LOOKUP.register_backend(LOCAL, Local)
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