Skip to content

Instantly share code, notes, and snippets.

@lashomb
Last active December 28, 2015 01:19
Show Gist options
  • Select an option

  • Save lashomb/7419958 to your computer and use it in GitHub Desktop.

Select an option

Save lashomb/7419958 to your computer and use it in GitHub Desktop.
First attempt at installing something with python
#/usr/bin/python
import os, requests
node_path = "/usr/local/bin/node"
node_url = "http://nodejs.org/dist/v0.10.21/node-v0.10.21.pkg"
os.chdir("/Users/Shared")
def download_file(url):
pkg_name = url.split('/')[-1]
r = requests.get(url, stream=True)
with open(pkg_name, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
return pkg_name
package = os.path.realpath(download_file(node_url))
if not os.path.exists(node_path):
from subprocess import call
call(["/usr/sbin/installer", "-pkg", package, "-target", "/"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment