forked from deanwilson/yum-transaction-json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction-json.py
32 lines (23 loc) · 1.09 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
from yum.plugins import PluginYumExit, TYPE_CORE, TYPE_INTERACTIVE
import simplejson
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( simplejson.dumps(packages) )
raise PluginYumExit('')