-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'Leviaria/main' into fork/Leviaria/main
- Loading branch information
Showing
5 changed files
with
108 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import subprocess | ||
import sys | ||
from time import sleep | ||
|
||
from loguru import logger | ||
|
||
|
||
def _is_branch_late() -> bool: | ||
subprocess.run( | ||
["git", "fetch"], check=True, capture_output=True, text=True | ||
) | ||
|
||
status = subprocess.run( | ||
["git", "status", "-uno"], | ||
capture_output=True, | ||
text=True, | ||
check=True, | ||
).stdout | ||
return "Your branch is up to date" not in status | ||
|
||
|
||
def _check_and_pull_updates() -> None: | ||
if not _is_branch_late(): | ||
return | ||
|
||
should_update = input( | ||
"New updates available. Do you want to update the bot? [y]/n: " | ||
) | ||
if should_update.lower() not in ["y", "yes", ""]: | ||
return | ||
subprocess.run(["git", "pull"], check=True, capture_output=True, text=True) | ||
|
||
|
||
def check_and_pull_updates() -> None: | ||
try: | ||
_check_and_pull_updates() | ||
except subprocess.CalledProcessError as e: | ||
if "not a git repository" in e.stderr: | ||
err = "We recommend getting the project using git." | ||
err += "You won't be able to get any updates until you do." | ||
logger.warning(err) | ||
sleep(3) | ||
return | ||
logger.error(f"Error while checking / pulling updates: {e.stderr}") | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters