Skip to content

Commit

Permalink
Change update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jayktaylor committed Mar 7, 2018
1 parent 901bb04 commit 9e69a7d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
0 runbot.bat → run.bat
100755 → 100644
File renamed without changes.
0 runbot_linux_mac.sh → run.sh
100755 → 100644
File renamed without changes.
4 changes: 2 additions & 2 deletions update_deps_win.bat → update.bat
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ if '%errorlevel%' NEQ '0' (
CD /d "%~dp0"

IF EXIST %SYSTEMROOT%\py.exe (
CMD /k %SYSTEMROOT%\py.exe -3 -m pip install --upgrade -r requirements.txt
CMD /k %SYSTEMROOT%\py.exe -3 update.py
EXIT
)

python --version > NUL 2>&1
IF %ERRORLEVEL% NEQ 0 GOTO nopython

CMD /k python -m pip install --upgrade -r requirements.txt
CMD /k python update.py
GOTO end

:nopython
Expand Down
65 changes: 65 additions & 0 deletions update.py
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()
2 changes: 1 addition & 1 deletion update_deps_linux_mac.sh → update.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ python3.5 -V > /dev/null 2>&1 || {
exit 1; }

cd "$(dirname "$BASH_SOURCE")"
python3.5 -m pip install --upgrade -r requirements.txt
python3.5 update.py

0 comments on commit 9e69a7d

Please sign in to comment.