#!/usr/bin/env python
## Python script for checking and installing latest version of atom editor in Linux
## Russell B
import subprocess, os, platform, sys
import requests as rq
from bs4 import BeautifulSoup as bs
path =
if platform.system() == 'Linux':
system = 'Linux'
else:
print('Currently, none other than Linux is supported')
sys.exit()
def get_sys_arch_name():
arch = platform.architecture()
os_name = platform.version()
osn = ''
exen = ''
if subprocess.call('dpkg --help', shell=True) == 0:
osn = 'Debian family'
exen = 'atom-amd64.deb'
elif subprocess.call('rpm --help', shell=True) == 0:
osn = 'Redhat family'
exen = 'atom.x86_64.rpm'
elif subprocess.call('dnf --help', shell=True) == 0:
osn = 'Fedora family'
exen = 'atom.x86_64.rpm'
else:
pass
return (arch, osn, exen)
def get_ins_version(system_details):
atom_v_ = subprocess.Popen('atom --version', shell=True, stdout=subprocess.PIPE)
atom_v = (atom_v_.stdout.readline()).strip()
return str(atom_v[10:int(len(atom_v))])
def get_cur_version():
latest_url = 'https://github.com/atom/atom/releases/latest'
resp = rq.get(latest_url)
soup = bs(resp.text, 'html5lib')
release_v = soup.head.title
return release_v.string[8:14]
sys_info = get_sys_arch_name()
ins_ver = get_ins_version(sys_info)
cur_ver = get_cur_version()
if sys_info[1] == 'Debian family':
atom_url = 'https://github.com/atom/atom/releases/download/v'+str(cur_ver)+'/'+str(sys_info[2])
elif sys_info[1] == 'Fedora family' or osn[1] == 'Redhat family':
atom_url = 'https://github.com/atom/atom/releases/download/v'+str(cur_ver)+'/'+str(sys_info[2])
else:
pass
if ins_ver == cur_ver:
print('Current installed version is the latest version and the version is ', get_latest_version())
else:
print('Current installed version is '+str(ins_ver)+'\n'+'The latest version is '+str(cur_ver))
print('\nUpdate will be downloaded now...')
if os.path.exists(os.path.join(path, str(cur_ver))):
print('Directory exists for donwloading...\nChanging to the download directory...')
os.chdir(os.path.join(path, str(cur_ver)))
else:
print('Directory does not exist and will be created.')
ret_val = subprocess.Popen(['mkdir', '-p', your location+str(cur_ver)])
ret_val.wait()
print('Changing to the downloaded direcotry...')
os.chdir(os.path.join(path, str(cur_ver)))
print('Downloading begins...')
download = subprocess.Popen(['wget', '-c', '-P', your location+str(cur_ver), '--progress=dot', str(atom_url)])
download.wait()
print('Download successfull!')
if sys_info[1] == 'Debian family':
print('Installation begins:\n')
ret_val = subprocess.Popen(['xterm', '-e', 'sudo', 'dpkg', '-i', str(sys_info[2])], shell=True, stdout=subprocess.PIPE)
ins_stat = ret_val.wait()
if ins_stat == 0:
print('Atom editor - '+str(cur_ver)+' has been installed successfully')
else:
print('Installation unsuccessful: Please inspect the error message')
elif sys_info[1] == 'Fedora family':
print('Installation begins:\n')
ret_val = subprocess.Popen(['xterm', '-e','sudo', 'dnf', 'install', str(sys_info[2])], shell=True, stdout=subprocess.PIPE)
ins_stat = ret_val.wait()
if ins_stat == 0:
print('Atom editor - '+str(cur_ver)+' has been installed successfully')
else:
print('Installation unsuccessful: Please inspect the error message')
elif sys_info[1] == 'Redhat family':
print('Installation begins:\n')
# ret_val = os.system('xterm -c \ sudo rpm -Uivh '+str(sys_info[2]))
ret_val = subprocess.Popen(['xterm', '-e', 'sudo', 'rpm', '-Uivh', str(sys_info[2])], shell=True, stdout=subprocess.PIPE)
ins_stat = ret_val.wait()
if ins_stat == 0:
print('Atom editor - '+str(cur_ver)+' has been installed successfully')
else:
print('Installation unsuccessful: Please inspect the error message')
## Python script for checking and installing latest version of atom editor in Linux
## Russell B
import subprocess, os, platform, sys
import requests as rq
from bs4 import BeautifulSoup as bs
path =
if platform.system() == 'Linux':
system = 'Linux'
else:
print('Currently, none other than Linux is supported')
sys.exit()
def get_sys_arch_name():
arch = platform.architecture()
os_name = platform.version()
osn = ''
exen = ''
if subprocess.call('dpkg --help', shell=True) == 0:
osn = 'Debian family'
exen = 'atom-amd64.deb'
elif subprocess.call('rpm --help', shell=True) == 0:
osn = 'Redhat family'
exen = 'atom.x86_64.rpm'
elif subprocess.call('dnf --help', shell=True) == 0:
osn = 'Fedora family'
exen = 'atom.x86_64.rpm'
else:
pass
return (arch, osn, exen)
def get_ins_version(system_details):
atom_v_ = subprocess.Popen('atom --version', shell=True, stdout=subprocess.PIPE)
atom_v = (atom_v_.stdout.readline()).strip()
return str(atom_v[10:int(len(atom_v))])
def get_cur_version():
latest_url = 'https://github.com/atom/atom/releases/latest'
resp = rq.get(latest_url)
soup = bs(resp.text, 'html5lib')
release_v = soup.head.title
return release_v.string[8:14]
sys_info = get_sys_arch_name()
ins_ver = get_ins_version(sys_info)
cur_ver = get_cur_version()
if sys_info[1] == 'Debian family':
atom_url = 'https://github.com/atom/atom/releases/download/v'+str(cur_ver)+'/'+str(sys_info[2])
elif sys_info[1] == 'Fedora family' or osn[1] == 'Redhat family':
atom_url = 'https://github.com/atom/atom/releases/download/v'+str(cur_ver)+'/'+str(sys_info[2])
else:
pass
if ins_ver == cur_ver:
print('Current installed version is the latest version and the version is ', get_latest_version())
else:
print('Current installed version is '+str(ins_ver)+'\n'+'The latest version is '+str(cur_ver))
print('\nUpdate will be downloaded now...')
if os.path.exists(os.path.join(path, str(cur_ver))):
print('Directory exists for donwloading...\nChanging to the download directory...')
os.chdir(os.path.join(path, str(cur_ver)))
else:
print('Directory does not exist and will be created.')
ret_val = subprocess.Popen(['mkdir', '-p', your location+str(cur_ver)])
ret_val.wait()
print('Changing to the downloaded direcotry...')
os.chdir(os.path.join(path, str(cur_ver)))
print('Downloading begins...')
download = subprocess.Popen(['wget', '-c', '-P', your location+str(cur_ver), '--progress=dot', str(atom_url)])
download.wait()
print('Download successfull!')
if sys_info[1] == 'Debian family':
print('Installation begins:\n')
ret_val = subprocess.Popen(['xterm', '-e', 'sudo', 'dpkg', '-i', str(sys_info[2])], shell=True, stdout=subprocess.PIPE)
ins_stat = ret_val.wait()
if ins_stat == 0:
print('Atom editor - '+str(cur_ver)+' has been installed successfully')
else:
print('Installation unsuccessful: Please inspect the error message')
elif sys_info[1] == 'Fedora family':
print('Installation begins:\n')
ret_val = subprocess.Popen(['xterm', '-e','sudo', 'dnf', 'install', str(sys_info[2])], shell=True, stdout=subprocess.PIPE)
ins_stat = ret_val.wait()
if ins_stat == 0:
print('Atom editor - '+str(cur_ver)+' has been installed successfully')
else:
print('Installation unsuccessful: Please inspect the error message')
elif sys_info[1] == 'Redhat family':
print('Installation begins:\n')
# ret_val = os.system('xterm -c \ sudo rpm -Uivh '+str(sys_info[2]))
ret_val = subprocess.Popen(['xterm', '-e', 'sudo', 'rpm', '-Uivh', str(sys_info[2])], shell=True, stdout=subprocess.PIPE)
ins_stat = ret_val.wait()
if ins_stat == 0:
print('Atom editor - '+str(cur_ver)+' has been installed successfully')
else:
print('Installation unsuccessful: Please inspect the error message')
Comments
Post a Comment