| 20 | |
| 21 | |
| 22 | class VSCUpdateDefinition(object): |
| 23 | |
| 24 | def __init__(self, platform=None, architecture=None, buildtype=None, quality=None, |
| 25 | updateurl=None, name=None, version=None, productVersion=None, |
| 26 | hashs=None, timestamp=None, sha256hash=None, supportsFastUpdate=None): |
| 27 | |
| 28 | if not vsc.Utility.validate_platform(platform): |
| 29 | raise ValueError(f"Platform {platform} invalid or not implemented") |
| 30 | |
| 31 | if not vsc.Utility.validate_architecture(architecture): |
| 32 | raise ValueError( |
| 33 | f"Architecture {architecture} invalid or not implemented") |
| 34 | |
| 35 | if not vsc.Utility.validate_buildtype(buildtype): |
| 36 | raise ValueError( |
| 37 | f"Buildtype {buildtype} invalid or not implemented") |
| 38 | |
| 39 | if not vsc.Utility.validate_quality(quality): |
| 40 | raise ValueError(f"Quality {quality} invalid or not implemented") |
| 41 | |
| 42 | self.identity = platform |
| 43 | |
| 44 | if architecture: |
| 45 | self.identity += f'-{architecture}' |
| 46 | if buildtype: |
| 47 | self.identity += f'-{buildtype}' |
| 48 | |
| 49 | self.platform = platform |
| 50 | self.architecture = architecture |
| 51 | self.buildtype = buildtype |
| 52 | self.quality = quality |
| 53 | self.updateurl = updateurl |
| 54 | self.name = name |
| 55 | self.version = version |
| 56 | self.productVersion = productVersion |
| 57 | self.hash = hashs |
| 58 | self.timestamp = timestamp |
| 59 | self.sha256hash = sha256hash |
| 60 | self.supportsFastUpdate = supportsFastUpdate |
| 61 | self.checkedForUpdate = False |
| 62 | |
| 63 | def check_for_update(self, old_commit_id=None): |
| 64 | if not old_commit_id: |
| 65 | # To trigger the API to delta |
| 66 | old_commit_id = '7c4205b5c6e52a53b81c69d2b2dc8a627abaa0ba' |
| 67 | |
| 68 | url = vsc.URL_BINUPDATES + \ |
| 69 | f"{self.identity}/{self.quality}/{old_commit_id}" |
| 70 | |
| 71 | log.debug(f'Update url {url}') |
| 72 | result = requests.get(url, allow_redirects=True, timeout=vsc.TIMEOUT) |
| 73 | self.checkedForUpdate = True |
| 74 | |
| 75 | if result.status_code == 204: |
| 76 | # No update available |
| 77 | return False |
| 78 | elif result.status_code != 200: |
| 79 | # Unhandled response from API |