forked from davidhrbac/cnucnu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcnucnu.py
executable file
·151 lines (129 loc) · 6.24 KB
/
cnucnu.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/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 logging
import sys
import os
from cnucnu.config import global_config
from cnucnu.package_list import Repository, PackageList, Package
from cnucnu.checkshell import CheckShell
from cnucnu.bugzilla_reporter import BugzillaReporter
from cnucnu.scm import SCM
from cnucnu.errors import UpstreamVersionRetrievalError
import pprint as pprint_module
pp = pprint_module.PrettyPrinter(indent=4)
pprint = pp.pprint
if __name__ == '__main__':
from optparse import OptionParser
parser = OptionParser()
parser.add_option("", "--shell", dest="action", help="Interactive shell", action="store_const", const="shell")
parser.add_option("", "--config", dest="config_filename", help="config_filename, e.g. for bugzilla credentials")
parser.add_option("", "--create-bugs", dest="action", help="file bugs for outdated packages", action="store_const", const="create-bugs")
parser.add_option("", "--fm-outdated-all", dest="action", help="compare all packages in rawhide with freshmeat", action="store_const", const="fm-outdated-all")
parser.add_option("", "--dump-config", dest="action", help="dumps dconfig to stdout", action="store_const", const="dump-config")
parser.add_option("", "--dump-default-config", dest="action", help="dumps default config to stdout", action="store_const", const="dump-default-config")
parser.add_option("", "--dry-run", dest="dry_run", help="Do not file or change bugs", default=False, action="store_true")
parser.add_option("", "--debug", dest="debug", help="Show debug output", default=False, action="store_true")
parser.add_option("", "--start-with", dest="start_with", help="Start with this package when reporting bugs", metavar="PACKAGE", default="")
(options, args) = parser.parse_args()
if options.action == "dump-default-config":
sys.stdout.write(global_config.yaml)
sys.exit(0)
if options.debug:
logging.basicConfig(level=logging.DEBUG)
# default to ./cnucnu.yaml if it exists and no config file is specified on
# the commandline
yaml_file = options.config_filename
if not yaml_file:
new_yaml_file = "./cnucnu.yaml"
if os.access(new_yaml_file, os.R_OK):
yaml_file = new_yaml_file
if yaml_file:
global_config.update_yaml_file(yaml_file)
if options.action == "dump-config":
sys.stdout.write(global_config.yaml)
sys.exit(0)
if options.action == "shell":
shell = CheckShell(config=global_config)
while True:
if not shell.cmdloop():
break
elif options.action == "create-bugs":
br = BugzillaReporter(global_config.bugzilla_config)
repo = Repository(**global_config.config["repo"])
scm = SCM(**global_config.config["scm"])
outdated = []
current=0
exceptions = 0
outdated = 0
upstream = 0
nopackage = 0
v=False
pl = PackageList(repo=repo, scm=scm, br=br, **global_config.config["package list"])
packages=len(pl.packages)
#pl = PackageList(repo=repo, scm=scm, br=br, false)
for p in pl:
current+=1
tty_rows, tty_columns = map(int, os.popen('stty size', 'r').read().split())
if p.name >= options.start_with:
logging.info("testing: %s", p.name)
#print "testing:",p.name
#print "testing: %s" % p.name
sys.stdout.write('\r' + ' ' * tty_rows)
sys.stdout.write("\r%s/%d %s %s " % (current, packages, "*", p.name))
sys.stdout.flush()
try:
if p.upstream_newer:
sys.stdout.write('\r' + ' ' * tty_rows)
sys.stdout.write("\r%d/%d %s %s\n" % (current , packages, "*", str(p)))
sys.stdout.flush()
outdated+=1
#print "Name",p.name
pprint(p.report_outdated(dry_run=options.dry_run))
except UpstreamVersionRetrievalError:
print "Missing URL"
upstream+=1
except KeyError:
# print "URL"
nopackage+=1
except Exception, e:
# pprint(e)
# print "Exc"
exceptions+=1
if v:
pprint(e)
else:
logging.info("skipping: %s", p.name)
sys.stdout.write('\r')
sys.stdout.flush()
print "%s %s %s" % ('=' * 20, "Results", '=' * 20)
fmt = "%%-%ds %%6s (%%3d%%%%)" % (len("Unresolved")*3)
print(fmt % (" Total" , str(packages), 100))
print(fmt % (" Outdated" , str(outdated), 100*outdated/packages))
print(fmt % (" Unresolved", str(exceptions), 100*exceptions/packages))
print(fmt % (" Upstream URL", str(upstream), 100*upstream/packages))
print(fmt % (" Missing RPM", str(nopackage), 100*nopackage/packages))
print(fmt % (" Other", str(exceptions - upstream - nopackage), 100*(exceptions - upstream - nopackage)/packages))
elif options.action == "fm-outdated-all":
print "checking all against FM"
repo = Repository()
package_names = [name for name in repo.repoquery()]
pl=[Package(name, "FM-DEFAULT", "FM-DEFAULT", repo) for name in package_names]
packages = PackageList(packages=pl)
repo.package_list = packages
analyse_packages(packages)