Update to class

This commit is contained in:
Dimitris Zlatanidis 2015-07-29 05:20:12 +03:00
parent f8f2de490e
commit 0a125a6e1f
3 changed files with 63 additions and 57 deletions

View file

@ -26,64 +26,70 @@ import os
import subprocess import subprocess
def graph_deps(deps_dict, image): class Graph(object):
"""Drawing dependencies diagram
"""
def __init__(self, image):
self.image = image
def dependencies(self, deps_dict):
"""Generate graph file with depenndencies map tree """Generate graph file with depenndencies map tree
""" """
try: try:
import pygraphviz as pgv import pygraphviz as pgv
except ImportError: except ImportError:
print("Require 'pygraphviz': Install with '$ slpkg -s sbo pygraphviz'") print("Require 'pygraphviz': Install with '$ slpkg -s sbo "
"pygraphviz'")
raise SystemExit() raise SystemExit()
if image != "ascii": if self.image != "ascii":
check_file(image) self.check_file()
try: try:
G = pgv.AGraph(deps_dict) G = pgv.AGraph(deps_dict)
G.layout(prog="fdp") G.layout(prog="fdp")
if image == "ascii": if self.image == "ascii":
G.write("{0}.dot".format(image)) G.write("{0}.dot".format(self.image))
graph_easy(image) self.graph_easy()
G.draw(image) G.draw(self.image)
except (IOError, KeyboardInterrupt): except (IOError, KeyboardInterrupt):
raise SystemExit() raise SystemExit()
if os.path.isfile(image): if os.path.isfile(self.image):
print("Graph image file '{0}' created".format(image)) print("Graph image file '{0}' created".format(self.image))
raise SystemExit() raise SystemExit()
def check_file(self):
def check_file(image):
"""Check for file format and type """Check for file format and type
""" """
file_format = ["bmp", "canon", "cmap", "cmapx", "cmapx_np", "dot", "eps", file_format = [
"fig", "gd", "gd2", "gif", "gtk", "gv", "ico", "imap", "bmp", "canon", "cmap", "cmapx", "cmapx_np", "dot",
"imap_np", "ismap", "jpe", "jpeg", "jpg", "pdf", "pic", "eps", "fig", "gd", "gd2", "gif", "gtk", "gv", "ico",
"plain", "plain-ext", "png", "pov", "ps", "ps2", "svg", "imap", "imap_np", "ismap", "jpe", "jpeg", "jpg", "pdf",
"svgz", "tif", "tiff", "tk", "vml", "vmlz", "vrml", "wbmp", "pic", "plain", "plain-ext", "png", "pov", "ps", "ps2",
"x11", "xdot", "xlib" "svg", "svgz", "tif", "tiff", "tk", "vml", "vmlz",
"vrml", "wbmp", "x11", "xdot", "xlib"
] ]
try: try:
if image.split(".")[1] not in file_format: if self.image.split(".")[1] not in file_format:
print("Format: {0} not recognized. Use one of: {1}".format( print("Format: {0} not recognized. Use one of: {1}".format(
image.split(".")[1], " ".join(file_format))) self.image.split(".")[1], " ".join(file_format)))
raise SystemExit() raise SystemExit()
except IndexError: except IndexError:
print("slpkg: error: Image file suffix missing") print("slpkg: error: Image file suffix missing")
raise SystemExit() raise SystemExit()
def graph_easy(self):
def graph_easy(image): """Draw ascii diagram. graph-easy perl module require
"""Draw ascii diagram. graph-easy perl modulr require
""" """
if not os.path.isfile("/usr/bin/graph-easy"): if not os.path.isfile("/usr/bin/graph-easy"):
print("Require 'graph-easy': Install with '$ slpkg -s sbo graph-easy'") print("Require 'graph-easy': Install with '$ slpkg -s sbo "
remove_dot(image) "graph-easy'")
self.remove_dot()
raise SystemExit() raise SystemExit()
subprocess.call("graph-easy {0}.dot".format(image), shell=True) subprocess.call("graph-easy {0}.dot".format(self.image), shell=True)
remove_dot(image) self.remove_dot()
raise SystemExit() raise SystemExit()
def remove_dot(self):
def remove_dot(image):
"""Remove .dot files """Remove .dot files
""" """
if os.path.isfile("{0}.dot".format(image)): if os.path.isfile("{0}.dot".format(self.image)):
os.remove("{0}.dot".format(image)) os.remove("{0}.dot".format(self.image))

View file

@ -24,7 +24,7 @@
from utils import Utils from utils import Utils
from messages import Msg from messages import Msg
from graph import graph_deps from graph import Graph
from splitting import split_package from splitting import split_package
from __metadata__ import MetaData as _meta_ from __metadata__ import MetaData as _meta_
@ -68,7 +68,7 @@ class DependenciesStatus(object):
""" """
self.data() self.data()
if self.image: if self.image:
graph_deps(self.dmap, self.image) Graph(self.image).dependencies(self.dmap)
grey = self.meta.color["GREY"] grey = self.meta.color["GREY"]
green = self.meta.color["GREEN"] green = self.meta.color["GREEN"]
yellow = self.meta.color["YELLOW"] yellow = self.meta.color["YELLOW"]

View file

@ -24,7 +24,7 @@
from utils import Utils from utils import Utils
from messages import Msg from messages import Msg
from graph import graph_deps from graph import Graph
from blacklist import BlackList from blacklist import BlackList
from __metadata__ import MetaData as _meta_ from __metadata__ import MetaData as _meta_
@ -136,7 +136,7 @@ class TrackingDeps(object):
"""Drawing image dependencies map """Drawing image dependencies map
""" """
image = self.flag.split("=")[1] image = self.flag.split("=")[1]
graph_deps(self.deps_dict, image) Graph(image).dependencies(self.deps_dict)
def check_used(self, pkg): def check_used(self, pkg):
"""Check if dependencies used """Check if dependencies used