File: updater.py

package info (click to toggle)
pysiogame 4.20.01-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,876 kB
  • sloc: python: 48,742; xml: 3,813; sh: 30; makefile: 11
file content (53 lines) | stat: -rw-r--r-- 1,375 bytes parent folder | download | duplicates (2)
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
# -*- coding: utf-8 -*-

import urllib
import socket
import threading
import classes.cversion


class Updater(threading.Thread):
    def __init__(self, config, android):
        self.config = config
        self.android = android
        if android is None:
            threading.Thread.__init__(self)

    @staticmethod
    def internet(host="8.8.8.8", port=53, timeout=3):
        try:
            socket.setdefaulttimeout(timeout)
            socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
            return True
        except Exception as ex:
            #print ex.message
            return False

    def check4updates(self):
        if self.android is None:
            from lxml import etree
            url = "https://www.updates.eduactiv8.org/update.xml"
            update = urllib.urlopen(url).read()
            root = etree.XML(update)
            version = root.find(".//v")
            version_value = version.text
            self.config.avail_version = version_value
            if version_value != classes.cversion.ver:
                self.config.update_available = True
            else:
                self.config.update_available = False

    def run(self):
        try:
            if self.internet():
                self.check4updates()
        except:
            pass


"""
update.xml
<vi>
    <v>3.80.411</v>
</vi>
"""