Ejemplo n.º 1
0
 def __init__(self, paths, size, distro, arch):
     logging.debug("WeatherIcon.__init__")
     gtk.Image.__init__(self)
     self.paths = paths
     self.icon_size = size
     self.distro = distro
     self.arch = arch
     self.weather = 0
     self.pb = PreferencesBox(self.paths, self.distro, self.arch)
     logging.debug("Created PreferencesBox")
     self.wb = WeatherBox(self.paths)
     logging.debug("Created WeatherBox")
     self.pb.connect('new-preferences', self.on_new_preferences)
     self.weather_select = { '1': self.set_clear,
                        '2': self.set_few_clouds,
                        '3': self.set_overcast,
                        '4': self.set_shower,
                        '5': self.set_storm}
Ejemplo n.º 2
0
class WeatherIcon(gtk.Image):
    tooltip_template = """Debian Weather: %s
Arch: %s
Uninstallable: %s/%s (%d)"""
    def __init__(self, paths, size, distro, arch):
        logging.debug("WeatherIcon.__init__")
        gtk.Image.__init__(self)
        self.paths = paths
        self.icon_size = size
        self.distro = distro
        self.arch = arch
        self.weather = 0
        self.pb = PreferencesBox(self.paths, self.distro, self.arch)
        logging.debug("Created PreferencesBox")
        self.wb = WeatherBox(self.paths)
        logging.debug("Created WeatherBox")
        self.pb.connect('new-preferences', self.on_new_preferences)
        self.weather_select = { '1': self.set_clear,
                           '2': self.set_few_clouds,
                           '3': self.set_overcast,
                           '4': self.set_shower,
                           '5': self.set_storm}
    def cleanup(self):
        logging.debug('cleanup')

    def set_unavailable(self, reason):
        self.set_imageicon('debweather.png')
        self.set_tooltip_text('Service unavailable %s' % reason)

    def set_clear(self, broken, total, percent):
        self.set_imageicon('clear.png')
        self.set_tooltip_text(self.tooltip_template % ('Clear', self.arch, broken, total, percent))

    def set_few_clouds(self, broken, total, percent):
        self.set_imageicon('few-clouds.png')
        self.set_tooltip_text(self.tooltip_template % ('Few clouds', self.arch, broken, total, percent))

    def set_overcast(self, broken, total, percent):
        self.set_imageicon('overcast.png')
        self.set_tooltip_text(self.tooltip_template % ('Overcast', self.arch, broken, total, percent))

    def set_shower(self, broken, total, percent):
        self.set_imageicon('shower.png')
        self.set_tooltip_text(self.tooltip_template % ('Shower scattered', self.arch, broken, total, percent))

    def set_storm(self, broken, total, percent):
        self.set_imageicon('storm.png')
        self.set_tooltip_text(self.tooltip_template % ('Storm', self.arch, broken, total, percent))

    def set_icon_size(self, size):
        self.icon_size = size

    def set_imageicon(self, pngname):
        filename = self.paths.get_in_pix_path(pngname)
        temp = gtk.gdk.pixbuf_new_from_file_at_size(filename, self.icon_size, self.icon_size)
        logging.debug("setting image file: %s" % filename)
        self.set_from_pixbuf(temp)

    def update(self):
        logging.debug("Calling weather update")
        weather_url = "http://edos.debian.net/edos-debcheck/results/%s/latest/%s/weather.xml" % (self.distro, self.arch)
        logging.debug(weather_url)

        data = str()
        try:
            logging.debug("Connecting to...")
            logging.debug(weather_url)
            r1 = urllib2.urlopen(weather_url)
            logging.debug("Getting weather_url...")
            logging.debug("Getting response...")
            logging.debug(str(r1.headers))
            data = r1.read()
            logging.debug(data)
        except urllib2.HTTPError, e:
            logging.debug(str(e))
            self.set_unavailable(str(e))
            return False
        
        try:
            logging.debug('Parsing XML')
            weather_xml = XML(data)

            description = weather_xml.getiterator("description")[0].text
            self.wb.set_descr(description)
            logging.debug("Description: %s" % description)

            self.wb.set_arch(self.arch)
            self.weather = weather_xml.getiterator("index")[0].text
            logging.debug("Weather: %s" % self.weather)

            total = weather_xml.getiterator('total')[0].text
            self.wb.set_totpkg(total)
            logging.debug("Total: %s" % total)

            broken = weather_xml.getiterator('broken')[0].text
            self.wb.set_broken(broken)
            logging.debug("Broken: %s" % broken)

            url = weather_xml.getiterator('url')[0].text
            self.wb.set_url(url)
            logging.debug("URL: %s" % url)
            percent = (float(broken)/float(total))*100
            self.weather_select[self.weather](broken, total, percent)
            logging.debug("End parsing")
        except ExpatError:
            self.set_unavailable('XML Parsing Error')
            return False

        return True