mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-14 07:04:51 -04:00
Automatically update and show release notes
This commit is contained in:
parent
b804be4bfb
commit
246d69cb30
1 changed files with 34 additions and 3 deletions
37
rip/cli.py
37
rip/cli.py
|
@ -18,6 +18,7 @@ logging.basicConfig(level="WARNING")
|
||||||
logger = logging.getLogger("streamrip")
|
logger = logging.getLogger("streamrip")
|
||||||
|
|
||||||
outdated = False
|
outdated = False
|
||||||
|
newest_version = __version__
|
||||||
|
|
||||||
|
|
||||||
class DownloadCommand(Command):
|
class DownloadCommand(Command):
|
||||||
|
@ -86,11 +87,38 @@ class DownloadCommand(Command):
|
||||||
|
|
||||||
update_check.join()
|
update_check.join()
|
||||||
if outdated:
|
if outdated:
|
||||||
|
import subprocess
|
||||||
|
import re
|
||||||
|
|
||||||
self.line(
|
self.line(
|
||||||
"<info>A new version of streamrip is available! Run</info> "
|
f"<info>Updating streamrip to <title>v{newest_version}</title>...</info>\n"
|
||||||
"<cmd>pip3 install streamrip --upgrade to update</cmd>"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# update in background
|
||||||
|
update_p = subprocess.Popen(
|
||||||
|
["pip3", "install", "streamrip", "--upgrade"],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
)
|
||||||
|
|
||||||
|
md_header = re.compile(r"#\s+(.+)")
|
||||||
|
bullet_point = re.compile(r"-\s*(.+)")
|
||||||
|
code = re.compile(r"`([^`]+)`")
|
||||||
|
issue_reference = re.compile(r"(#\d+)")
|
||||||
|
|
||||||
|
release_notes = requests.get(
|
||||||
|
"https://api.github.com/repos/nathom/streamrip/releases/latest"
|
||||||
|
).json()["body"]
|
||||||
|
|
||||||
|
release_notes = md_header.sub(r"<header>\1</header>", release_notes)
|
||||||
|
release_notes = bullet_point.sub(r"<options=bold>•</> \1", release_notes)
|
||||||
|
release_notes = code.sub(r"<cmd>\1</cmd>", release_notes)
|
||||||
|
release_notes = issue_reference.sub(r"<options=bold>\1</>", release_notes)
|
||||||
|
|
||||||
|
self.line(release_notes)
|
||||||
|
|
||||||
|
update_p.wait()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -448,6 +476,7 @@ class Application(BaseApplication):
|
||||||
formatter.set_style("path", Style("green", options=["bold"]))
|
formatter.set_style("path", Style("green", options=["bold"]))
|
||||||
formatter.set_style("cmd", Style("magenta"))
|
formatter.set_style("cmd", Style("magenta"))
|
||||||
formatter.set_style("title", Style("yellow", options=["bold"]))
|
formatter.set_style("title", Style("yellow", options=["bold"]))
|
||||||
|
formatter.set_style("header", Style("yellow", options=["bold", "underline"]))
|
||||||
io.output.set_formatter(formatter)
|
io.output.set_formatter(formatter)
|
||||||
io.error_output.set_formatter(formatter)
|
io.error_output.set_formatter(formatter)
|
||||||
|
|
||||||
|
@ -491,8 +520,10 @@ def clean_options(*opts):
|
||||||
|
|
||||||
def is_outdated():
|
def is_outdated():
|
||||||
global outdated
|
global outdated
|
||||||
|
global newest_version
|
||||||
r = requests.get("https://pypi.org/pypi/streamrip/json").json()
|
r = requests.get("https://pypi.org/pypi/streamrip/json").json()
|
||||||
outdated = r["info"]["version"] != __version__
|
newest_version = r["info"]["version"]
|
||||||
|
outdated = newest_version != __version__
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue