Created
October 21, 2022 19:02
-
-
Save MarkBaggett/eafe6b0f892abab3ab659ee34548d1c2 to your computer and use it in GitHub Desktop.
SEC673 Workshop Setup Checks
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
import sys | |
import subprocess | |
import webbrowser | |
import time | |
import urllib.request | |
import tempfile | |
import zipfile | |
import pathlib | |
from io import BytesIO | |
def cmd(cmdline): | |
return subprocess.run(cmdline,shell=True,capture_output=True).stdout.decode() | |
if sys.version_info < (3,7): | |
print("You will need Python version 3.7 or later. Python 3.10 is recommended.") | |
time.sleep(1) | |
webbrowser.open("https://www.python.org/") | |
sys.exit(1) | |
else: | |
print("Python 3.7 or later found!") | |
try: | |
import pyWars | |
except: | |
print("The pyWars module was not found. Attempting to install it now.") | |
else: | |
print("Your machine looks ready to go! Be sure you have a good text editor. Microsoft Visual Code with the python extension is recommended but not required.") | |
sys.exit(0) | |
try: | |
import pip | |
except: | |
print("You need to install pip to proceed. On Debian/Ubuntu based systems this is usually accomplished by 'apt install python3-pip'.") | |
time.sleep(1) | |
webbrowser.open("https://pip.pypa.io/en/stable/installation/") | |
sys.exit(1) | |
else: | |
print("Attempting to install the required pyWars module for you.") | |
with tempfile.TemporaryDirectory() as tmpdirname: | |
try: | |
pywars_url = 'https://github.com/MarkBaggett/pyWars/archive/refs/heads/master.zip' | |
with urllib.request.urlopen(pywars_url) as f: | |
zip_file = f.read() | |
except Exception as e: | |
print("Unable to download pywars client.") | |
print("Install 'git' and manually installation it with 'pip install git+https://github.com/markbaggett'") | |
sys.exit(1) | |
try: | |
with zipfile.ZipFile(BytesIO(zip_file),"r") as zip_ref: | |
zip_ref.extractall(tmpdirname) | |
except Exception as e: | |
print("Unable to extract the zip file.") | |
print("Install 'git' and manually installation it with 'pip install git+https://github.com/markbaggett'") | |
sys.exit(1) | |
install_path = pathlib.Path(tmpdirname) / "pyWars-master" | |
install_cmd = f"{sys.executable} -m pip install {install_path}" | |
cmd(install_cmd) | |
try: | |
import pyWars | |
except: | |
print("The automated setup has failed.") | |
print("To participate in the workshop you need:\n - Python 3.7 or greater\n - A text editor of some sorts (Visual Studio Code is recommended)\n - The pyWars module installed in Python") | |
time.sleep(1) | |
webbrowser.open("https://github.com/MarkBaggett/pywars") | |
else: | |
print("Your machine looks ready to go! Be sure you have a good text editor. Microsoft Visual Code with the python extension is recommended but not required.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment