Update README.rst

feat(setup): add updater to setup
This commit is contained in:
Romain J 2021-01-19 11:40:49 +01:00
parent e5c3f1b8de
commit 98b82e680e
3 changed files with 44 additions and 2 deletions

View file

@ -13,6 +13,8 @@ install-dev:
$(VENV)/bin/pip install -r dev.requirements.txt
update:
$(VENV)/bin/pip install --upgrade --force-reinstall .
update_soft:
$(VENV)/bin/pip install --upgrade .
# Blackify code
reformat:

View file

@ -1,4 +1,4 @@
|image0| |image1| |image2|
|image0| |image1| |image2| |image3|
.. role:: bash(code)
:language: bash
@ -87,4 +87,6 @@ To update the whole bot after a :bash:`git pull`, just execute
.. |image0| image:: https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-%23007ec6
.. |image1| image:: https://img.shields.io/badge/dynamic/json?color=%23dfb317&label=issues&query=%24.open_issues_count&suffix=%20open&url=https%3A%2F%2Fgit.gnous.eu%2Fapi%2Fv1%2Frepos%2FGnousEU%2Ftuxbot-bot%2F
.. |image2| image:: https://img.shields.io/badge/code%20style-black-000000.svg
.. |image2| image:: https://img.shields.io/badge/code%20style-black-000000.svg
.. |image3| image:: https://wakatime.com/badge/github/Rom1-J/tuxbot-bot.svg
:target: https://wakatime.com/badge/github/Rom1-J/tuxbot-bot

View file

@ -1,11 +1,14 @@
import argparse
import importlib
import json
import logging
import os
import re
import sys
from argparse import Namespace
from pathlib import Path
from typing import Union, List
from urllib.request import urlopen
from rich.prompt import Prompt, IntPrompt
from rich.console import Console
@ -13,6 +16,7 @@ from rich.rule import Rule
from rich.style import Style
from rich.traceback import install
from tuxbot import version_info
from tuxbot.core.config import set_for, set_for_key
from tuxbot.logging import formatter
from tuxbot.core.utils.data_manager import config_dir, app_dir, cogs_data_path
@ -396,6 +400,30 @@ def basic_setup() -> None:
)
def update() -> None:
response = (
urlopen(
"https://api.github.com/repos/Rom1-J/tuxbot-bot/commits/master"
)
.read()
.decode("utf-8")
)
json_response = json.loads(response)
if json_response.get("sha")[:6] == version_info.build:
print(
"Nothing to update, you can run `tuxbot [instance_name]` "
"to start the bot"
)
else:
print(f"Updating to {json_response.get('sha')[:6]}...")
os.popen("/usr/bin/git pull")
print("Done!")
def parse_cli_flags(args: list) -> Namespace:
"""Parser for cli values.
@ -423,6 +451,12 @@ def parse_cli_flags(args: list) -> Namespace:
nargs="+",
help="Execute setup to additional configs",
)
parser.add_argument(
"-U",
"--update",
action="store_true",
help="Check for update",
)
args = parser.parse_args(args)
@ -433,6 +467,10 @@ def setup() -> None:
cli_flags = parse_cli_flags(sys.argv[1:])
try:
if cli_flags.update:
update()
sys.exit()
# Create a new instance.
level = logging.DEBUG
base_logger = logging.getLogger("tuxbot")