summaryrefslogtreecommitdiff
blob: e876fb301b7502286276a6a7ae51af5a234c3d7e (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
124
125
# Copyright John N. Laliberte <allanonjl@gentoo.org>
# LICENSE - GPL2

import package_module,time,clioptions_module,gnome_module,os

class Output:

    def __init__(self, packages, to_calculate):
        self.packages = packages

        if to_calculate:
            self.calculate_stats()
    
    def calculate_stats(self):
        # variables to hold for stats
        total_packs = len(self.packages)        
        self.update_needed = float(0)
        self.compliant = float(0)
        self.not_found = float(0)
        self.newer = float(0)
        
        for package in self.packages:
            if package.status == package_module.Status.Compliant:
                self.compliant +=1
            elif package.status == package_module.Status.NewerVersion:
                self.newer +=1
            elif package.status == package_module.Status.NotFound:
                self.not_found +=1
            elif package.status == package_module.Status.NeedUpdate:
                self.update_needed +=1
        
        try:
            self.update_percent = float(self.update_needed / total_packs) * 100
        except ZeroDivisionError:
            self.update_percent = 0
        try:
            self.compliant_percent = float(self.compliant / total_packs) * 100
        except ZeroDivisionError:
            self.compliant_percent = 0
        try:
            self.notfound_percent = float(self.not_found / total_packs) * 100
        except ZeroDivisionError:
            self.notfound_percent = 0
        try:
            self.total_percent = float( (self.update_needed + self.not_found ) / total_packs ) * 100
        except ZeroDivisionError:
            self.total_percent = 0
        
    def generate_html(self):
        
        # now we have all the results in the results list.
        # just time to generate some kind of "useful" output.
        # for now, lets just make a crappy html file. ( this should use css and the like )
        # name, portage_version, gnome_version, status <-- is whats in the PackageUpdate object
        current_time = str(time.asctime(time.localtime()))
        
        lines = []
        
        # header
        lines.append("<html>")
        lines.append("<h2>Gnome " + clioptions_module.Options().get_arguments().release_number + " Progress</h2>")
        lines.append("contact " + os.environ["USER"] + "@gentoo.org if anything is not correct<br>")
        lines.append("Generated date: " + current_time + "<br>")
        lines.append("Directories checked ( recursively ): <br>")
        for dir in gnome_module.GNOME().release_directories:
            directory = "ftp://ftp.gnome.org/" + dir
            lines.append("<a href=" + "\"" + directory + "\"" + ">" + directory + "</a>" + "<br>")
        
        # stats
        lines.append("<br>")
        lines.append("Compliant Packs: " + str('%0.2f' % self.compliant_percent)+ "%" + "  Number = " + str(self.compliant) + "<br>")
        lines.append("Packs that need to be updated: " + str('%0.2f' % self.update_percent)+ "%" + "  Number = " + str(self.update_needed) + "<br>")
        lines.append("New Packs that need to be added: " + str('%0.2f' % self.notfound_percent)+ "%" + "  Number = " + str(self.not_found) + "<br>")
        
        lines.append("<table cellpadding=\"10\">")
        lines.append("<th>Package Name</th><th>Portage Version</th><th>Official Release Version</th><th>Latest Available Version</th>")
        
        # data
        for package in self.packages:
            if package.status == package_module.Status.NeedUpdate:
                lines.append("<tr bgcolor=\"red\">")
            elif package.status == package_module.Status.Compliant:
                lines.append("<tr bgcolor=\"green\">")
            elif package.status == package_module.Status.NotFound:
                lines.append("<tr bgcolor=\"grey\">")    
            elif package.status == package_module.Status.NewerVersion:
                lines.append("<tr bgcolor=\"33CC00\">")
            
            lines.append("<td>" + str(package.name) + "</td>")
            lines.append("<td>" + str(package.portage_version) + "</td>")
            lines.append("<td>" + str(package.gnome_version) + "</td>")
            lines.append("<td>" + str(package.latest_version) + "</td>")
                
            lines.append("</tr>")
        
        lines.append("</table>")
        
        # footer
        lines.append("<br>")
        lines.append("</html>")
        
        self.write_file(lines, clioptions_module.Options().get_arguments().output)
        
        print "Generated html output."

    def generate_keywords(self):
        lines = []
        for package in self.packages:
            package_string = package.category + "/" + package.name + "-" + package.version
            # only append revision if its not -r0
            if "r0" != package.revision:
                package_string += "-" + package.revision

            lines.append("=" + package_string)

        self.write_file(lines, "package.keywords")

        print "Generate package.keywords output."

    def write_file(self, lines, filename):
        file = open(filename, "w")
        file.writelines(x +'\n' for x in lines)
        file.flush()
        file.close()
        del file