Last active
October 31, 2018 12:47
-
-
Save fepegar/4c5ce2f5c068f90a6a95e886fbee7177 to your computer and use it in GitHub Desktop.
Script I use to upgrade 3D Slicer on macOS using brew
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
#!/usr/bin/env python3 | |
""" | |
This script prints out the revision number and bitstream ID of the latest | |
nightly build of 3D Slicer. | |
""" | |
import re | |
import sys | |
from sys import platform as _platform | |
import urllib.request # https://stackoverflow.com/a/22279013 | |
from bs4 import BeautifulSoup # https://stackoverflow.com/a/10974140 | |
slicerURL = 'http://download.slicer.org' | |
## Get download URL | |
response = urllib.request.urlopen(slicerURL) | |
html = response.read() | |
parsed = BeautifulSoup(html, "html.parser") | |
o = parsed.findAll('a') | |
if _platform == "linux" or _platform == "linux2": # linux | |
button = o[6] | |
elif _platform == "darwin": # MAC OS X | |
button = o[5] | |
elif _platform == "win32": # Windows | |
button = o[4] | |
downloadURL = slicerURL + button.get('href') | |
buttonText = button.getText() | |
p = r'revision (\d+)' | |
revisionNumberString = re.findall(p, buttonText)[0] | |
n1 = revisionNumberString | |
n2 = downloadURL.split('/')[-1] | |
if len(sys.argv) == 2 and sys.argv[1] == '-cask': # TODO: use argparse | |
print(f'cask-repair --cask-version 4.11.0.{n1},{n2}' | |
' --fail-on-error --blind-submit slicer-nightly') | |
else: | |
print(n1, n2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment