From 932d380faf409b85a96c929f42c8624bdfcec086 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 28 Jul 2015 07:06:17 +0300 Subject: [PATCH] Added drawing ascii diagrams --- README.rst | 44 +++++++++++++++++++++++++++++++++++++++----- requirements.txt | 16 ++++++++++++---- slpkg/arguments.py | 6 +++--- slpkg/graph.py | 26 +++++++++++++++++++++++++- 4 files changed, 79 insertions(+), 13 deletions(-) diff --git a/README.rst b/README.rst index 9d8874b9..a952d294 100644 --- a/README.rst +++ b/README.rst @@ -349,8 +349,8 @@ Command Line Tool Usage repository. health, --silent Health check installed packages. deps-status, --graph=[image] Print dependencies status used by - packages or drawing image map - dependencies. + packages or drawing dependencies + diagram. Optional arguments: -h, --help Print this help message and exit. @@ -385,7 +385,7 @@ Command Line Tool Usage --check-deps, --graph=[image] print package dependenies tree with highlight if packages is installed. Also check if dependencies used or - drawing image map dependencies. + drawing dependencies diagram. -p, --desc, [repository] [package], Print description of a package --color=[] directly from the repository and change color text. @@ -727,13 +727,47 @@ and also displays installed packages: +--5: werkzeug is dependency --> Flask - Drawing image map dependencies: + Drawing dependencies diagram: $ slpkg -t sbo flexget --graph=image.x11 .. image:: https://raw.githubusercontent.com/dslackw/images/master/slpkg/deps2.png :target: https://raw.githubusercontent.com/dslackw/images/master/slpkg/deps2.png + + or drawing dependencies ascii diagram: + +.. code-block:: bash + + $ slpkg -t sbo brasero --graph=ascii + + +---------------------------------+ + | | + | | + | +---------+ | + | | | | + | | | | + +----------------+----+----+ | | + | | | | | | + +--------------+ | +--------------------+ | +-----------------+ | + | jmespath | -+- | botocore | +- | python-dateutil | | + +--------------+ | +--------------------+ +-----------------+ | + | | | | | | | + | | | | | | | + | | | | | | | + +--------------+ | +----------+ | | +-----------------+ | + | pysetuptools | -+ | bcdoc | -+----+------ | six | -+ + +--------------+ +----------+ | | +-----------------+ + | | | | + | | | | + | | | | + | +----------+ | | + | | docutils | -+ | + | +----------+ | + | | + +-------------------------------------+ + + .. code-block:: bash $ slpkg -t sbo Flask --check-deps --graph=image.x11 @@ -793,7 +827,7 @@ Print dependencies status used by packages: Found 19 dependencies in 4 packages. - or use additional option "--graph=[image]" to drawing image map dependencies, like: + or use additional option "--graph=[image]" to drawing dependencies diagram, like: $ slpkg deps-status --graph=image.x11 diff --git a/requirements.txt b/requirements.txt index 5cdd6289..fa8d1045 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,17 @@ # Slackware Linux # Python 2.7+ # GNU wget -# aria2 [optional] -# curl [optional] # GNU coreutils - +# # [OPTIONAL] -# pygraphviz >= 1.3rc2 +# aria2 (alternative downloader) +# +# [OPTIONAL] +# curl (alternative downloader) +# +# [OPTIONAL] +# pygraphviz >= 1.3rc2 (drawing dependencies diagram) +# +# [OPTIONAL] +# perl 5 +# graph-easy >= 0.75 (drawing dependencies ascii diagram) diff --git a/slpkg/arguments.py b/slpkg/arguments.py index a5c70c8d..4516adbf 100644 --- a/slpkg/arguments.py +++ b/slpkg/arguments.py @@ -56,8 +56,8 @@ Commands: repository. health, --silent Health check installed packages. deps-status, --graph=[image] Print dependencies status used by - packages or drawing image map - dependencies. + packages or drawing dependencies + diagram. Optional arguments: -h, --help Print this help message and exit. @@ -92,7 +92,7 @@ Optional arguments: --check-deps, --graph=[image] print package dependenies tree with highlight if packages is installed. Also check if dependencies used or - drawing image map dependencies. + drawing dependencies digram. -p, --desc, [repository] [package], Print description of a package --color=[] directly from the repository and change color text. diff --git a/slpkg/graph.py b/slpkg/graph.py index aba03a8b..e132e8cd 100644 --- a/slpkg/graph.py +++ b/slpkg/graph.py @@ -23,6 +23,7 @@ import os +import subprocess def graph_deps(deps_dict, image): @@ -33,10 +34,14 @@ def graph_deps(deps_dict, image): except ImportError: print("Require 'pygraphviz': Install with '$ slpkg -s sbo pygraphviz'") raise SystemExit() - check_file(image) + if image != "ascii": + check_file(image) try: G = pgv.AGraph(deps_dict) G.layout(prog="fdp") + if image == "ascii": + G.write("{0}.dot".format(image)) + graph_easy(image) G.draw(image) except (IOError, KeyboardInterrupt): raise SystemExit() @@ -63,3 +68,22 @@ def check_file(image): except IndexError: print("slpkg: error: Image file suffix missing") raise SystemExit() + + +def graph_easy(image): + """Draw ascii diagram. graph-easy perl modulr require + """ + if not os.path.isfile("/usr/bin/graph-easy"): + print("Require 'graph-easy': Install with '$ slpkg -s sbo graph-easy'") + remove_dot(image) + raise SystemExit() + subprocess.call("graph-easy {0}.dot".format(image), shell=True) + remove_dot(image) + raise SystemExit() + + +def remove_dot(image): + """Remove .dot files + """ + if os.path.isfile("{0}.dot".format(image)): + os.remove("{0}.dot".format(image))