forked from 005jon/plugin.video.antiktv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_update.py
103 lines (80 loc) · 3.21 KB
/
check_update.py
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
# -*- coding: utf-8 -*-
import requests
import os,sys
from zipfile import ZipFile
import xml.etree.ElementTree as ET
ADDONS_PATH='/usr/lib/enigma2/python/Plugins/Extensions/archivCZSK/resources/repositories/addons/'
ANTIK_ADDON_PATH=os.path.join( ADDONS_PATH, 'plugin.video.antiktv' )
GITHUB_ADDON_XML='https://raw.githubusercontent.com/skyjet18/plugin.video.antiktv/master/addon.xml'
GITHUB_ARCHIVE_URL='https://github.com/skyjet18/plugin.video.antiktv/archive/%s.zip'
GITHUB_ADDON_XML_COMMITS='https://api.github.com/repos/skyjet18/plugin.video.antiktv/commits?path=addon.xml'
TMP_ZIP='/tmp/plugin_antiktv-update.zip'
# ####################################################################################################
def get_addon_version( xml_string ):
xml_root = ET.fromstring(xml_string)
return int(xml_root.attrib['version'].replace('.', ''))
# ####################################################################################################
# check if archivCZSK is installed
if os.path.isdir( ADDONS_PATH ) == False:
print("archivCZSK nie je nainstalovany")
sys.exit(1)
# get latest addon.xml from github
try:
with requests.get( GITHUB_ADDON_XML ) as response:
if response.status_code != 200:
print( "Zlyhalo stiahnutie aktualneho addon.xml z githubu - navratovy kod %d" % response.status_code)
sys.exit(1)
github_ver = get_addon_version( response.text )
except:
print( "Kontrola najnovsej verzie z githubu zlyhala")
sys.exit(1)
# get local version
try:
with open( ADDONS_PATH + 'plugin.video.antiktv/addon.xml', 'r' ) as f:
local_ver = get_addon_version( f.read() )
except FileNotFoundError:
print("Addon nie je nainstalovany - vynucujem cistu instalaciu")
local_ver = 0
print( "Local ver: %d" % local_ver )
print( "Github ver: %d" % github_ver )
if local_ver >= github_ver:
print( "Je nainstalovana aktualna verzia - nie je potrebne aktualizovat")
sys.exit(0)
# check latest commit sha of addon.xml file
commit_sha = None
try:
with requests.get( GITHUB_ADDON_XML_COMMITS ) as response:
if response.status_code == 200:
commit_sha = response.json()[0]['sha']
except:
print("Zlyhalo zistovanie sha commit id pre addon.xml z githubu")
sys.exit(1)
if commit_sha == None:
print("Nepodarilo sa ziskat sha commit id pre addon.xml z githubu")
sys.exit(1)
print( "Update commit sha: %s" % commit_sha )
# download latest version
try:
with requests.get( GITHUB_ARCHIVE_URL % commit_sha ) as response:
with open( TMP_ZIP, 'wb' ) as f:
f.write( response.content )
except:
print("Stiahnutie archivu z poslednou verziou z githubu zlyhalo")
sys.exit(1)
with ZipFile( TMP_ZIP, 'r' ) as zip:
for l in zip.infolist():
dst_file = l.filename.replace('plugin.video.antiktv-master/', '')
if dst_file == '.gitignore':
continue
dst_file = os.path.join( ANTIK_ADDON_PATH, dst_file )
# check if it is a directory
if l.external_attr == 16:
os.makedirs( dst_file )
else:
with open( dst_file, 'wb' ) as f:
f.write( zip.read(l.filename) )
# if we have saved permissions, then set it
if (l.external_attr >> 16) != 0:
os.chmod( dst_file, (l.external_attr >> 16) )
os.remove( TMP_ZIP )
print( "Uspesne zaktualizovane na verziu %s - restartujte prijimac pre aplikaciu zmien" % github_ver )