summaryrefslogtreecommitdiffstats
path: root/cnucnu.py
blob: aa2a247c956061fd9103482fcc35d726276df258 (plain)
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
#!/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
sys.path.insert(0, './lib')

import cnucnu.package_list as package_list
import cnucnu.checkshell as checkshell
import pickle

if __name__ == '__main__':
    import re
    import cnucnu.errors as cc_errors

    from optparse import OptionParser
    parser = OptionParser()
     
    parser.add_option("", "--check", dest="check", help="check URL and regex interactively", action="store_true", default=False)

    (options, args) = parser.parse_args()

    if options.check:
        shell = checkshell.CheckShell()
        while True:
            try:
                if not shell.cmdloop():
                    break
            except Exception, ex: 
                print 'Exception occured:'
                print repr(ex)
                break
    else:
        repo = package_list.Repository(repoid="rawhide-source")
        plist = package_list.PackageList(repo=repo)
        packages = plist.packages

        package_nr = 0

        if package_nr == 0:
            mode = "w"
        else:
            mode = "a"


        outdated_f = open("cnucnu-outdated.log", mode)
        too_new_f = open("cnucnu-too_new.log", mode)
        error_f = open("cnucnu-error.log", mode)

        for package in packages[package_nr:]:
            sys.stderr.write("Testing: %i -  %s\n" % (package_nr, package.name))

            try:
                if package.upstream_newer:
                    print "Outdated package %(name)s: Rawhide version: %(repo_version)s, Upstream latest: %(latest_upstream)s" % package
                    outdated_f.write("%(name)s %(repo_version)s %(latest_upstream)s\n" % package)
                elif package.repo_newer:
                    print "Rawhide newer %(name)s: Rawhide version: %(repo_version)s, Upstream latest: %(latest_upstream)s" % package
                    too_new_f.write("%(name)s %(repo_version)s %(latest_upstream)s\n" % package)

            except cc_errors.UpstreamVersionRetrievalError, e:
                sys.stderr.write("%s\n" % str(e))
                sys.stderr.write("Rawhide Version: %s\n" % package.repo_version)
                error_f.write("%s: %s - Rawhide Version: %s\n" % (package.name, str(e), package.repo_version))
            except KeyError, ke:
                sys.stderr.write("Package not found in Rawhide: %s\n" % str(ke))

            package_nr = package_nr + 1

        outdated_f.close()
        too_new_f.close()
        error_f.close()
        pickle_file = open("data.pickle", "wb")
        pickle.dump(packages, pickle_file)
        pickle_file.close()