summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archey.py105
1 files changed, 50 insertions, 55 deletions
diff --git a/archey.py b/archey.py
index fef4e23..bb010b1 100644
--- a/archey.py
+++ b/archey.py
@@ -5,72 +5,67 @@ from subprocess import Popen, PIPE
# Define colors.
# Uncomment whatever color scheme you prefer.
-clear = "\x1b[0m" # clear [Do NOT comment out]
+clear = '\x1b[0m' # clear [Do NOT comment out]
-# color = "\x1b[1;30m" # black
-# color2 = "\x1b[0;30m" # black
+# color = '\x1b[1;30m' # black
+# color2 = '\x1b[0;30m' # black
-# color = "\x1b[1;31m" # red
-# color2 = "\x1b[0;30m" # red
+# color = '\x1b[1;31m' # red
+# color2 = '\x1b[0;30m' # red
-# color = "\x1b[1;32m" # green
-# color2 = "\x1b[0;32m" # green
+# color = '\x1b[1;32m' # green
+# color2 = '\x1b[0;32m' # green
-# color = "\x1b[1;33m" # yellow
-# color2 = "\x1b[0;33m" # yellow
+# color = '\x1b[1;33m' # yellow
+# color2 = '\x1b[0;33m' # yellow
-color = "\x1b[1;34m" # blue [Default]
-color2 = "\x1b[0;34m" # blue [Default]
+color = '\x1b[1;34m' # blue [Default]
+color2 = '\x1b[0;34m' # blue [Default]
-# color = "\x1b[1;35m" # magenta
-# color2 = "\x1b[0;35m" # magenta
+# color = '\x1b[1;35m' # magenta
+# color2 = '\x1b[0;35m' # magenta
-# color = "\x1b[1;36m" # cyan
-# color2 = "\x1b[0;36m" # cyan
+# color = '\x1b[1;36m' # cyan
+# color2 = '\x1b[0;36m' # cyan
-# color = "\x1b[1;37m" # white
-# color2 = "\x1b[0;37m" # white
+# color = '\x1b[1;37m' # white
+# color2 = '\x1b[0;37m' # white
# Define arrays containing values.
list = []
blank = ['']*10
# Find running processes.
-p1 = Popen(['ps', '-A'], stdout=PIPE)
-p2 = Popen(["awk", '{print $4}'], stdin=p1.stdout, stdout=PIPE)
-processes = p2.communicate()[0].split("\n")
-p1 = p2 = None
+p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n')
+processes = [process.split()[3] for process in p1 if process]
+p1 = None
# Print coloured key with normal value.
def output(key, value):
- output = "%s%s:%s %s" % (color, key, clear, value)
+ output = '%s%s:%s %s' % (color, key, clear, value)
list.append(output)
# Define operating system.
def os_display():
- p1 = Popen(['uname', '-m'],stdout=PIPE)
- arch = p1.communicate()[0].rstrip("\n")
- os = "Arch Linux %s" % arch
+ arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n')
+ os = 'Arch Linux %s' % (arch)
output('OS', os)
# Define kernel.
def kernel_display():
- kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip("\n")
+ kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n')
output ('Kernel', kernel)
# Define uptime.
def uptime_display():
- p1 = Popen(['uptime'], stdout=PIPE)
- p2 = Popen(['sed', '-e', 's/^.*up //', "-e", 's/, *[0-9]*.users.*//'], stdin=p1.stdout, stdout=PIPE)
- uptime = p2.communicate()[0].rstrip("\n")
+ p1 = Popen(['uptime'], stdout=PIPE).communicate()[0].lstrip().split(' ')
+ uptime = ' '.join(p1[2:(p1.index(''))]).rstrip(',')
output ('Uptime', uptime)
- p1 = p2 = None
# Define battery. [Requires: acpi]
def battery_display():
- p1 = Popen(['acpi'], stdout=PIPE)
- p2 = Popen(['sed', 's/.*, //'], stdin=p1.stdout, stdout=PIPE)
- battery = p2.communicate()[0].rstrip("\n")
+ p1 = Popen(['acpi'], stdout=PIPE).communicate()[0].lstrip()
+ battery = p1.split(' ')[3].rstrip('\n')
output ('Battery', battery)
# Define desktop environment.
@@ -108,36 +103,37 @@ def wm_display():
def packages_display():
p1 = Popen(['pacman', '-Q'], stdout=PIPE)
p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE)
- packages = p2.communicate()[0].rstrip("\n")
+ packages = p2.communicate()[0].rstrip('\n')
output ('Packages', packages)
-# Define root partition information.
-def fs_display():
- # Display root filesystem information.
- p1 = Popen(['df', '-Th'], stdout=PIPE)
- p2 = Popen(['grep', "/$"], stdin=p1.stdout, stdout=PIPE)
- p3 = Popen(['awk', '{print $4" / "$3}'], stdin=p2.stdout, stdout=PIPE)
- root = p3.communicate()[0].rstrip("\n")
+# Define root file system information.
+def rootfs_display():
+ p1 = Popen(['df', '-Th'], stdout=PIPE).communicate()[0]
+ drives = [line for line in p1.split('\n') if line]
+ for line in drives:
+ if line.endswith('/'):
+ root = line.split()[3]
+ break
output ('Root', root)
-# Define home partition information.
-def home_display():
- # Display home filesystem information.
- p1 = Popen(['df', '-Th'], stdout=PIPE)
- p2 = Popen(['grep', "/home$"], stdin=p1.stdout, stdout=PIPE)
- p3 = Popen(['awk', '{print $4" / "$3}'], stdin=p2.stdout, stdout=PIPE)
- home = p3.communicate()[0].rstrip("\n")
- output ('Home', home)
-
+# Define home file system information.
+def homefs_display():
+ p1 = Popen(['df', '-Th'], stdout=PIPE).communicate()[0]
+ drives = [line for line in p1.split('\n') if line]
+ for line in drives:
+ if line.endswith('/home'):
+ home = line.split()[3]
+ break
+ output ('home', home)
# Values to display.
-# Possible Options [Enabled by default]: os, kernel, uptime, de, wm, packages, fs
-# Possible Options [Disabled by default]: battery, home
-display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs' ]
+# Possible Options [Enabled by default]: os, kernel, uptime, de, wm, packages, rootfs
+# Possible Options [Disabled by default]: battery, homefs
+display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'rootfs']
# Run functions found in 'display' array.
for x in display:
- funcname=x+"_display"
+ funcname=x+'_display'
func=locals()[funcname]
func()
@@ -165,4 +161,3 @@ print """%s
%s ##' '##
%s #' `# %s
""" % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear)
-