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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#!/usr/bin/python
# vim: fileencoding=utf8 foldmethod=marker
#{{{ License header: GPLv2+
# This file is part of cnucnu.
#
# Cnucnu is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Cnucnu is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cnucnu. If not, see <http://www.gnu.org/licenses/>.
#}}}
import sys
import cmd
import readline
from cnucnu.package_list import Package, PackageList, Repository
from cnucnu.bugzilla_reporter import BugzillaReporter
class CheckShell(cmd.Cmd):
def __init__(self, config):
cmd.Cmd.__init__(self)
readline.set_completer_delims(' ')
self.repo = Repository()
self.package = Package("", None, None, self.repo)
self._package_list = None
self.prompt_default = " URL:"
self.update_prompt()
self.config = config
self._br = None
@property
def package_list(self):
if not self._package_list:
self._package_list = PackageList(repo=self.repo)
self._package_list.append(self.package)
return self._package_list
@property
def br(self):
if not self._br:
try:
bugzilla_config = self.config.bugzilla_config
self._br = BugzillaReporter(**bugzilla_config)
except:
print "Cannot query bugzilla, maybe config is faulty or missing"
return self._br
def update_prompt(self):
self.prompt = "%(name)s %(regex)s %(url)s " % self.package
self.prompt += "%s> " % self.prompt_default
def do_url(self, args):
self.package.url = args
def do_name(self, args):
self.package.name = args
if not self.package.regex:
self.package.regex = "DEFAULT"
if not self.package.url:
self.package.url = "SF-DEFAULT"
def do_fm(self, args):
self.package.name = args
self.package.regex = "FM-DEFAULT"
self.package.url = "FM-DEFAULT"
def do_report(self, args):
self.br.report_outdated(self.package, dry_run=False)
def do_inspect(self, args):
try:
self.package = self.package_list[args]
except KeyError, ke:
print ke
def complete_inspect(self, text, line, begidx, endidx):
package_names = [p.name for p in self.package_list if p.name.startswith(text)]
return package_names
def do_regex(self, args):
self.package.regex = args
def do_EOF(self, args):
self.emptyline()
def emptyline(self):
if self.package.url:
self.package.url = None
else:
print
sys.exit(0)
def default(self, args):
if not self.package.url:
self.do_url(args)
else:
self.do_regex(args)
def postcmd(self, stop, line):
if not self.package.url:
self.prompt_default = " URL:"
else:
self.prompt_default = " Regex:"
self.update_prompt()
if self.package.url and self.package.regex:
try:
print "Versions:", self.package.upstream_versions
print "Latest:", self.package.latest_upstream
if self.package.name:
if self.package.status:
status = " %s" % self.package.status
else:
status = ""
print "Repo Version: %s%s" % (self.package.repo_version, status)
if self.package.upstream_newer and self.br:
bugs = self.br.get_open(self.package)
if bugs:
for bug in bugs:
print "Open Bug:", "https://bugzilla.redhat.com/show_bug.cgi?id=%s %s:%s" % (bug.bug_id, bug.bug_status, bug.summary)
bugs = self.br.get_bug(self.package)
if bugs:
for bug in bugs:
print "Matching Bug:", "https://bugzilla.redhat.com/show_bug.cgi?id=%s %s:%s" % (bug.bug_id, bug.bug_status, bug.summary)
except Exception, e:
print e
return stop
|