Skip to content

Instantly share code, notes, and snippets.

@MarkBaggett
Last active October 18, 2022 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkBaggett/1d57c358480afb05cca3b287aa1adfca to your computer and use it in GitHub Desktop.
Save MarkBaggett/1d57c358480afb05cca3b287aa1adfca to your computer and use it in GitHub Desktop.
SEC673 Workshop Setup Check
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