-
Notifications
You must be signed in to change notification settings - Fork 4
/
yupdate-review
executable file
·105 lines (88 loc) · 2.82 KB
/
yupdate-review
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# Review the update log from yum in a VIM based, split window interactive UI.
# Shows RPM changelog, files, provides, requires.
# See yum_update_log.vim for the key bindings.
# Installation:
# 1. Put yum_update_log.vim in the same directory as this script
# or use the '--vim-script' option.
# 2. Setup 'sudo' privileges.
# usage: yupdate-review [ YUM.LOG ]
import sys
import os
import optparse
import tempfile
import subprocess
import errno
def program_name():
return os.path.basename(sys.argv[0])
main_function_map = {}
def main_function(func):
global main_function_map
main_function_map[func.__name__.replace('_','-')] = func
return func
def main_function_dispatch(name, args):
try:
f = main_function_map[name]
except KeyError:
sys.stderr.write('%s is not a valid command name\n' % (name,))
sys.exit(2)
f(args)
def print_usage_exit():
sys.stderr.write('usage: %s [YUM_or_DNF_LOG_FILE]\n' % (program_name(),))
sys.exit(2)
@main_function
def yupdate_review(args, sudo=True):
bin_dir = os.path.dirname(sys.argv[0])
op = optparse.OptionParser(option_list=[
optparse.Option('--vim-script', default=os.path.join(bin_dir, 'yum_update_log.vim')),
])
(options, args) = op.parse_args(args)
if len(args) == 0:
yum_log_filename = '/var/log/yum.log'
elif len(args) == 1:
yum_log_filename = args[0]
else:
print_usage_exit()
# TODO: don't run vim under sudo.
# Run 'yum_log_open()' in a privileged process and pass the fd back instead.
tf = tempfile.TemporaryFile(mode='w+')
cmd = ['wc', '-l', yum_log_filename]
if sudo:
cmd = ['sudo'] + cmd
subprocess.check_call(cmd, stdout=tf)
tf.seek(0)
l = int(tf.read().split()[0])
cmd = ['vim', '-R', '-S', options.vim_script, yum_log_filename, '+%d' % (l,)]
if sudo:
cmd = ['sudo'] + cmd
subprocess.check_call(cmd)
@main_function
def dupdate_review(args):
if len(args) == 0:
original_logfile = '/var/log/dnf.rpm.log'
elif len(args) == 1:
original_logfile = args[0]
else:
print_usage_exit()
try:
log_file = open(original_logfile)
except IOError as e:
if e.errno != errno.EACCES:
raise
subprocess.check_call(['sudo'] + sys.argv)
sys.exit(0)
tf = tempfile.NamedTemporaryFile(mode='w+')
# filter out lines like
# Sep 11 04:44:50 INFO Cleanup: gstreamer1-vaapi-0.5.8-3.fc20.x86_64
# Sep 11 05:19:14 INFO --- logging initialized ---
for i in log_file:
if 'INFO ---' in i:
continue
elif 'INFO Cleanup: ' in i:
continue
else:
tf.write(i)
tf.seek(0)
yupdate_review([tf.name], sudo=False)
if __name__ == '__main__':
main_function_dispatch(program_name(), sys.argv[1:])