File: version_check.py

package info (click to toggle)
streamtuner2 2.2.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,432 kB
  • sloc: python: 8,976; makefile: 91; php: 51; sh: 7; perl: 3
file content (42 lines) | stat: -rw-r--r-- 1,342 bytes parent folder | download | duplicates (4)
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
# encoding: utf-8
# title: Version/update check on startup
# description: Checks fossil repository for newer version
# version: 1.1
# depends: streamtuner2 >= 2.2.0
# priority: default
# type: feature
# category: ui
#
# Probes http://fossil.include-once.org/streamtuner2/cat/releases.json
# for newer version. Activates only on ~20% of startups, only adds a statusbar
# notification after 5 seconds, no nag screen.


import json
import ahttp
import random
import threading
from config import plugin_meta
from channels import FeaturePlugin

# Update notification
class version_check(FeaturePlugin):

    # Hook timer
    def init2(self, parent):
        if random.randint(0,5):
            return
        threading.Timer(5, self.check).start()

    # Request release.json, notify in status bar
    def check(self, *x, **y):
        try:
            j = ahttp.get("http://fossil.include-once.org/streamtuner2/cat/releases.json", timeout=5, quieter=1)
            j = json.loads(j)
            max = j["releases"][0]["version"] # alread ordered newest-first
            m = plugin_meta(module="st2", extra_base=["config"])
            ver = m["version"]
            if ver < max:
                self.status(text="A newer streamtuner2 version (→%s) is available." % str(ver), timeout=7, icon="gtk-dialog-info")
        except:
            None