-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpipeviz.py
More file actions
79 lines (68 loc) · 2.98 KB
/
pipeviz.py
File metadata and controls
79 lines (68 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from yum.plugins import PluginYumExit, TYPE_CORE, TYPE_INTERACTIVE
from yum import config
import json, socket, urllib2, urllib
requires_api_version = '2.3'
plugin_type = (TYPE_CORE, TYPE_INTERACTIVE)
#(name, epoch, version, release, arch)
#nevra = (transaction.name, transaction.epoch, transaction.version,transaction.release,transaction.arch)
def getfiles(name, pkgs):
for p in pkgs:
try:
if name == p.name:
return (p.version, p.filelist)
except:
print name, "failed", len(pkgs)
def config_hook(conduit):
# This is how the docs at http://yum.baseurl.org/wiki/WritingYumPlugins recommend setting configuration
# but it isn't working so I copied the technique from the other plugins.
# config.YumConf.pipevizurl = config.UrlOption(default="http://pipeserv:2309/", schemes=('http', 'https'))
global pipeviz_url
pipeviz_url = conduit.confString('main', 'pipeviz_url', default="http://pipeserv:2309/")
def posttrans_hook(conduit):
# import pdb; pdb.set_trace()
pkgs = conduit.getPackages()
file_collections = []
hostname = socket.getfqdn()
libraries = list()
with open("/tmp/conduit.json", "w") as f:
for transaction in conduit.getTsInfo():
file_collections.append(getfiles(transaction.name, pkgs))
for dep in transaction.depends_on:
file_collections.append(getfiles(dep.name, pkgs))
logic_states = {"logic-states":list()}
#do libraries first, disabled for now
# for version, filelist in file_collections:
# for file_name in filelist:
# if file_name.find(".so") != -1:
# state = {"type":"library",
# "id":
# {"version":version},
# "environment":
# {"address":
# {"hostname":hostname}
# },
# }
# libraries.append(file_name)
# state["path"] = file_name
# logic_states["logic-states"].append(state)
#then binaries
for version, filelist in file_collections:
for file_name in filelist:
if file_name.find("bin/") != -1:
state = {"type":"binary",
"id":
{"version":version},
"environment":
{"address":
{"hostname":hostname}
},
}
if libraries:
state["libraries"] = libraries
state["path"] = file_name
logic_states["logic-states"].append(state)
#Dump a copy into /tmp for debugging.
json.dump(logic_states, f, indent=2)
req = urllib2.Request(pipeviz_url, data=json.dumps(logic_states))
urllib2.urlopen(req)
# vim: set tabstop=4 shiftwidth=4 expandtab