Skip to content

Instantly share code, notes, and snippets.

@zlalanne
Created March 12, 2020 12:05
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 zlalanne/ed498e967949260889bc0b9b21bcab7c to your computer and use it in GitHub Desktop.
Save zlalanne/ed498e967949260889bc0b9b21bcab7c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
Usage:
dev_installccs [OPTIONS] <ccs_version>
dev_installccs (--help|-h)
dev_installccs (--version|-v)
Options:
"""
import atexit
import shutil
import subprocess
import sys
import tempfile
import docopt
import tqdm
import requests
URL = "/{}/{}.tar.gz"
def main():
# Create temporary directory for saving installer
tempws = tempfile.mkdtemp()
atexit.register(shutil.rmtree, tempws)
url = URL
# Streaming, so we can iterate over the response.
res = requests.get(url, stream=True)
if res.status_code == 404:
sys.stderr.write("Testing\n")
sys.exit(1)
# Total size in bytes
total_size = int(res.headers.get("content-length", 0))
block_size = 1024
progress = tqdm.tdqm(total=total_size, unit="iB", unit_scale=True)
with open("test.dat", "wb") as installer_fh:
for data in res.iter_content(block_size):
progress.update(len(data))
installer_fh.write(data)
progress.close()
# Extract the installer
shutil.unpack_archive("ccs.tgz.", extract_dir=tempws)
# Run the installer
subprocess.run([
tempws + "/ccs_setup", "--prefix", "ccs{}"
], check=True)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment