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