Suggest ansicolors, progress when missing (#3367)
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 4 Mar 2013 16:55:50 +0000 (18:55 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 4 Mar 2013 17:05:39 +0000 (19:05 +0200)
docs/installation.rst
kamaki/cli/__init__.py
kamaki/cli/utils.py

index 81fb712..1b7a075 100644 (file)
@@ -65,14 +65,6 @@ The following steps describe a command-line approach, but any graphic package ma
 
         $ sudo apt-get install kamaki
 
-Install ansicolors and/or progress (Optional but recommended)
-"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
-
-.. code-block:: console
-
-    $ sudo apt-get install python-ansicolors
-    $ sudo apt-get install python-progress
-
 .. _installing-from-source-ref:
 
 Installing from source (git repos.)
@@ -136,18 +128,41 @@ and then installed by the setup script:
     $ cd kamaki
     $ ./setup build install
 
-Install progress and/or ansicolors (optional)
-"""""""""""""""""""""""""""""""""""""""""""""
+Install ansicolors / progress
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Packages **ansicolors** and **progress** are not required for running kamaki, but
+they are recommended as a user experience improvement. In specific, ansicolors
+adds colors to kamaki responses and progress adds progressbars to the commands
+that can make use of it (*/store download*, */store upload*, */server wait* etc.)
 
-progress: command-line progress bars (in some commands)
+Debian and Ubuntu
+"""""""""""""""""
 
-ansicolors: color kamaki output (can switched on and off in `setup <setup.html>`_)
+Follow the `Debian <#debian>`_ or `Ubuntu <#ubuntu>`_ installation procedure described earlier
+and then type:
 
 .. code-block:: console
 
-    $ pip install progress
+    #For ansicolors
+    $ sudo apt-get install python-ansicolors
+
+    # For progress
+    $ sudo apt-get install python-progress
+
+From source
+"""""""""""
+
+If setuptools is not installed, `install them <http://pypi.python.org/pypi/setuptools>`_ and then type:
+
+.. code-block:: console
+
+    #For ansicolors
     $ pip install ansicolors
 
+    #For progress
+    $ pip install progress
+
 Mac OS X
 --------
 
index d832ce1..f1024d3 100644 (file)
@@ -390,6 +390,9 @@ def main():
 
         _init_session(parser.arguments)
 
+        from kamaki.cli.utils import suggest_missing
+        suggest_missing()
+
         if parser.unparsed:
             run_one_cmd(exe, parser)
         elif _help:
index f6e2b10..82fc726 100644 (file)
@@ -37,6 +37,16 @@ from time import sleep
 
 from kamaki.cli.errors import raiseCLIError
 
+suggest = dict(
+    ansicolors=dict(
+        active=False,
+        url='#install-ansicolors-progress',
+        description='Add colors to console responses'),
+    progress=dict(
+        active=False,
+        url='#install-ansicolors-progress',
+        description='Add progress bars to some commands'))
+
 try:
     from colors import magenta, red, yellow, bold
 except ImportError:
@@ -44,6 +54,24 @@ except ImportError:
     def dummy(val):
         return val
     red = yellow = magenta = bold = dummy
+    suggest['ansicolors']['active'] = True
+
+try:
+    from progress.bar import ShadyBar
+except ImportError:
+    suggest['progress']['active'] = True
+
+
+def suggest_missing(miss=None):
+    global suggest
+    kamaki_docs = 'http://www.synnefo.org/docs/kamaki/latest'
+    for k, v in (miss, suggest[miss]) if miss else suggest.items():
+        if v['active'] and stdout.isatty():
+            print('Suggestion: for better user experience install %s' % k)
+            print('\t%s' % v['description'])
+            print('\tIt is easy, here are the instructions:')
+            print('\t%s/installation.html%s' % (kamaki_docs, v['url']))
+            print('')
 
 
 def remove_colors():