[update] implement '--update-to'

to switch between update channels (stable or dev (alias nightly & master))
or to install a specific version

Examples:
--update-to dev
--update-to dev@2024.05.25
--update-to v1.25.2
pull/5667/head
Mike Fährmann 4 months ago
parent 5018bd42f8
commit 53aadb0c44
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -179,6 +179,11 @@ def build_parser():
dest="update", action="store_const", const="latest", dest="update", action="store_const", const="latest",
help="Update to the latest version", help="Update to the latest version",
) )
general.add_argument(
"--update-to",
dest="update", metavar="[CHANNEL@]TAG",
help="Upgrade/downgrade to a specific version",
)
general.add_argument( general.add_argument(
"--update-check", "--update-check",
dest="update", action="store_const", const="check", dest="update", action="store_const", const="check",

@ -7,29 +7,38 @@
# published by the Free Software Foundation. # published by the Free Software Foundation.
import os import os
import re
import sys import sys
from .extractor.common import Extractor, Message from .extractor.common import Extractor, Message
from .job import DownloadJob from .job import DownloadJob
from . import util, version from . import util, version, exception
REPOS = { REPOS = {
"stable": "mikf/gallery-dl", "stable" : "mikf/gallery-dl",
"dev" : "gdl-org/builds", "dev" : "gdl-org/builds",
"nightly": "gdl-org/builds",
"master" : "gdl-org/builds",
} }
BINARIES_STABLE = {
"windows" : "gallery-dl.exe",
"windows_x86": "gallery-dl.exe",
"windows_x64": "gallery-dl.exe",
"linux" : "gallery-dl.bin",
}
BINARIES_DEV = {
"windows" : "gallery-dl_windows.exe",
"windows_x86": "gallery-dl_windows_x86.exe",
"windows_x64": "gallery-dl_windows.exe",
"linux" : "gallery-dl_ubuntu",
"macos" : "gallery-dl_macos",
}
BINARIES = { BINARIES = {
"stable": { "stable" : BINARIES_STABLE,
"windows" : "gallery-dl.exe", "dev" : BINARIES_DEV,
"windows_x86": "gallery-dl.exe", "nightly": BINARIES_DEV,
"linux" : "gallery-dl.bin", "master" : BINARIES_DEV,
},
"dev": {
"windows" : "gallery-dl_windows.exe",
"windows_x86": "gallery-dl_windows_x86.exe",
"linux" : "gallery-dl_ubuntu",
"macos" : "gallery-dl_macos",
},
} }
@ -40,7 +49,7 @@ class UpdateJob(DownloadJob):
if kwdict["_check"]: if kwdict["_check"]:
self.status |= 1 self.status |= 1
return self.extractor.log.info( return self.extractor.log.info(
"Current version is up to date (%s)", version.__version__) "gallery-dl is up to date (%s)", version.__version__)
if kwdict["_check"]: if kwdict["_check"]:
return self.extractor.log.info( return self.extractor.log.info(
@ -109,6 +118,9 @@ class UpdateJob(DownloadJob):
self.out.success(pathfmt.path) self.out.success(pathfmt.path)
def _check_update(self, kwdict): def _check_update(self, kwdict):
if kwdict["_exact"]:
return True
tag = kwdict["tag_name"] tag = kwdict["tag_name"]
if tag[0] == "v": if tag[0] == "v":
@ -149,22 +161,51 @@ class UpdateExtractor(Extractor):
pattern = r"update(?::(.+))?" pattern = r"update(?::(.+))?"
def items(self): def items(self):
tag = "latest"
check = exact = False
variant = version.__variant__ or "stable/windows" variant = version.__variant__ or "stable/windows"
repo, _, binary = variant.partition("/") repo, _, binary = variant.partition("/")
tag = "latest"
target = self.groups[0]
if target == "latest":
pass
elif target == "check":
check = True
else:
channel, sep, target = target.partition("@")
if sep:
repo = channel
tag = target
exact = True
elif channel in REPOS:
repo = channel
else:
tag = channel
exact = True
if re.match(r"\d\.\d+\.\d+", tag):
tag = "v" + tag
try:
path_repo = REPOS[repo or "stable"]
except KeyError:
raise exception.StopExtraction("Invalid channel '%s'", repo)
path_tag = tag if tag == "latest" else "tags/" + tag
url = "{}/repos/{}/releases/{}".format( url = "{}/repos/{}/releases/{}".format(
self.root_api, REPOS[repo], tag) self.root_api, path_repo, path_tag)
headers = { headers = {
"Accept": "application/vnd.github+json", "Accept": "application/vnd.github+json",
"User-Agent": util.USERAGENT, "User-Agent": util.USERAGENT,
"X-GitHub-Api-Version": "2022-11-28", "X-GitHub-Api-Version": "2022-11-28",
} }
data = self.request(url, headers=headers).json() data = self.request(url, headers=headers, notfound="tag").json()
data["_check"] = (self.groups[0] == "check") data["_check"] = check
data["_exact"] = exact
url = "{}/{}/releases/download/{}/{}".format( url = "{}/{}/releases/download/{}/{}".format(
self.root, REPOS[repo], data["tag_name"], BINARIES[repo][binary]) self.root, path_repo, data["tag_name"], BINARIES[repo][binary])
yield Message.Directory, data yield Message.Directory, data
yield Message.Url, url, data yield Message.Url, url, data

Loading…
Cancel
Save