Source code for liatool.versions

from os import listdir, path, remove
from bpy.types import Scene
from .bitbucket.mybitbucket import BitbucketRepo
from zipfile import ZipFile
from shutil import move
from distutils.version import StrictVersion


[docs] def readToken(): try: with open(Scene.ILSP_tokenPath, 'r') as file: return file.read().replace('\n', '') except Exception: return ''
[docs] def testToken(token): repo = BitbucketRepo( workspace=Scene.ILSP_workspace, repo=Scene.ILSP_repo, token=token ) _, status = repo.getDownloadsList() return status
[docs] def remoteVersions(): repo = BitbucketRepo( workspace=Scene.ILSP_workspace, repo=Scene.ILSP_repo, token=readToken() ) items = {'RELEASE': [], 'DEVELOPER': []} tags, status = repo.getDownloadsList() if status == 200: for tag in tags['values']: name = tag['name'] if 'rel-' in name: name = name.replace('rel-', '') items['RELEASE'].append(name) if 'dev-' in name: name = name.replace('dev-', '') items['DEVELOPER'].append(name) return items
[docs] def downloadApp(branch, version): if branch == 'RELEASE': fileName = 'rel-' elif branch == 'DEVELOPER': fileName = 'dev-' fileName += version bitbucket = BitbucketRepo( workspace=Scene.ILSP_workspace, repo=Scene.ILSP_repo, token=readToken() ) targetPath = path.dirname(Scene.ILSP_addonPath) suffix = fileName.replace('.', '-') targetPath = path.join(targetPath, 'LIATool-' + suffix) zipTargetPath = targetPath + '.zip' bitbucket.downloads( fileName=fileName, filePath=targetPath + '.zip') with ZipFile(zipTargetPath, 'r') as zObject: zObject.extractall(targetPath) remove(zipTargetPath) for root in listdir(targetPath): rootDir = path.join(targetPath, root) for file in listdir(rootDir): move(path.join(rootDir, file), path.join(targetPath, file))
[docs] def checkUpdates(local=[], remote=[]): actualLocal = {} actualLocal['DEVELOPER'] = '0.0.0' actualLocal['RELEASE'] = '0.0.0' actualRemote = {} actualRemote['DEVELOPER'] = '0.0.0' actualRemote['RELEASE'] = '0.0.0' for branch in local: for version in local[branch]: try: if type(version) is tuple: new = '' new = str(version[0]) + '.' new += str(version[1]) + '.' new += str(version[2]) version = new if StrictVersion(version) > StrictVersion(actualLocal[branch]): actualLocal[branch] = version except Exception: pass for branch in remote: for version in remote[branch]: try: if StrictVersion(version) > StrictVersion(actualRemote[branch]): actualRemote[branch] = version except Exception: pass update = {} update['DEVELOPER'] = None update['RELEASE'] = None for branch in remote: try: if StrictVersion(actualRemote[branch]) > StrictVersion(actualLocal[branch]): if StrictVersion(actualLocal[branch]) > StrictVersion('0.0.0'): update[branch] = actualRemote[branch] + ' > ' + actualLocal[branch] else: update[branch] = actualRemote[branch] except Exception: pass return update