miglioramenti updater per major release
This commit is contained in:
+61
-48
@@ -5,14 +5,14 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
from core import httptools, filetools, downloadtools
|
from core import httptools, filetools
|
||||||
from core.ziptools import ziptools
|
|
||||||
from platformcode import logger, platformtools
|
from platformcode import logger, platformtools
|
||||||
import json
|
import json
|
||||||
import xbmc
|
import xbmc
|
||||||
import re
|
import re
|
||||||
import xbmcaddon
|
import xbmcaddon
|
||||||
from lib import githash
|
from lib import githash
|
||||||
|
import urllib
|
||||||
|
|
||||||
addon = xbmcaddon.Addon('plugin.video.kod')
|
addon = xbmcaddon.Addon('plugin.video.kod')
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ _hdr_pat = re.compile("^@@ -(\d+),?(\d+)? \+(\d+),?(\d+)? @@.*")
|
|||||||
branch = 'stable'
|
branch = 'stable'
|
||||||
user = 'kodiondemand'
|
user = 'kodiondemand'
|
||||||
repo = 'addon'
|
repo = 'addon'
|
||||||
addonDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/'
|
addonDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))).replace('\\', '/') + '/'
|
||||||
maxPage = 5 # le api restituiscono 30 commit per volta, quindi se si è rimasti troppo indietro c'è bisogno di andare avanti con le pagine
|
maxPage = 5 # le api restituiscono 30 commit per volta, quindi se si è rimasti troppo indietro c'è bisogno di andare avanti con le pagine
|
||||||
trackingFile = "last_commit.txt"
|
trackingFile = "last_commit.txt"
|
||||||
|
|
||||||
@@ -80,6 +80,15 @@ def check_addon_init():
|
|||||||
logger.info('aggiornando a ' + commitJson['sha'])
|
logger.info('aggiornando a ' + commitJson['sha'])
|
||||||
alreadyApplied = True
|
alreadyApplied = True
|
||||||
|
|
||||||
|
# major update
|
||||||
|
if len(commitJson['files']) > 50:
|
||||||
|
localCommitFile.close()
|
||||||
|
c['sha'] = updateFromZip('Aggiornamento in corso...')
|
||||||
|
localCommitFile = open(addonDir + trackingFile, 'w') # il file di tracking viene eliminato, lo ricreo
|
||||||
|
changelog += commitJson['commit']['message'] + " | "
|
||||||
|
nCommitApplied += 3 # il messaggio sarà lungo, probabilmente, il tempo di vis. è maggiorato
|
||||||
|
break
|
||||||
|
|
||||||
for file in commitJson['files']:
|
for file in commitJson['files']:
|
||||||
if file["filename"] == trackingFile: # il file di tracking non si modifica
|
if file["filename"] == trackingFile: # il file di tracking non si modifica
|
||||||
continue
|
continue
|
||||||
@@ -109,15 +118,12 @@ def check_addon_init():
|
|||||||
alreadyApplied = False
|
alreadyApplied = False
|
||||||
else: # nel caso ci siano stati problemi
|
else: # nel caso ci siano stati problemi
|
||||||
logger.info('lo sha non corrisponde, scarico il file')
|
logger.info('lo sha non corrisponde, scarico il file')
|
||||||
remove(addonDir + file["filename"])
|
localFile.close()
|
||||||
downloadtools.downloadfile(file['raw_url'], addonDir + file['filename'],
|
urllib.urlretrieve(file['raw_url'], os.path.join(addonDir, file['filename']))
|
||||||
silent=True, continuar=True, resumir=False)
|
|
||||||
else: # è un file NON testuale, lo devo scaricare
|
else: # è un file NON testuale, lo devo scaricare
|
||||||
# se non è già applicato
|
# se non è già applicato
|
||||||
if not (filetools.isfile(addonDir + file['filename']) and getSha(addonDir + file['filename']) == file['sha']):
|
if not (filetools.isfile(addonDir + file['filename']) and getSha(addonDir + file['filename']) == file['sha']):
|
||||||
remove(addonDir + file["filename"])
|
urllib.urlretrieve(file['raw_url'], os.path.join(addonDir, file['filename']))
|
||||||
downloadtools.downloadfile(file['raw_url'], addonDir + file['filename'], silent=True,
|
|
||||||
continuar=True, resumir=False)
|
|
||||||
alreadyApplied = False
|
alreadyApplied = False
|
||||||
elif file['status'] == 'removed':
|
elif file['status'] == 'removed':
|
||||||
remove(addonDir+file["filename"])
|
remove(addonDir+file["filename"])
|
||||||
@@ -210,15 +216,21 @@ def apply_patch(s,patch,revert=False):
|
|||||||
|
|
||||||
|
|
||||||
def getSha(path):
|
def getSha(path):
|
||||||
f = open(path).read()
|
try:
|
||||||
return githash.blob_hash(path, len(f)).hexdigest()
|
f = open(path, 'rb')
|
||||||
|
except:
|
||||||
|
return ''
|
||||||
|
size = len(f.read())
|
||||||
|
f.seek(0)
|
||||||
|
return githash.blob_hash(f, size).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def getShaStr(str):
|
def getShaStr(str):
|
||||||
return githash.blob_hash(StringIO(str), len(str)).hexdigest()
|
return githash.blob_hash(StringIO(str), len(str)).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def updateFromZip():
|
def updateFromZip(message='Installazione in corso...'):
|
||||||
dp = platformtools.dialog_progress_bg('Kodi on Demand', 'Installazione in corso...')
|
dp = platformtools.dialog_progress_bg('Kodi on Demand', message)
|
||||||
dp.update(0)
|
dp.update(0)
|
||||||
|
|
||||||
remotefilename = 'https://github.com/' + user + "/" + repo + "/archive/" + branch + ".zip"
|
remotefilename = 'https://github.com/' + user + "/" + repo + "/archive/" + branch + ".zip"
|
||||||
@@ -232,7 +244,6 @@ def updateFromZip():
|
|||||||
remove(localfilename)
|
remove(localfilename)
|
||||||
removeTree(destpathname + "addon-" + branch)
|
removeTree(destpathname + "addon-" + branch)
|
||||||
|
|
||||||
import urllib
|
|
||||||
urllib.urlretrieve(remotefilename, localfilename,
|
urllib.urlretrieve(remotefilename, localfilename,
|
||||||
lambda nb, bs, fs, url=remotefilename: _pbhook(nb, bs, fs, url, dp))
|
lambda nb, bs, fs, url=remotefilename: _pbhook(nb, bs, fs, url, dp))
|
||||||
|
|
||||||
@@ -243,17 +254,19 @@ def updateFromZip():
|
|||||||
try:
|
try:
|
||||||
hash = fixZipGetHash(localfilename)
|
hash = fixZipGetHash(localfilename)
|
||||||
import zipfile
|
import zipfile
|
||||||
with zipfile.ZipFile(localfilename, "r") as zip_ref:
|
with zipfile.ZipFile(io.FileIO(localfilename), "r") as zip_ref:
|
||||||
zip_ref.extractall(destpathname)
|
zip_ref.extractall(destpathname)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info('Non sono riuscito ad estrarre il file zip')
|
logger.info('Non sono riuscito ad estrarre il file zip')
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
|
dp.close()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
dp.update(95)
|
dp.update(95)
|
||||||
|
|
||||||
# puliamo tutto
|
# puliamo tutto
|
||||||
removeTree(addonDir)
|
removeTree(addonDir)
|
||||||
|
xbmc.sleep(1000)
|
||||||
|
|
||||||
rename(destpathname + "addon-" + branch, addonDir)
|
rename(destpathname + "addon-" + branch, addonDir)
|
||||||
|
|
||||||
@@ -269,34 +282,45 @@ def updateFromZip():
|
|||||||
|
|
||||||
def remove(file):
|
def remove(file):
|
||||||
if os.path.isfile(file):
|
if os.path.isfile(file):
|
||||||
removed = False
|
try:
|
||||||
while not removed:
|
os.remove(file)
|
||||||
try:
|
except:
|
||||||
os.remove(file)
|
logger.info('File ' + file + ' NON eliminato')
|
||||||
removed = True
|
|
||||||
except:
|
|
||||||
logger.info('File ' + file + ' NON eliminato')
|
|
||||||
|
|
||||||
|
|
||||||
|
def onerror(func, path, exc_info):
|
||||||
|
"""
|
||||||
|
Error handler for ``shutil.rmtree``.
|
||||||
|
|
||||||
|
If the error is due to an access error (read only file)
|
||||||
|
it attempts to add write permission and then retries.
|
||||||
|
|
||||||
|
If the error is for another reason it re-raises the error.
|
||||||
|
|
||||||
|
Usage : ``shutil.rmtree(path, onerror=onerror)``
|
||||||
|
"""
|
||||||
|
import stat
|
||||||
|
if not os.access(path, os.W_OK):
|
||||||
|
# Is the error an access error ?
|
||||||
|
os.chmod(path, stat.S_IWUSR)
|
||||||
|
func(path)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
def removeTree(dir):
|
def removeTree(dir):
|
||||||
if os.path.isdir(dir):
|
if os.path.isdir(dir):
|
||||||
removed = False
|
try:
|
||||||
while not removed:
|
shutil.rmtree(dir, ignore_errors=False, onerror=onerror)
|
||||||
try:
|
except Exception as e:
|
||||||
shutil.rmtree(dir)
|
logger.info('Cartella ' + dir + ' NON eliminata')
|
||||||
removed = True
|
logger.error(e)
|
||||||
except:
|
|
||||||
logger.info('Cartella ' + dir + ' NON eliminato')
|
|
||||||
|
|
||||||
|
|
||||||
def rename(dir1, dir2):
|
def rename(dir1, dir2):
|
||||||
renamed = False
|
try:
|
||||||
while not renamed:
|
filetools.rename(dir1, dir2)
|
||||||
try:
|
except:
|
||||||
filetools.rename(dir1, dir2)
|
logger.info('cartella ' + dir1 + ' NON rinominata')
|
||||||
renamed = True
|
|
||||||
except:
|
|
||||||
logger.info('cartella ' + dir1 + ' NON rinominata')
|
|
||||||
|
|
||||||
|
|
||||||
# https://stackoverflow.com/questions/3083235/unzipping-file-results-in-badzipfile-file-is-not-a-zip-file
|
# https://stackoverflow.com/questions/3083235/unzipping-file-results-in-badzipfile-file-is-not-a-zip-file
|
||||||
@@ -325,15 +349,4 @@ def _pbhook(numblocks, blocksize, filesize, url, dp):
|
|||||||
dp.update(percent)
|
dp.update(percent)
|
||||||
except:
|
except:
|
||||||
percent = 90
|
percent = 90
|
||||||
dp.update(percent)
|
dp.update(percent)
|
||||||
|
|
||||||
|
|
||||||
def remove(file):
|
|
||||||
if os.path.isfile(file):
|
|
||||||
removed = False
|
|
||||||
while not removed:
|
|
||||||
try:
|
|
||||||
os.remove(file)
|
|
||||||
removed = True
|
|
||||||
except:
|
|
||||||
logger.info('File ' + file + ' NON eliminato')
|
|
||||||
Reference in New Issue
Block a user