list_modules.py 2.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/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/>.

22
from __future__ import absolute_import
23

24 25
import logging

26 27 28 29 30 31
from hdlmake.util import path
import hdlmake.fetch as fetch

from .action import Action


32 33 34 35 36 37 38 39 40 41
def _convert_to_source_name(source_code):
    if source_code == fetch.GIT:
        return "git"
    elif source_code == fetch.SVN:
        return "svn"
    elif source_code == fetch.LOCAL:
        return "local"
    elif source_code == fetch.GITSUBMODULE:
        return "git_submodule"

42 43 44

class ListModules(Action):
    def run(self):
45 46
        for m in self.modules_pool:
            if not m.isfetched:
47
                logging.warning("Module not fetched: %s" % m.url)
48 49 50 51 52 53 54 55 56
                if not self.options.terse: print("# MODULE UNFETCHED! -> %s" % m.url)
            else:
                if not self.options.terse: print("# MODULE START -> %s" % m.url)
                if m.source in [fetch.SVN, fetch.GIT]:
                    if not self.options.terse: print("# * URL: "+m.url)
                elif m.source == fetch.GITSUBMODULE:
                    if not self.options.terse: print("# * This is a submodule of: %s" % m.parent.url)
                if m.source in [fetch.SVN, fetch.GIT, fetch.LOCAL] and m.parent:
                    if not self.options.terse: print("# * The parent for this module is: %s" % m.parent.url)
57
                else:
58 59 60
                    if not self.options.terse: print("# * This is the root module")
                print("%s\t%s" % (path.relpath(m.path), _convert_to_source_name(m.source)))
                if self.options.withfiles:
61
                    if not len(m.files):
62
                        if not self.options.terse: print("# * This module has no files")
63 64
                    else:
                        for f in m.files:
65 66 67
                            print("%s\t%s" % (path.relpath(f.path), "file"))
                if not self.options.terse: print("# MODULE END -> %s" % m.url)
            if not self.options.terse: print("")
68