Skip to content

Commit

Permalink
Added Solus, fixed #3.
Browse files Browse the repository at this point in the history
Solus is now available to be used with pyupdate, have yet to test extensively. Changed the readme to reflect changes in script.
  • Loading branch information
CodyKank committed Jan 13, 2017
1 parent 4c8baa1 commit 67bd802
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 32 deletions.
42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
#Pyupdate
**Pyupdate** is a small project created to learn the subprocess module and practice using python 3.
The script will probe your system to find the distribution, desktop environment, CPU, and memory
usage. If I think of anything else useful I may end up adding that as well (disk usage?). Cuurently
the script is targeted at the popular distros and their updating schemes. So, the supported distros
are: Arch, Debian, RHEL. This also includes distros based on those, as long as they are using the
default package manger their parent distro uses (pacman, yum, and dpkg/apt-get).
* The sys-info isn't all too appealing right now. I'm hoping I change that.
**Pyupdate** is a small project to ease the troubles of keeping a system up to date.
The script attempts to make it easy to update a good portion of Linux distributions.
Python 3 is the future of Python, and it is installed on most bleeding edge style
distros and so it was the choice for this project. It will record the last update
if the update was applied through Pyupdate, and display it before updating again.
It works on the principle of inheritance, that most distributions are based on another.
Look at Debian for example, there are hundreds of different distros based off Debian alone.
Thus, this script will search in itself for the detected distribution and find what it is
based off of and use that package manager to update the system. The supported distros are as
follows:

* Must be using Arch, Debian, or RHEL (and their children distros) for this to work. See above.
####Supported Derived distributions
| Distro | Derived From |
| --------------- | ---------------- |
| Ubuntu | Debian |
| Xubuntu | Debian |
| GalliumOs | Debian |
| Elementary | Debian |
| Antergos | Arch |
| Manjaro | Arch |
| Fedora | RHEL |
| CentOs | RHEL |
| Scientific | RHEL |

* Must have python 3 installed, with the subprocess module (should be there by default).
####Supported Independent/Parent distributions
| Distro | Supported |
| --------------- | ---------------- |
| RHEL | Yes |
| Arch | Yes |
| Debian | Yes |
| Solus | Yes |

####Requirements
* Must have Python 3 installed
* Must have one of the above distributions of Linux.
52 changes: 29 additions & 23 deletions python_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

"""//////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// Python 3 Linux System Update Script \\
// Cody Kankel \\
// Cody Kankel \\
|| Started Jul 11, 2016 ||
|| Last update: September 14th, 2016 ||
|| Last update: Jan 12th, 2016 ||
\\Currently only supports debian/ubuntu distros with apt-get, and Arch based distros with pacman.//
\\ !RHEL based distros have not been tested yet! //
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\///////////////////////////////////////////////"""
Expand All @@ -28,7 +28,7 @@ def main():
show_sys_info(user_response)
sys.exit()
#^----------------------------------------------------------------------------- main()

def get_last_update(user_name):
"""Method to obtain previous update, path is specified as update_file.
If the file is not found, assuming this is the first time running the script.
Expand All @@ -48,32 +48,37 @@ def update(user_name):
"""Method which actually updates the system. Checks if system is Arch, Debian, etc.
then properly updates the system. For Arch systems, performs full system upgrade."""
system = get_system_type()

if system != 'Unknown':

print("System identified as, or based on: {0}".format(system))
print("Proceeding to update system. . .")

if system == 'arch':
pacman = subprocess.Popen(['sudo', 'pacman', '-Syyu'])
pacman.wait()
save_update(user_name)
print("\nUpdate complete. . .\n")
elif system == 'debian':
apt_update = subprocess.Popen(['sudo', 'apt-get', 'update'])
apt_update = subprocess.Popen(['sudo', 'apt-get', '-y', 'update'])
apt_update.communicate() #making the script wait
apt_update.wait()
apt_upgrade = subprocess.Popen(['sudo', 'apt-get', 'dist-upgrade'])
apt_upgrade = subprocess.Popen(['sudo', 'apt-get', '-y', 'dist-upgrade'])
apt_upgrade.wait()
apt_remove = subprocess.Popen(['sudo', 'apt-get', 'autoremove'])
apt_remove = subprocess.Popen(['sudo', 'apt-get', '-y', 'autoremove'])
apt_remove.wait()
save_update(user_name)
print("Update complete. . .")
elif system == 'rhel':
yum = subprocess.Popen(['su', '-c', 'yum', 'update'])
yum = subprocess.Popen(['su', '-c', 'yum', '-y', 'update'])
yum.wait()
save_update(user_name)
print("Update complete. . .")
elif system == 'solus':
update = subprocess.Popen((['sudo', '-S', 'eopkg', '-y', 'up']))
update.wait()
save_update(user_name)
print("Update complete. . .")
else:
print("\nSystem is not recognized currently. If you feel as if this is an error,\n"\
+ "please report it on Github.\n")
Expand All @@ -85,21 +90,22 @@ def get_system_type():
etc. Will look for the ID in /etc/os-release. This means it will discover Antergos, Manjaro
and others as Arch, and Xubuntu, Ubuntu, and others as Debian, and Scientific, CentOs, Fedora
and others as Red Hat. Method returns the base system as a string."""

system_id = (subprocess.getoutput("cat /etc/os-release | grep 'ID='")).split('\n')[0]
system_id = system_id.replace('"','') # Some systems produce (")'s others do not!
system_id = system_id[system_id.find('=') + 1:]

# switch statement wanna-be
distro_choices = {'fedora': 'rhel', 'centos': 'rhel', 'scientific': 'rhel', 'rhel': 'rhel', \
'debian': 'debian', 'ubuntu': 'debian', 'xubuntu': 'debian', 'galliumos': 'debian', \
'arch': 'arch', 'antergos': 'arch', 'manjaro': 'arch'}
'elementary': 'debian', 'arch': 'arch', 'antergos': 'arch', 'manjaro': 'arch', \
'solus': 'solus'}
default = 'Unknown'
system = distro_choices.get(system_id, default)
if system == default:
system_id = subprocess.getoutput("cat /etc/os-release | grep'ID_LIKE=").split('\n')[0]
system_id = system_id.replace('"', '')

return system
#^----------------------------------------------------------------------------- find_system_type()

Expand All @@ -124,35 +130,35 @@ def no_update(yn):
def show_sys_info(yn):
"""Showing some info, plan to add more. Currently shows:
Number of Cores, CPU"""

print("_".center(80, '_')) #Filling screen with line
print("Printing System Info".center(80,'.')+ '\n')
print("Printing System Info".center(80,'.')+ '\n')
cpu_proc = subprocess.getoutput("lscpu | grep 'Model name:'")
cpu_name = " ".join((cpu_proc.split()[2:]))
cores_proc = subprocess.getoutput("lscpu | grep 'CPU(s):'")
cores = cores_proc.split()[1]
arch = subprocess.getoutput("uname -m")


mem_free_proc = subprocess.getoutput("free -h")
temp = mem_free_proc.split()
total_mem = temp[7]
used_mem = temp[8]
free_mem = temp[9]
cached_mem = temp[11]

print_info("CPU:", cpu_name)
print_info("NUM CORES:", cores)
print_info("ARCHITECTURE:", arch)
print_seperator()

print("MEMORY USAGE:".center(80))
print_info("TOTAL MEMORY:", total_mem)
print_info("USED MEMORY:", used_mem)
print_info("CACHED MEMORY:", cached_mem)
print_info("FREE MEMORY:", free_mem)
print_seperator()

show_gui_info()
return
#^----------------------------------------------------------------------------- show_sys_info(yn)
Expand All @@ -163,15 +169,15 @@ def show_gui_info():
option = subprocess.getoutput("echo $GDMSESSION")
distro = subprocess.getoutput("cat /etc/os-release | grep 'PRETTY'")
distro = distro.split('=')[1].replace('"', '') # Grabbing just the pretty-name

print("DESKTOP INFO:".center(80))
print_info("DISTRIBUTION:", distro)
print_info("SESSION:", option)
print_info("DESKTOP ENVIRONMENT:", desktop_environment)
print_seperator()
return
#^----------------------------------------------------------------------------- show_gui_info()

def print_info(str_name, result):
"""Prints the information given as the str_name to be the designator and result being what
the designator will be. (free mem = str_name, 4K = result)"""
Expand All @@ -184,8 +190,8 @@ def print_seperator():
"""Simply prints a separator on screen with periods. 80 chars long."""
print(".".center(80, '.'))
return
#^----------------------------------------------------------------------------- print_separator()
#^----------------------------------------------------------------------------- print_separator()

#Standard broiler plate to run as main
#Standard broiler plate to run as main
if __name__ == '__main__':
main()

0 comments on commit 67bd802

Please sign in to comment.