Last active
          June 3, 2019 15:30 
        
      - 
      
- 
        Save noahpeltier/18d4ccf85cc0c48c57946cff65b97b1a to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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/python3.7 | |
| """ | |
| This will determin your OS version | |
| and download the appropriate copy to a directory | |
| """ | |
| import os | |
| import sys | |
| import platform | |
| import urllib.request | |
| def Windows_EtcherDownload(): | |
| url = 'https://github.com/balena-io/etcher/releases/download/v1.5.43/balenaEtcher-Portable-1.5.43.exe' | |
| # let's break up the url and get a file name | |
| parsedurl = urllib.request.urlparse(url) | |
| filename = os.path.basename(parsedurl.path) | |
| savepath = os.path.join('C:/temp', filename) | |
| print("Saving file to", savepath) | |
| urllib.request.urlretrieve(url, savepath) | |
| print("Finished Downloading\nRunning", filename) | |
| os.system(savepath) | |
| def Linux_EtcherDownload(): | |
| url = 'https://github.com/balena-io/etcher/releases/download/v1.5.43/balena-etcher-electron-1.5.43-linux-x64.zip' | |
| """ | |
| little different for Linux | |
| Have to expand home directory and join it all together | |
| """ | |
| parsedurl = urllib.request.urlparse(url) | |
| filename = os.path.basename(parsedurl.path) | |
| savepath = (os.path.join(os.path.expanduser('~'),'Downloads',filename)) | |
| print("Saving file to", savepath) | |
| urllib.request.urlretrieve(url, savepath) | |
| print("Finished Downloading\nRunning", filename) | |
| os.system(savepath) | |
| # Running our function after OS check | |
| print("Detecting OS") | |
| platform = sys.platform | |
| print("OS is",platform) | |
| if platform == 'linux': | |
| Linux_EtcherDownload() | |
| exit() | |
| if platform == 'win32': | |
| Windows_EtcherDownload() | |
| exit() | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment