summaryrefslogtreecommitdiff
blob: 205d96e0385e03f8afb33c6bc5f2294ea1880491 (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
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
# Copyright John N. Laliberte <allanonjl@gentoo.org>
# LICENSE - GPL2
# vim: set sts=4 sw=4 et tw=0 :

# gnome module
import urllib2, package_module, simple_cache_module
import clioptions_module
# import ftp_module



DEBUG = False
class GNOME:
    def _isgnome3(self, gnome_release_list):
        if int(gnome_release_list[0]) == 2 and int(gnome_release_list[1]) > 90:
            return True
        return False

    def __init__(self, nextrev=False):
        options = clioptions_module.Options()
        args = options.get_arguments()

        self.nextrev = nextrev;
        self.major_release = ".".join( args.release_number.split(".")[:2] )
        self.full_release = args.release_number

        # gnome_release is the major release number the development is leading up to or is part of. E.g, 2.21.5 will turn to 2.22 and 2.22.2 becomes 2.22
        # This is used in latest versions list fetching URL construction
        gnome_release_list = args.release_number.split(".")
        if self._isgnome3(gnome_release_list):
            gnome_release_list = ['3', '0']
        elif int(gnome_release_list[1]) % 2 != 0:
            gnome_release_list[1] = str(int(gnome_release_list[1]) + 1)
        self.gnome_release = ".".join(gnome_release_list[:2])

        self.ftpserver = "download.gnome.org"
        self.release_versions_file_path = 'https://download.gnome.org/teams/releng/'

    def generate_data_from_versions_markup(self, url):
        try:
            f = urllib2.urlopen(url)
        except:
            raise ValueError("Couldn't open %s" % url)

        ret = []
        for line in f.readlines():
            components = str.strip(line).split(':')
            # Skip invalid lines
            if len(components) != 4 or len(components[2]) == 0:
                continue
            # Skip mobile stuff, because we don't care. And they are mostly dupes anyway
            if components[0] == 'mobile':
                continue
            pkg = package_module.Package(components[1] + "-" + components[2])
            if (pkg.name and pkg.version):
                ret.append(pkg)
            else:
                print "Warning: Ignoring package %s because parsing of its name or version string '%s' failed" % (components[1], components[2])
        f.close()
        return ret

    def generate_data_individual(self):
        return self.generate_data_release()

    def generate_data_release(self):
        return self.generate_data_from_versions_markup(self.release_versions_file_path + self.full_release + '/versions')

import portage_module
def compare_packages(release_packages, latest_packages, packages_in_portage):
    # we care about 5 cases
    # 1.  portage version is less than the release version. (RED)
    # 2.  portage version is equal to the release version, but less than the latest version. (LIGHT GREEN)
    # 3.  portage version is equal to the release version and the latest version. (GREEN)
    # 4.  portage version is greater than the release version (GREEN)
    # 5.  package does not exist in portage (GREY)

    # again, we choose release_packages as the enumerator for the package names
    # since it will have ALL packages ( for example, if we used portage_packages, we
    # might miss the packages that do not exist in portage )
    status_packages = []
    for package in release_packages:
        color = None
        release_package = package
        latest_package = portage_module.findpackage(package.name, latest_packages)
        if latest_package == None:
            print "Warning: latest packages set does not have an entry for %s, using release set version %s." % (package.name, package.version)
            latest_package = package
        portage_package = portage_module.findpackage(package.name, packages_in_portage)

        if portage_package == None:
            status = package_module.Status.NotFound
            # we need to create a phony package since findpackage
            # returns None
            portage_package = package_module.Package(package.name)

        elif portage_module.best_version_test(portage_package.name_plus_version, \
                                     release_package.name_plus_version) == 2:
            status = package_module.Status.NeedUpdate

        elif portage_module.best_version_test(portage_package.name_plus_version, \
                                       latest_package.name_plus_version) == 2:
            status = package_module.Status.NewerVersion

        else:
            status = package_module.Status.Compliant

        #if portage_package != None:

        # FIXME: Reports release version as latest version to not have to deal with this right now
        if latest_package == None:
            print "No latest version known for %s, FIXME!" % release_package.name
            latest_package = release_package

        if DEBUG:
            print "package: " + str(release_package.name) + \
                 " | pp: " + str(portage_package.version) + \
                 " | rp: " + str(release_package.version) + \
                 " | lp: " + str(latest_package.version) + \
                 " | status: " + str(status)

        status_packages.append(package_module.PackageStatus(release_package.name, str(portage_package.version), str(release_package.version), str(latest_package.version), status))

    return status_packages