-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdater.py
More file actions
50 lines (42 loc) · 1.76 KB
/
Copy pathupdater.py
File metadata and controls
50 lines (42 loc) · 1.76 KB
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
"""Updater for Sculptor release artifacts."""
from __future__ import annotations
from datetime import UTC
from email.utils import parsedate_to_datetime
from typing import TYPE_CHECKING, ClassVar
if TYPE_CHECKING:
import aiohttp
from lib.update.net import fetch_headers
from lib.update.updaters import DownloadHashUpdater, VersionInfo, register_updater
from lib.update.updaters.metadata import NO_METADATA
@register_updater
class SculptorUpdater(DownloadHashUpdater):
"""Resolve Sculptor version metadata from object-store headers."""
name = "sculptor"
BASE_URL = "https://imbue-sculptor-releases.s3.us-west-2.amazonaws.com/sculptor"
PLATFORMS: ClassVar[dict[str, str]] = {
"aarch64-darwin": "Sculptor.dmg",
"x86_64-darwin": "Sculptor-x86_64.dmg",
"x86_64-linux": "AppImage/x64/Sculptor.AppImage",
}
async def fetch_latest(self, session: aiohttp.ClientSession) -> VersionInfo:
"""Read the Last-Modified header and derive a date-based version."""
url = f"{self.BASE_URL}/Sculptor.dmg"
headers = await fetch_headers(
session,
url,
request_timeout=self.config.default_timeout,
config=self.config,
)
last_modified = headers.get("Last-Modified", "")
if not last_modified:
msg = "No Last-Modified header from Sculptor download"
raise RuntimeError(msg)
try:
dt = parsedate_to_datetime(last_modified)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=UTC)
dt = dt.astimezone(UTC)
version = dt.strftime("%Y-%m-%d")
except (TypeError, ValueError):
version = last_modified[:10]
return VersionInfo(version=version, metadata=NO_METADATA)