s4ros icon

atomupdate.py

s4ros | PRO | 11/29/17 05:45:25 PM UTC | 0 ⭐ | 350 👁️ | Never ⏰ | []
Python |

1.32 KB

|

None

|

0 👍

/

0 👎

# Check the Atom installed version VS stable version available on homepage
# Program requirements:
# - linux env
# - pip install requests
# - wget installed
 
import requests
import re
import subprocess
 
download_url = 'https://github.com/atom/atom/releases/download/vVVV/atom-amd64.deb'
 
if __name__ == "__main__":
    r = requests.get('https://atom.io/releases')
    m = re.search('https://github.com/atom/atom/releases/tag/v\d+\.\d+\.\d+', r.text)
    if m:
        web_version = m.group(0).split('/')[7].replace('v', '')
        local_version = subprocess.check_output(["atom", "--version"])
        local_version = local_version.splitlines()[0]
        local_version = ' '.join(local_version.split())
        local_version = local_version.split(' ')[2]
 
        if local_version != web_version:
            print("New version available - {}. Atom will be updated.".format(web_version))
            url = download_url.replace('VVV', web_version)
            print(url)
            ret = subprocess.call(['wget', '-c', '-O', '/tmp/atom.deb', url])
            if ret == 0:
                print("Atom downloaded to /tmp/atom.deb")
                ret = subprocess.call(['sudo', 'apt', 'install', '-yq', '/tmp/atom.deb'])
                if ret == 0:
                  subprocess.call(['rm', '-rf', '/tmp/atom.deb'])

Comments