-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtransaction-json.py
44 lines (33 loc) · 1.25 KB
/
transaction-json.py
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
from yum.plugins import PluginYumExit, TYPE_CORE, TYPE_INTERACTIVE
try:
import json
except ImportError:
import simplejson as json
requires_api_version = '2.5'
plugin_type = (TYPE_INTERACTIVE,)
def config_hook(conduit):
parser = conduit.getOptParser()
parser.add_option('', '--json', dest='json', action='store_true',
default=False,
help="show pending package changes as JSON")
def postresolve_hook(conduit):
opts, commands = conduit.getCmdLine()
if opts.json:
packages = {}
for transaction in conduit.getTsInfo():
if transaction.name not in packages:
packages[transaction.name] = {}
version = {
"version": transaction.version,
"release": transaction.release,
"epoch": transaction.epoch,
"arch": transaction.arch,
"state": transaction.ts_state,
"repo": getattr(transaction.po, 'repoid')
}
if transaction.ts_state:
packages[transaction.name]["pending"] = version
else:
packages[transaction.name]["current"] = version
print(json.dumps(packages))
raise PluginYumExit('')