From da968b88c3326d1eb0252ac3ba9a7bcf0752eab0 Mon Sep 17 00:00:00 2001
From: Dominika Hodovska <dhodovsk@redhat.com>
Date: Aug 02 2017 09:26:57 +0000
Subject: Add verbose option


---

diff --git a/modularity/cli.py b/modularity/cli.py
index bc749d8..db30a7f 100644
--- a/modularity/cli.py
+++ b/modularity/cli.py
@@ -1,5 +1,6 @@
 import sys
 import argparse
+import logging
 
 from modularity.module_generator import ModuleGenerator
 from modularity.oc_template import OpenShiftTemplateGenerator
@@ -12,10 +13,19 @@ class ModtoolsCLI(object):
     @staticmethod
     def build_parser():
         parser = argparse.ArgumentParser(description="Generates module related files")
+        base_parser = argparse.ArgumentParser(add_help=False)
+        base_parser.add_argument(
+            "--verbose",
+            "-v",
+            action="store_true",
+            help="verbose operation"
+        )
+
         subparsers = parser.add_subparsers(dest="cmd_name")
 
         parser_rpm2module = subparsers.add_parser(
-            'rpm2module', help="Generates modulemd file",
+            'rpm2module', parents=[base_parser],
+            help="Generates modulemd file",
             description="Gets package info and dependencies and creates modulemd file."
         )
         parser_rpm2module.add_argument(
@@ -26,7 +36,8 @@ class ModtoolsCLI(object):
         )
 
         parser_docker2openshift = subparsers.add_parser(
-            "docker2openshift", help="Generates openshift template from dockerfile",
+            "docker2openshift", parents=[base_parser],
+            help="Generates openshift template from dockerfile",
             description="Creates an OpenShift template YAML file.",
         )
 
@@ -41,7 +52,8 @@ class ModtoolsCLI(object):
         )
 
         parser_module2dockerfile = subparsers.add_parser(
-            'module2dockerfile', help="Generates dockerfile from modulemd file",
+            'module2dockerfile', parents=[base_parser],
+            help="Generates dockerfile from modulemd file",
             description="Creates Dockerfile with suggestions and pre-filled values"
         )
 
@@ -82,6 +94,8 @@ class ModtoolsCLIHelper(object):
     def run():
         try:
             cli = ModtoolsCLI(sys.argv[1:])
+            if cli.args.verbose:
+                logging.basicConfig(level=logging.INFO)
             if cli.args.cmd_name == 'rpm2module':
                 mg = ModuleGenerator(cli.args.pkgs)
                 mg.run()
diff --git a/modularity/module_deps_differ.py b/modularity/module_deps_differ.py
index ed396fd..4403b81 100755
--- a/modularity/module_deps_differ.py
+++ b/modularity/module_deps_differ.py
@@ -1,5 +1,5 @@
 import os
-import sys
+import logging
 
 import dnf
 
@@ -63,17 +63,20 @@ class ModuleDepsDiffer(object):
         return self.module_id_to_name.get(koji_tag_name, koji_tag_name)
 
     def obtain_module_names(self):
+        logging.info('Scanning built modules, this might take a while.')
         j = self.p['unreleasedvariants'](
             variant_type="module",
             active=True,
             page_size=-1
             # variant_version=STREAM,
         )
+        logging.info('Scanning built modules - DONE.')
         for module in j:
             self.module_id_to_name[module["koji_tag"]] = "{}:{}".format(module["variant_id"], module["variant_version"])
 
     @staticmethod
     def get_base_from_repo(reponame, repourl):
+        logging.info('Loading repo: %s', reponame)
         base = dnf.Base()
         if LooseVersion(dnf.__version__) < LooseVersion("2.0.0"):
             repo = dnf.repo.Repo(reponame, base.conf.cachedir)
@@ -97,9 +100,9 @@ class ModuleDepsDiffer(object):
 
         initialize repo objects for dnf to kick off queries
         """
-        print("Getting module information from mbs cache." +
-              " Please run mbs-build local with dependency modules" +
-              " you are interested in before running this script.")
+        logging.warn("Getting module information from mbs cache." +
+                     " Please run mbs-build local with dependency modules" +
+                     " you are interested in before running this script.")
         cache_path = os.path.expanduser("~/modulebuild/cache/koji_tags")
         for module_name in os.listdir(cache_path):
             # for now ignore all what is not in f26 stream, remove when situation changes
@@ -113,6 +116,7 @@ class ModuleDepsDiffer(object):
 
     def get_package_requires(self):
         # runtime
+        logging.info('Getting package requirements')
         pkgs = []
         base = ModuleDepsDiffer.get_base_from_repo('f26', REPO_F26)
         for pkg in self.packages:
@@ -169,6 +173,7 @@ class ModuleDepsDiffer(object):
         base = ModuleDepsDiffer.get_base_from_repo('f26', REPO_F26)
         q = base.sack.query()
         for cap in caps:
+            logging.info('Getting source package for %s:', cap)
             pkg = q.filter(provides__glob=[cap], arch=['noarch', ARCH], latest=True)
             if not pkg:
                 pkg = q.filter(file__glob=cap)
diff --git a/modularity/module_generator.py b/modularity/module_generator.py
index b0a86bb..c8932ce 100644
--- a/modularity/module_generator.py
+++ b/modularity/module_generator.py
@@ -3,7 +3,7 @@ from __future__ import absolute_import
 import modulemd
 import dnf
 from .module_deps_differ import ModuleDepsDiffer
-
+import logging
 
 class ModuleGenerator(object):
 
@@ -88,6 +88,7 @@ class ModuleGenerator(object):
             Function loads package from dnf
             :return:
             """
+        logging.info("Getting package info from DNF")
         b = dnf.Base()
         b.read_all_repos()
         b.fill_sack()
@@ -105,9 +106,11 @@ class ModuleGenerator(object):
             Function gets build and runtime dependencies of package
             :return:
             """
+        logging.info('Dependency resolution started')
         self.differ.run()
         self.build_deps = ModuleDepsDiffer.whatprovides(self.differ.build_caps_classified['result'])
         self.run_deps = ModuleDepsDiffer.whatprovides(self.differ.runtime_caps_classified['result'])
+        logging.info('Dependency resolution finished succesfully.')
 
     def run(self):
         if len(self.pkgs) == 1:

