Added drawing ascii diagrams

This commit is contained in:
Dimitris Zlatanidis 2015-07-28 07:06:17 +03:00
parent ecc1098d49
commit 932d380faf
4 changed files with 79 additions and 13 deletions

View file

@ -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

View file

@ -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)

View file

@ -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.

View file

@ -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()
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))