-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
901bb04
commit 9e69a7d
Showing
5 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
0
runbot.bat → run.bat
100755 → 100644
File renamed without changes.
0
runbot_linux_mac.sh → run.sh
100755 → 100644
File renamed without changes.
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,65 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
def y_n(q): | ||
while True: | ||
ri = input('{} (y/n): '.format(q)) | ||
if ri.lower() in ['yes', 'y']: return True | ||
elif ri.lower() in ['no', 'n']: return False | ||
|
||
def main(): | ||
print('Starting...') | ||
|
||
# Make sure that we're in a Git repository | ||
if not os.path.isdir('.git'): | ||
raise EnvironmentError("This isn't a Git repository.") | ||
|
||
# Make sure that we can actually use Git on the command line | ||
# because some people install Git Bash without allowing access to Windows CMD | ||
try: | ||
subprocess.check_call('git --version', shell=True, stdout=subprocess.DEVNULL) | ||
except subprocess.CalledProcessError: | ||
raise EnvironmentError("Couldn't use Git on the CLI. You will need to run 'git pull' yourself.") | ||
|
||
print("Passed Git checks...") | ||
|
||
# Check that the current working directory is clean | ||
sp = subprocess.check_output('git status --porcelain', shell=True, encoding='utf-8', universal_newlines=True) | ||
if sp: | ||
oshit = y_n('You have modified files that are tracked by Git (e.g the bot\'s source files).\n' | ||
'We can try to reset your folder to a clean version for you. Continue?') | ||
if oshit: | ||
try: | ||
subprocess.check_call('git reset --hard', shell=True) | ||
except subprocess.CalledProcessError: | ||
raise OSError("Could not reset the directory to a clean state.") | ||
else: | ||
print('Okay. Cancelling update process for now.') | ||
return | ||
|
||
print("Attempting to update the bot using Git...") | ||
|
||
try: | ||
subprocess.check_call('git pull', shell=True) | ||
except subprocess.CalledProcessError: | ||
raise OSError("Could not update the bot. You will need to run 'git pull' yourself.") | ||
|
||
print("Attempting to update dependencies...") | ||
|
||
try: | ||
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-U', '-r', 'requirements.txt'], shell=True) | ||
except subprocess.CalledProcessError: | ||
raise OSError("Could not update dependencies. You will need to run '{0} -m pip install -U -r requirements.txt' yourself.".format(sys.executable)) | ||
|
||
|
||
try: | ||
from musicbot.constants import VERSION | ||
print('MusicBot is at version {0}'.format(VERSION)) | ||
except Exception: | ||
pass | ||
|
||
print("Done!") | ||
|
||
if __name__ == '__main__': | ||
main() |
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