From ecd9c11bf52e2d0a2aab25f8d2c095d42f5ce19b Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Sun, 17 Jan 2010 14:44:55 -0800 Subject: replaced ps -A with ps -u --- archey | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/archey b/archey index 9bae108..b8ffeab 100644 --- a/archey +++ b/archey @@ -13,6 +13,7 @@ import subprocess, optparse, re from subprocess import Popen, PIPE from optparse import OptionParser +from getpass import getuser # Display [Comment/Uncomment to Enable/Disable information.] display = [ @@ -78,19 +79,20 @@ wm_dict = {'awesome': 'Awesome', 'xfwm4': 'Xfwm', 'xmonad': 'xmonad'} -sh_dict = {'zsh': 'Z-Shell', +sh_dict = {'zsh': 'Zsh', 'bash': 'Bash', 'dash': 'Dash', 'fish': 'Fish', - 'ksh': 'Korn Shell', - 'jsh': 'Job control shell', - 'tcsh': 'The C Shell'} + 'ksh': 'Ksh', + 'csh': 'Csh', + 'jsh': 'Jsh', + 'tcsh': 'Tcsh'} # Find running processes. def xmonadfix(str): if re.compile("xmonad").match(str): return "xmonad" return str -p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') +p1 = Popen(['ps', '-u', getuser()], stdout=PIPE).communicate()[0].split('\n') processes = map(xmonadfix, [process.split()[3] for process in p1 if process]) p1 = None @@ -99,7 +101,6 @@ def output(key, value): output = '%s%s:%s %s' % (color, key, clear, value) result.append(output) - # RAM Function def ram_display(): raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].split('\n') @@ -109,8 +110,9 @@ def ram_display(): # Screenshot Function screen = '%s' % options.screenshot + def screenshot(): - subprocess.check_call(['scrot', '-cd5']) + subprocess.check_call(['scrot', '-cd5']) # Operating System Function def os_display(): @@ -134,7 +136,7 @@ def cpu_display(): cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) output ('CPU', cpuinfo) -# Uptime Function +# Upscrottime Function def uptime_display(): fuptime = int(open('/proc/uptime').read().split('.')[0]) day = int(fuptime / 86400) @@ -209,7 +211,7 @@ for x in display: func() # Array containing values. -result.extend(['']*(15 - len(display))) +result.extend(['']*(16 - len(display))) ###### Result ####### print """%s @@ -229,9 +231,9 @@ print """%s %s #########. .########` %s %s ######' '###### %s %s ;#### ####; %s -%s ##' '## +%s ##' '## %s %s #' `# -%s """ % (color, color, color, result[0], color, result[1], color, result[2], color, result[3], color, result[4], color, result[5], color, result[6], color, color2, color, result[7], color, color2, color, result[8], color, color2, result[9], color2, result[10], color2, result[11], color2, result[12], color2, result[13], color2, result[14], color2, color2, clear) +%s """ % (color, color, color, result[0], color, result[1], color, result[2], color, result[3], color, result[4], color, result[5], color, result[6], color, color2, color, result[7], color, color2, color, result[8], color, color2, result[9], color2, result[10], color2, result[11], color2, result[12], color2, result[13], color2, result[14], color2, result[15], color2, clear) if screen == 'True': screenshot() -- cgit v1.2.3-54-g00ecf From 77deabd4d15e35e3dde02bc7286964d18abd9a4f Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Sun, 17 Jan 2010 14:52:16 -0800 Subject: cleanup --- archey | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/archey b/archey index b8ffeab..06daf8d 100644 --- a/archey +++ b/archey @@ -103,14 +103,13 @@ def output(key, value): # RAM Function def ram_display(): - raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].split('\n') - ram = ''.join(filter(re.compile('M').search, raminfo)).split() - used = int(ram[2]) - int(ram[5]) - int(ram[6]) - output ('RAM', '%s MB / %s MB' % (used, ram[1])) + raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].split('\n') + ram = ''.join(filter(re.compile('M').search, raminfo)).split() + used = int(ram[2]) - int(ram[5]) - int(ram[6]) + output ('RAM', '%s MB / %s MB' % (used, ram[1])) # Screenshot Function screen = '%s' % options.screenshot - def screenshot(): subprocess.check_call(['scrot', '-cd5']) @@ -132,11 +131,11 @@ def hostname_display(): # CPU Function def cpu_display(): - file = open('/proc/cpuinfo').readlines() - cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) - output ('CPU', cpuinfo) + file = open('/proc/cpuinfo').readlines() + cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) + output ('CPU', cpuinfo) -# Upscrottime Function +# Uptime Function def uptime_display(): fuptime = int(open('/proc/uptime').read().split('.')[0]) day = int(fuptime / 86400) -- cgit v1.2.3-54-g00ecf From 5e7b77694c12fccf68568df32e468638ea3b3556 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Sun, 17 Jan 2010 20:54:38 -0800 Subject: replaced scrot with imagemagick import --- archey | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/archey b/archey index 06daf8d..4bb95f9 100644 --- a/archey +++ b/archey @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# archey [version 0.1-7] +# archey [version 0.1-8] # # Maintained by Melik Manukyan # Distributed under the terms of the GNU General Public License v3. @@ -10,10 +10,11 @@ # Along with basic system information. # Import libraries -import subprocess, optparse, re +import sys, subprocess, optparse, re from subprocess import Popen, PIPE from optparse import OptionParser from getpass import getuser +from time import ctime, sleep # Display [Comment/Uncomment to Enable/Disable information.] display = [ @@ -111,7 +112,15 @@ def ram_display(): # Screenshot Function screen = '%s' % options.screenshot def screenshot(): - subprocess.check_call(['scrot', '-cd5']) + print 'Taking shot in', + list = range(1,6) + list.reverse() + for x in list: + print '%s..' % x, + sys.stdout.flush() + sleep(1) + subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.png']) + print 'Say Cheeze!' # Operating System Function def os_display(): -- cgit v1.2.3-54-g00ecf From 3a5bc347b86c0c04ec96baa949524fbad181db46 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Sun, 17 Jan 2010 20:55:38 -0800 Subject: fixed typo --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 4bb95f9..d005638 100644 --- a/archey +++ b/archey @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# archey [version 0.1-8] +# archey [version 0.1-9] # # Maintained by Melik Manukyan # Distributed under the terms of the GNU General Public License v3. -- cgit v1.2.3-54-g00ecf From 5ffb614ee83013c42f5170a7741a09227c75e17a Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 25 Jan 2010 13:18:30 -0800 Subject: minor cleanup, added support for scrotwm --- archey | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/archey b/archey index d005638..e81aca1 100644 --- a/archey +++ b/archey @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# archey [version 0.1-9] +# archey [version 0.1-10] # # Maintained by Melik Manukyan # Distributed under the terms of the GNU General Public License v3. @@ -39,8 +39,8 @@ result = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.') - parser.add_option('-c', + parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.', version="%prog 0.1.10") + parser.add_option('-c', action='store', default='blue', type='choice', dest='color', choices=('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'), help='choose a color: black, red, green, yellow, blue, magenta, cyan, white [Default: blue]') parser.add_option('-s', '--screenshot', action='store_true', dest='screenshot', help='take a screenshot') @@ -75,6 +75,7 @@ wm_dict = {'awesome': 'Awesome', 'musca': 'Musca', 'openbox': 'Openbox', 'pekwm': 'PekWM', + 'scrotwm': 'ScrotWM', 'wmaker': 'Window Maker', 'wmii': 'wmii', 'xfwm4': 'Xfwm', @@ -119,8 +120,8 @@ def screenshot(): print '%s..' % x, sys.stdout.flush() sleep(1) - subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.png']) print 'Say Cheeze!' + subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.png']) # Operating System Function def os_display(): @@ -171,14 +172,14 @@ def de_display(): de = 'None found' for key in de_dict.keys(): if key in processes: de = de_dict[key] - output ('DE', de) + output ('Desktop Enviornment', de) # Window Manager Function def wm_display(): wm = 'None found' for key in wm_dict.keys(): if key in processes: wm = wm_dict[key] - output ('WM', wm) + output ('Window Manager', wm) # Shell Function def sh_display(): -- cgit v1.2.3-54-g00ecf From 360fc44a2f66bb51414f642a9480cce6cdf840fc Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 25 Jan 2010 16:23:44 -0800 Subject: cleanup --- archey | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/archey b/archey index e81aca1..8bae15c 100644 --- a/archey +++ b/archey @@ -28,7 +28,7 @@ display = [ 'packages', # Display Number of Packages Installed 'ram', # Display RAM Usage 'cpu', # Display CPU Model - 'sh', # Display Current Shell + 'sh', # Display Current Shell # 'fs:/boot', # Display /boot Partition Usage # 'fs:/home', # Display /home Partition Usage # 'fs:/MOUNT/POINT', # Display * Partition, Edit To Your Needs @@ -72,8 +72,8 @@ wm_dict = {'awesome': 'Awesome', 'icewm': 'IceWM', 'kwin': 'KWin', 'metacity': 'Metacity', - 'musca': 'Musca', - 'openbox': 'Openbox', + 'musca': 'Musca', + 'openbox': 'Openbox', 'pekwm': 'PekWM', 'scrotwm': 'ScrotWM', 'wmaker': 'Window Maker', @@ -172,7 +172,7 @@ def de_display(): de = 'None found' for key in de_dict.keys(): if key in processes: de = de_dict[key] - output ('Desktop Enviornment', de) + output ('Desktop Environment', de) # Window Manager Function def wm_display(): @@ -183,10 +183,10 @@ def wm_display(): # Shell Function def sh_display(): - sh = 'None found' - for key in processes: - if key in sh_dict.keys(): sh = sh_dict[key] - output ('Shell', sh) + sh = 'None found' + for key in processes: + if key in sh_dict.keys(): sh = sh_dict[key] + output ('Shell', sh) # Packages Function def packages_display(): -- cgit v1.2.3-54-g00ecf From e584c91e41d97e465236a0b0f1b28392bd5b4fd7 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 25 Jan 2010 16:25:03 -0800 Subject: removed xfce-mcs-manager (depreciated) support --- archey | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/archey b/archey index 8bae15c..92d6687 100644 --- a/archey +++ b/archey @@ -58,8 +58,7 @@ clear = '\x1b[0m' # Define processes for identifying Desktop Environmentss, Window Managers, Shells. de_dict = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', - 'xfce-mcs-manager': 'Xfce 4', - 'xfconfd': 'Xfce 4.6'} + 'xfconfd': 'Xfce'} wm_dict = {'awesome': 'Awesome', 'beryl': 'Beryl', -- cgit v1.2.3-54-g00ecf From b413ab592534db63b28d5ad9aa4f77252120eeed Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Wed, 27 Jan 2010 20:52:19 -0800 Subject: major cleanup, updated shell function --- archey | 261 +++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 131 insertions(+), 130 deletions(-) diff --git a/archey b/archey index 92d6687..97b43d8 100644 --- a/archey +++ b/archey @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# archey [version 0.1-10] +# archey [version 0.1-11] # # Maintained by Melik Manukyan # Distributed under the terms of the GNU General Public License v3. @@ -10,7 +10,7 @@ # Along with basic system information. # Import libraries -import sys, subprocess, optparse, re +import os, sys, subprocess, optparse, re from subprocess import Popen, PIPE from optparse import OptionParser from getpass import getuser @@ -18,89 +18,92 @@ from time import ctime, sleep # Display [Comment/Uncomment to Enable/Disable information.] display = [ - 'os', # Display Operating System - 'hostname', # Display Machine Hostname - 'kernel', # Display Kernel Version -# 'battery', # Display Battery Usage [Requires 'acpi'] - 'uptime', # Display System Uptime - 'wm', # Display Window Manager - 'de', # Display Desktop Environment - 'packages', # Display Number of Packages Installed - 'ram', # Display RAM Usage - 'cpu', # Display CPU Model - 'sh', # Display Current Shell -# 'fs:/boot', # Display /boot Partition Usage -# 'fs:/home', # Display /home Partition Usage -# 'fs:/MOUNT/POINT', # Display * Partition, Edit To Your Needs - 'fs:/' # Display / Partition Usage - ] + 'os', # Display Operating System + 'hostname', # Display Machine Hostname + 'kernel', # Display Kernel Version +# 'battery', # Display Battery Usage [Requires 'acpi'] + 'uptime', # Display System Uptime + 'wm', # Display Window Manager + 'de', # Display Desktop Environment + 'packages', # Display Number of Packages Installed + 'ram', # Display RAM Usage + 'cpu', # Display CPU Model + 'sh', # Display Current Shell +# 'fs:/boot', # Display /boot Partition Usage +# 'fs:/home', # Display /home Partition Usage +# 'fs:/MOUNT/POINT', # Display * Partition, Edit To Your Needs + 'fs:/' # Display / Partition Usage + ] # Array containing Values result = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.', version="%prog 0.1.10") - parser.add_option('-c', - action='store', default='blue', type='choice', dest='color', choices=('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'), help='choose a color: black, red, green, yellow, blue, magenta, cyan, white [Default: blue]') - parser.add_option('-s', '--screenshot', - action='store_true', dest='screenshot', help='take a screenshot') - (options, args) = parser.parse_args() + parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.', version="%prog 0.1.11") + parser.add_option('-c', + action='store', default='blue', type='choice', dest='color', choices=('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'), help='choose a color: black, red, green, yellow, blue, magenta, cyan, white [Default: blue]') + parser.add_option('-s', '--screenshot', + action='store_true', dest='screenshot', help='take a screenshot') + (options, args) = parser.parse_args() # Define colors colorscheme = '%s' % options.color colors = {'black': '0', 'red': '1', 'green': '2', 'yellow': '3', 'blue': '4', 'magenta': '5', 'cyan': '6', 'white': '7'} for key in colors.keys(): - if key in colorscheme: colorcode = colors[key] + if key in colorscheme: colorcode = colors[key] color = '\x1b[1;3%sm' % colorcode color2 = '\x1b[0;3%sm' % colorcode clear = '\x1b[0m' # Define processes for identifying Desktop Environmentss, Window Managers, Shells. -de_dict = {'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfconfd': 'Xfce'} +de_dict = { + 'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfconfd': 'Xfce'} -wm_dict = {'awesome': 'Awesome', - 'beryl': 'Beryl', - 'blackbox': 'Blackbox', - 'compiz': 'Compiz', - 'dwm': 'DWM', - 'enlightenment': 'Enlightenment', - 'fluxbox': 'Fluxbox', - 'fvwm': 'FVWM', - 'icewm': 'IceWM', - 'kwin': 'KWin', - 'metacity': 'Metacity', - 'musca': 'Musca', - 'openbox': 'Openbox', - 'pekwm': 'PekWM', - 'scrotwm': 'ScrotWM', - 'wmaker': 'Window Maker', - 'wmii': 'wmii', - 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad'} - -sh_dict = {'zsh': 'Zsh', - 'bash': 'Bash', - 'dash': 'Dash', - 'fish': 'Fish', - 'ksh': 'Ksh', - 'csh': 'Csh', - 'jsh': 'Jsh', - 'tcsh': 'Tcsh'} +wm_dict = { + 'awesome': 'Awesome', + 'beryl': 'Beryl', + 'blackbox': 'Blackbox', + 'compiz': 'Compiz', + 'dwm': 'DWM', + 'enlightenment': 'Enlightenment', + 'fluxbox': 'Fluxbox', + 'fvwm': 'FVWM', + 'icewm': 'IceWM', + 'kwin': 'KWin', + 'metacity': 'Metacity', + 'musca': 'Musca', + 'openbox': 'Openbox', + 'pekwm': 'PekWM', + 'scrotwm': 'ScrotWM', + 'wmaker': 'Window Maker', + 'wmii': 'wmii', + 'xfwm4': 'Xfwm', + 'xmonad': 'xmonad'} + +sh_dict = { + 'zsh': 'Zsh', + 'bash': 'Bash', + 'dash': 'Dash', + 'fish': 'Fish', + 'ksh': 'Ksh', + 'csh': 'Csh', + 'jsh': 'Jsh', + 'tcsh': 'Tcsh'} # Find running processes. def xmonadfix(str): - if re.compile("xmonad").match(str): return "xmonad" - return str + if re.compile("xmonad").match(str): return "xmonad" + return str p1 = Popen(['ps', '-u', getuser()], stdout=PIPE).communicate()[0].split('\n') processes = map(xmonadfix, [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) - result.append(output) + output = '%s%s:%s %s' % (color, key, clear, value) + result.append(output) # RAM Function def ram_display(): @@ -112,111 +115,109 @@ def ram_display(): # Screenshot Function screen = '%s' % options.screenshot def screenshot(): - print 'Taking shot in', - list = range(1,6) - list.reverse() - for x in list: - print '%s..' % x, - sys.stdout.flush() - sleep(1) - print 'Say Cheeze!' - subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.png']) + print 'Taking shot in', + list = range(1,6) + list.reverse() + for x in list: + print '%s..' % x, + sys.stdout.flush() + sleep(1) + print 'Say Cheeze!' + subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.png']) # Operating System Function def os_display(): - arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') - os = 'Arch Linux %s' % (arch) - output('OS', os) + arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') + os = 'Arch Linux %s' % (arch) + output('OS', os) # Kernel Function def kernel_display(): - kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') - output ('Kernel', kernel) + kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') + output ('Kernel', kernel) # Hostname Function def hostname_display(): - hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].rstrip('\n') - output ('Hostname', hostname) + hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].rstrip('\n') + output ('Hostname', hostname) # CPU Function def cpu_display(): - file = open('/proc/cpuinfo').readlines() - cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) - output ('CPU', cpuinfo) + file = open('/proc/cpuinfo').readlines() + cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) + output ('CPU', cpuinfo) # Uptime Function def uptime_display(): - fuptime = int(open('/proc/uptime').read().split('.')[0]) - day = int(fuptime / 86400) - fuptime = fuptime % 86400 - hour = int(fuptime / 3600) - fuptime = fuptime % 3600 - minute = int(fuptime / 60) - uptime = '' - if day == 1: - uptime += '%d day, ' % day - if day > 1: - uptime += '%d days, ' % day - uptime += '%d:%02d' % (hour, minute) - output('Uptime', uptime) + fuptime = int(open('/proc/uptime').read().split('.')[0]) + day = int(fuptime / 86400) + fuptime = fuptime % 86400 + hour = int(fuptime / 3600) + fuptime = fuptime % 3600 + minute = int(fuptime / 60) + uptime = '' + if day == 1: + uptime += '%d day, ' % day + if day > 1: + uptime += '%d days, ' % day + uptime += '%d:%02d' % (hour, minute) + output('Uptime', uptime) # Battery Function [Requires: acpi] def battery_display(): - p1 = Popen(['acpi'], stdout=PIPE).communicate()[0].lstrip() - battery = p1.split(' ')[3].rstrip('\n') - output ('Battery', battery) + p1 = Popen(['acpi'], stdout=PIPE).communicate()[0].lstrip() + battery = p1.split(' ')[3].rstrip('\n') + output ('Battery', battery) # Desktop Environment Function def de_display(): - de = 'None found' - for key in de_dict.keys(): - if key in processes: de = de_dict[key] - output ('Desktop Environment', de) + de = 'None found' + for key in de_dict.keys(): + if key in processes: de = de_dict[key] + output ('Desktop Environment', de) # Window Manager Function def wm_display(): - wm = 'None found' - for key in wm_dict.keys(): - if key in processes: wm = wm_dict[key] - output ('Window Manager', wm) + wm = 'None found' + for key in wm_dict.keys(): + if key in processes: wm = wm_dict[key] + output ('Window Manager', wm) # Shell Function def sh_display(): - sh = 'None found' - for key in processes: - if key in sh_dict.keys(): sh = sh_dict[key] - output ('Shell', sh) + sh = os.getenv("SHELL").split('/')[-1].capitalize() + output ('Shell', sh) # Packages Function def packages_display(): - p1 = Popen(['pacman', '-Q'], stdout=PIPE) - p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) - packages = p2.communicate()[0].rstrip('\n') - output ('Packages', packages) + p1 = Popen(['pacman', '-Q'], stdout=PIPE) + p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) + packages = p2.communicate()[0].rstrip('\n') + output ('Packages', packages) # File System Function def fs_display(mount=''): - p1 = Popen(['df', '-TPh', mount], stdout=PIPE).communicate()[0] - used = [line for line in p1.split('\n') if line][1] - used = used.split()[3] - total = [line for line in p1.split('\n') if line][1] - total = total.split()[2] - type = [line for line in p1.split('\n') if line][1] - type = type.split()[1] - if mount == '/': mount = '/root' - fs = mount.rpartition('/')[2].title() + " FS" - part = '%s / %s (%s)' % (used, total, type) - output (fs, part) + p1 = Popen(['df', '-TPh', mount], stdout=PIPE).communicate()[0] + used = [line for line in p1.split('\n') if line][1] + used = used.split()[3] + total = [line for line in p1.split('\n') if line][1] + total = total.split()[2] + type = [line for line in p1.split('\n') if line][1] + type = type.split()[1] + if mount == '/': mount = '/root' + fs = mount.rpartition('/')[2].title() + " FS" + part = '%s / %s (%s)' % (used, total, type) + output (fs, part) # Run functions found in 'display' array. for x in display: - call = [arg for arg in x.split(':') if arg] - funcname=call[0] + '_display' - func=locals()[funcname] - if len(call) > 1: - func(arg) - else: - func() + call = [arg for arg in x.split(':') if arg] + funcname=call[0] + '_display' + func=locals()[funcname] + if len(call) > 1: + func(arg) + else: + func() # Array containing values. result.extend(['']*(16 - len(display))) @@ -244,4 +245,4 @@ print """%s %s """ % (color, color, color, result[0], color, result[1], color, result[2], color, result[3], color, result[4], color, result[5], color, result[6], color, color2, color, result[7], color, color2, color, result[8], color, color2, result[9], color2, result[10], color2, result[11], color2, result[12], color2, result[13], color2, result[14], color2, result[15], color2, clear) if screen == 'True': - screenshot() + screenshot() -- cgit v1.2.3-54-g00ecf From 92c4c570b1aafef830b9c918470c510e9d90f417 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Wed, 27 Jan 2010 20:54:04 -0800 Subject: converted remaining tabs to spaces --- archey | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/archey b/archey index 97b43d8..55a3f76 100644 --- a/archey +++ b/archey @@ -107,10 +107,10 @@ def output(key, value): # RAM Function def ram_display(): - raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].split('\n') - ram = ''.join(filter(re.compile('M').search, raminfo)).split() - used = int(ram[2]) - int(ram[5]) - int(ram[6]) - output ('RAM', '%s MB / %s MB' % (used, ram[1])) + raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].split('\n') + ram = ''.join(filter(re.compile('M').search, raminfo)).split() + used = int(ram[2]) - int(ram[5]) - int(ram[6]) + output ('RAM', '%s MB / %s MB' % (used, ram[1])) # Screenshot Function screen = '%s' % options.screenshot -- cgit v1.2.3-54-g00ecf From feb84f31dddcff9ce059ab4f0013dfe91448f120 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Thu, 8 Apr 2010 07:06:08 -0700 Subject: Added support for ratpoison --- archey | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/archey b/archey index 55a3f76..3b0c5e1 100644 --- a/archey +++ b/archey @@ -6,8 +6,7 @@ # Distributed under the terms of the GNU General Public License v3. # See http://www.gnu.org/licenses/gpl.txt for the full license text. # -# Simple python script to display an Archlinux logo in ASCII art -# Along with basic system information. +# System information tool for Archlinux written in python. # Import libraries import os, sys, subprocess, optparse, re @@ -76,6 +75,7 @@ wm_dict = { 'musca': 'Musca', 'openbox': 'Openbox', 'pekwm': 'PekWM', + 'ratpoison': 'ratpoison', 'scrotwm': 'ScrotWM', 'wmaker': 'Window Maker', 'wmii': 'wmii', @@ -123,7 +123,7 @@ def screenshot(): sys.stdout.flush() sleep(1) print 'Say Cheeze!' - subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.png']) + subprocess.check_call([scrot]) # Operating System Function def os_display(): -- cgit v1.2.3-54-g00ecf From 299e37de539d90730c57fd24bba983e16b0cef3f Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Thu, 8 Apr 2010 09:25:00 -0700 Subject: Fixed screenshot function. --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 3b0c5e1..f6ac7a9 100644 --- a/archey +++ b/archey @@ -123,7 +123,7 @@ def screenshot(): sys.stdout.flush() sleep(1) print 'Say Cheeze!' - subprocess.check_call([scrot]) + subprocess.check_call(['scrot']) # Operating System Function def os_display(): -- cgit v1.2.3-54-g00ecf From f745a4c36b8955eb0d6183a99faf3c394d7bac8c Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Fri, 4 Jun 2010 12:49:50 -0700 Subject: Added support for i3 window manager. --- archey | 1 + 1 file changed, 1 insertion(+) diff --git a/archey b/archey index f6ac7a9..1dde179 100644 --- a/archey +++ b/archey @@ -69,6 +69,7 @@ wm_dict = { 'enlightenment': 'Enlightenment', 'fluxbox': 'Fluxbox', 'fvwm': 'FVWM', + 'i3': 'i3', 'icewm': 'IceWM', 'kwin': 'KWin', 'metacity': 'Metacity', -- cgit v1.2.3-54-g00ecf From c18d179001f263392ac11c43b45bc9916f2a83ee Mon Sep 17 00:00:00 2001 From: DjMelik Date: Sun, 13 Jun 2010 22:41:45 -0700 Subject: updated fs_display function --- archey | 62 +++++++++++++++++++++++++++----------------------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/archey b/archey index 1dde179..64b0e58 100644 --- a/archey +++ b/archey @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# archey [version 0.1-11] +# archey [version 0.2.1] # # Maintained by Melik Manukyan # Distributed under the terms of the GNU General Public License v3. @@ -20,7 +20,6 @@ display = [ 'os', # Display Operating System 'hostname', # Display Machine Hostname 'kernel', # Display Kernel Version -# 'battery', # Display Battery Usage [Requires 'acpi'] 'uptime', # Display System Uptime 'wm', # Display Window Manager 'de', # Display Desktop Environment @@ -28,17 +27,15 @@ display = [ 'ram', # Display RAM Usage 'cpu', # Display CPU Model 'sh', # Display Current Shell -# 'fs:/boot', # Display /boot Partition Usage -# 'fs:/home', # Display /home Partition Usage -# 'fs:/MOUNT/POINT', # Display * Partition, Edit To Your Needs - 'fs:/' # Display / Partition Usage + 'fs' # Display / Partition Usage ] + # Array containing Values result = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.', version="%prog 0.1.11") + parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.', version="%prog 0.2.1") parser.add_option('-c', action='store', default='blue', type='choice', dest='color', choices=('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'), help='choose a color: black, red, green, yellow, blue, magenta, cyan, white [Default: blue]') parser.add_option('-s', '--screenshot', @@ -164,12 +161,6 @@ def uptime_display(): uptime += '%d:%02d' % (hour, minute) output('Uptime', uptime) -# Battery Function [Requires: acpi] -def battery_display(): - p1 = Popen(['acpi'], stdout=PIPE).communicate()[0].lstrip() - battery = p1.split(' ')[3].rstrip('\n') - output ('Battery', battery) - # Desktop Environment Function def de_display(): de = 'None found' @@ -197,35 +188,36 @@ def packages_display(): output ('Packages', packages) # File System Function -def fs_display(mount=''): - p1 = Popen(['df', '-TPh', mount], stdout=PIPE).communicate()[0] - used = [line for line in p1.split('\n') if line][1] - used = used.split()[3] - total = [line for line in p1.split('\n') if line][1] - total = total.split()[2] - type = [line for line in p1.split('\n') if line][1] - type = type.split()[1] - if mount == '/': mount = '/root' - fs = mount.rpartition('/')[2].title() + " FS" - part = '%s / %s (%s)' % (used, total, type) - output (fs, part) +def fs_display(): + supported = ('ext2', 'ext3', 'ext4', 'reiserfs', 'jfs', 'ntfs', 'fat32') + p1 = Popen(['df', '-TPh'], stdout=PIPE).communicate()[0] + filesystems = p1.rstrip().split('\n') + del filesystems[0] + + for fs in filesystems: + fs_split = fs.split() + used = fs_split[3] + total = fs_split[2] + type = fs_split[1] + name = fs_split[6] + part = '%s / %s (%s)' % (used, total, type) + if name == '/': name = '/root' + fs = name.rpartition('/')[2].title() + " FS" + if type in supported: + output (fs, part) # Run functions found in 'display' array. for x in display: - call = [arg for arg in x.split(':') if arg] - funcname=call[0] + '_display' + funcname=x+'_display' func=locals()[funcname] - if len(call) > 1: - func(arg) - else: - func() + func() # Array containing values. -result.extend(['']*(16 - len(display))) +result.extend(['']*(17 - len(display))) ###### Result ####### print """%s -%s + +%s + %s %s # %s %s ### %s %s ##### %s @@ -242,8 +234,8 @@ print """%s %s ######' '###### %s %s ;#### ####; %s %s ##' '## %s -%s #' `# -%s """ % (color, color, color, result[0], color, result[1], color, result[2], color, result[3], color, result[4], color, result[5], color, result[6], color, color2, color, result[7], color, color2, color, result[8], color, color2, result[9], color2, result[10], color2, result[11], color2, result[12], color2, result[13], color2, result[14], color2, result[15], color2, clear) +%s #' `# %s +%s """ % (color, color, result[0], color, result[1], color, result[2], color, result[3], color, result[4], color, result[5], color, result[6], color, result[7], color, color2, color, result[8], color, color2, color, result[9], color, color2, result[10], color2, result[11], color2, result[12], color2, result[13], color2, result[14], color2, result[15], color2, result[16], color2, result[17], clear) if screen == 'True': screenshot() -- cgit v1.2.3-54-g00ecf From ae29a0391b85298c59a1a3de6792d2a384068648 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Fri, 18 Jun 2010 14:20:35 -0700 Subject: --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 64b0e58..2f17834 100644 --- a/archey +++ b/archey @@ -213,7 +213,7 @@ for x in display: func() # Array containing values. -result.extend(['']*(17 - len(display))) +result.extend(['']*(19 - len(display))) ###### Result ####### print """%s -- cgit v1.2.3-54-g00ecf From d71b07062db3727496da843ee84829998d42173f Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Wed, 23 Jun 2010 18:37:49 -0700 Subject: Updated WM/DE Functions --- archey | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/archey b/archey index 2f17834..a185c63 100644 --- a/archey +++ b/archey @@ -165,15 +165,17 @@ def uptime_display(): def de_display(): de = 'None found' for key in de_dict.keys(): - if key in processes: de = de_dict[key] - output ('Desktop Environment', de) + if key in processes: + de = de_dict[key] + output ('Desktop Environment', de) # Window Manager Function def wm_display(): wm = 'None found' for key in wm_dict.keys(): - if key in processes: wm = wm_dict[key] - output ('Window Manager', wm) + if key in processes: + wm = wm_dict[key] + output ('Window Manager', wm) # Shell Function def sh_display(): @@ -213,7 +215,7 @@ for x in display: func() # Array containing values. -result.extend(['']*(19 - len(display))) +result.extend(['']*(20 - len(display))) ###### Result ####### print """%s -- cgit v1.2.3-54-g00ecf From 5242b3aa17ae229cd7e59ad06eaf8d2661ab323f Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Wed, 23 Jun 2010 18:39:48 -0700 Subject: Void --- archey | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archey b/archey index a185c63..42671f8 100644 --- a/archey +++ b/archey @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# archey [version 0.2.1] +# archey [version 0.2.2] # # Maintained by Melik Manukyan # Distributed under the terms of the GNU General Public License v3. @@ -35,7 +35,7 @@ result = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.', version="%prog 0.2.1") + parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.', version="%prog 0.2.2") parser.add_option('-c', action='store', default='blue', type='choice', dest='color', choices=('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'), help='choose a color: black, red, green, yellow, blue, magenta, cyan, white [Default: blue]') parser.add_option('-s', '--screenshot', -- cgit v1.2.3-54-g00ecf From 92d1ce799bf1aea8aecd4cfee594a42eca69d30d Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Thu, 24 Jun 2010 09:56:23 -0700 Subject: Added support for wmfs and btrfs --- archey | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archey b/archey index 42671f8..9940452 100644 --- a/archey +++ b/archey @@ -76,6 +76,7 @@ wm_dict = { 'ratpoison': 'ratpoison', 'scrotwm': 'ScrotWM', 'wmaker': 'Window Maker', + 'wmfs': 'Wmfs', 'wmii': 'wmii', 'xfwm4': 'Xfwm', 'xmonad': 'xmonad'} @@ -191,7 +192,7 @@ def packages_display(): # File System Function def fs_display(): - supported = ('ext2', 'ext3', 'ext4', 'reiserfs', 'jfs', 'ntfs', 'fat32') + supported = ('ext2', 'ext3', 'ext4', 'reiserfs', 'jfs', 'ntfs', 'fat32', 'btrfs') p1 = Popen(['df', '-TPh'], stdout=PIPE).communicate()[0] filesystems = p1.rstrip().split('\n') del filesystems[0] -- cgit v1.2.3-54-g00ecf From 5a0baf0e553aea4d31570a0b74015e056491ab15 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Thu, 24 Jun 2010 18:12:34 -0700 Subject: Added terminal function --- archey | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/archey b/archey index 9940452..e62d66d 100644 --- a/archey +++ b/archey @@ -27,6 +27,7 @@ display = [ 'ram', # Display RAM Usage 'cpu', # Display CPU Model 'sh', # Display Current Shell + 'term', # Display Current Terminal 'fs' # Display / Partition Usage ] @@ -183,6 +184,11 @@ def sh_display(): sh = os.getenv("SHELL").split('/')[-1].capitalize() output ('Shell', sh) +# Terminal Function +def term_display(): + term = os.getenv("TERM").split('/')[-1].capitalize() + output ('Terminal', term) + # Packages Function def packages_display(): p1 = Popen(['pacman', '-Q'], stdout=PIPE) -- cgit v1.2.3-54-g00ecf From 2cbf832471d7e43ea51f048ea9f069b01c1dae35 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Thu, 24 Jun 2010 18:13:38 -0700 Subject: Minor cleanup --- archey | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archey b/archey index e62d66d..468708a 100644 --- a/archey +++ b/archey @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# archey [version 0.2.2] +# archey [version 0.2.3] # # Maintained by Melik Manukyan # Distributed under the terms of the GNU General Public License v3. @@ -36,7 +36,7 @@ result = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.', version="%prog 0.2.2") + parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.', version="%prog 0.2.3") parser.add_option('-c', action='store', default='blue', type='choice', dest='color', choices=('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'), help='choose a color: black, red, green, yellow, blue, magenta, cyan, white [Default: blue]') parser.add_option('-s', '--screenshot', -- cgit v1.2.3-54-g00ecf From 0c9128fff4b69e79b52ec1d2b049558184edca88 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Mon, 23 Aug 2010 12:46:09 -0700 Subject: added support for Ubuntu --- archey | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 24 deletions(-) diff --git a/archey b/archey index 468708a..4632134 100644 --- a/archey +++ b/archey @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# archey [version 0.2.3] +# archey [version 0.2.4] # # Maintained by Melik Manukyan # Distributed under the terms of the GNU General Public License v3. @@ -9,7 +9,7 @@ # System information tool for Archlinux written in python. # Import libraries -import os, sys, subprocess, optparse, re +import os, sys, subprocess, optparse, re, linecache from subprocess import Popen, PIPE from optparse import OptionParser from getpass import getuser @@ -17,7 +17,7 @@ from time import ctime, sleep # Display [Comment/Uncomment to Enable/Disable information.] display = [ - 'os', # Display Operating System + 'distro', # Display Distribution 'hostname', # Display Machine Hostname 'kernel', # Display Kernel Version 'uptime', # Display System Uptime @@ -36,20 +36,12 @@ result = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the info displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.', version="%prog 0.2.3") - parser.add_option('-c', - action='store', default='blue', type='choice', dest='color', choices=('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'), help='choose a color: black, red, green, yellow, blue, magenta, cyan, white [Default: blue]') + parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.4") parser.add_option('-s', '--screenshot', action='store_true', dest='screenshot', help='take a screenshot') (options, args) = parser.parse_args() -# Define colors -colorscheme = '%s' % options.color -colors = {'black': '0', 'red': '1', 'green': '2', 'yellow': '3', 'blue': '4', 'magenta': '5', 'cyan': '6', 'white': '7'} -for key in colors.keys(): - if key in colorscheme: colorcode = colors[key] -color = '\x1b[1;3%sm' % colorcode -color2 = '\x1b[0;3%sm' % colorcode +# Clear clear = '\x1b[0m' # Define processes for identifying Desktop Environmentss, Window Managers, Shells. @@ -102,7 +94,11 @@ p1 = None # Print coloured key with normal value. def output(key, value): - output = '%s%s:%s %s' % (color, key, clear, value) + if Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE): + ucolor = '\x1b[1;31m' + output ='%s%s:%s %s' % (ucolor, key, clear, value) + if os.path.exists('/etc/arch-release'): + output = '%s%s:%s %s' % (color, key, clear, value) result.append(output) # RAM Function @@ -126,10 +122,15 @@ def screenshot(): subprocess.check_call(['scrot']) # Operating System Function -def os_display(): - arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') - os = 'Arch Linux %s' % (arch) - output('OS', os) +def distro_display(): + arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n' + ) + urelease = linecache.getline('/etc/lsb-release', 2).rstrip('\n').split('=')[1].title() + if Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE).communicate()[0].rstrip('\n'): + distro = 'Ubuntu %s %s' % (urelease, arch) + if os.path.exists('/etc/arch-release'): + distro = 'Arch Linux %s' % arch + output('OS', distro) # Kernel Function def kernel_display(): @@ -191,10 +192,17 @@ def term_display(): # Packages Function def packages_display(): - p1 = Popen(['pacman', '-Q'], stdout=PIPE) - p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) - packages = p2.communicate()[0].rstrip('\n') - output ('Packages', packages) + if Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE): + p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) + p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) + p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) + packages = p3.communicate()[0].rstrip('\n') + output ('Packages', packages) + if os.path.exists('/etc/arch-release'): + p1 = Popen(['pacman', '-Q'], stdout=PIPE) + p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) + packages = p2.communicate()[0].rstrip('\n') + output ('Packages', packages) # File System Function def fs_display(): @@ -225,7 +233,50 @@ for x in display: result.extend(['']*(20 - len(display))) ###### Result ####### -print """%s + +## Ubuntu +# Colors +ucolor = '\x1b[1;33m' +ucolor2 = '\x1b[1;31m' +ucolor3 = '\x1b[0;31m' + +if Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE): + print """ +%s ++++++ %s +%s ++++++++ %s +%s ++++++++++ %s++++++++ %s +%s ++++++++++++ %s++++++++ %s +%s ++ %s++++++++++++ %s++++++ %s +%s +++++ %s++++++++++++ %s**** %s +%s +++++++ %s+++++++++++++++++++ %s +%s +++++++++ %s+++++++++++ %s +%s ++++++++++ %s++++++++++ %s +%s ++++++++ %s++++++++++ %s +%s ++++++ %s++++++ %s++++++++++ %s +%s ++++++++ %s+++++ %s+++++++++ %s +%s +++++++++ %s++++ %s +%s ++++++++ %s+++++ %s+++++++++ %s +%s ++++++ %s++++++ %s++++++++++ %s +%s ++++++++ %s++++++++++ %s +%s +++++++++ %s++++++++++ %s +%s +++++++++ %s++++++++++++ %s +%s +++++++ %s+++++++++++++++++++ +%s +++++ %s++++++++++++ %s,,,, +%s ++ %s++++++++++++ %s++++++ +%s ++++++++++++ %s++++++++ +%s ++++++++++ %s++++++++ +%s ++++++++ +%s ++++++ +%s """ % (ucolor3, result[0], ucolor3, result[1], ucolor2, ucolor3, result[2], ucolor2, ucolor3, result[3], ucolor, ucolor2, ucolor3, result[4], ucolor, ucolor2, ucolor3, result[5], ucolor, ucolor2, result[6], ucolor, ucolor2, result[7], ucolor, ucolor2, result[8], ucolor, ucolor2, result[9], ucolor2, ucolor, ucolor2, result[10], ucolor2, ucolor, ucolor2, result[11], ucolor2, ucolor, result[12], ucolor2, ucolor, ucolor3, result[13], ucolor2, ucolor, ucolor3, result[14], ucolor, ucolor3, result[15], ucolor, ucolor3, result[16], ucolor, ucolor3, ucolor, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor, ucolor, clear) + + +## Arch Linux +# Colors +acolor = '\x1b[1;34m' +acolor2 = '\x1b[0;34m' + +if os.path.exists('/etc/arch-release'): + print """%s %s + %s %s # %s %s ### %s @@ -244,7 +295,7 @@ print """%s %s ;#### ####; %s %s ##' '## %s %s #' `# %s -%s """ % (color, color, result[0], color, result[1], color, result[2], color, result[3], color, result[4], color, result[5], color, result[6], color, result[7], color, color2, color, result[8], color, color2, color, result[9], color, color2, result[10], color2, result[11], color2, result[12], color2, result[13], color2, result[14], color2, result[15], color2, result[16], color2, result[17], clear) +%s """ % (acolor, acolor, result[0], acolor, result[1], acolor, result[2], acolor, result[3], acolor, result[4], acolor, result[5], acolor, result[6], acolor, result[7], acolor, acolor2, acolor, result[8], acolor, acolor2, acolor, result[9], acolor, acolor2, result[10], acolor2, result[11], acolor2, result[12], acolor2, result[13], acolor2, result[14], acolor2, result[15], acolor2, result[16], acolor2, result[17], clear) if screen == 'True': screenshot() -- cgit v1.2.3-54-g00ecf From fc3aa5137bf0fee9349ad659247073dd8999c586 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Mon, 23 Aug 2010 12:57:03 -0700 Subject: Major cleanup --- archey | 75 ++++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/archey b/archey index 4632134..dc4d386 100644 --- a/archey +++ b/archey @@ -84,6 +84,17 @@ sh_dict = { 'jsh': 'Jsh', 'tcsh': 'Tcsh'} +# Define Color Schemes. + +# Arch Linux. +acolor = '\x1b[1;34m' +acolor2 = '\x1b[0;34m' + +# Ubuntu. +ucolor = '\x1b[1;33m' +ucolor2 = '\x1b[1;31m' +ucolor3 = '\x1b[0;31m' + # Find running processes. def xmonadfix(str): if re.compile("xmonad").match(str): return "xmonad" @@ -92,23 +103,28 @@ p1 = Popen(['ps', '-u', getuser()], stdout=PIPE).communicate()[0].split('\n') processes = map(xmonadfix, [process.split()[3] for process in p1 if process]) p1 = None +# Find Distro. +DetectUbuntu = Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE) +DetectArch = os.path.exists('/etc/arch-release') + # Print coloured key with normal value. def output(key, value): - if Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE): + if DetectUbuntu: ucolor = '\x1b[1;31m' output ='%s%s:%s %s' % (ucolor, key, clear, value) - if os.path.exists('/etc/arch-release'): - output = '%s%s:%s %s' % (color, key, clear, value) + if DetectArch: + ucolor = '\x1b[1;34m' + output = '%s%s:%s %s' % (acolor, key, clear, value) result.append(output) -# RAM Function +# RAM Function. def ram_display(): raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].split('\n') ram = ''.join(filter(re.compile('M').search, raminfo)).split() used = int(ram[2]) - int(ram[5]) - int(ram[6]) output ('RAM', '%s MB / %s MB' % (used, ram[1])) -# Screenshot Function +# Screenshot Function. screen = '%s' % options.screenshot def screenshot(): print 'Taking shot in', @@ -121,34 +137,34 @@ def screenshot(): print 'Say Cheeze!' subprocess.check_call(['scrot']) -# Operating System Function +# Operating System Function. def distro_display(): arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n' ) urelease = linecache.getline('/etc/lsb-release', 2).rstrip('\n').split('=')[1].title() - if Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE).communicate()[0].rstrip('\n'): + if DetectUbuntu: distro = 'Ubuntu %s %s' % (urelease, arch) - if os.path.exists('/etc/arch-release'): + if DetectArch: distro = 'Arch Linux %s' % arch output('OS', distro) -# Kernel Function +# Kernel Function. def kernel_display(): kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') output ('Kernel', kernel) -# Hostname Function +# Hostname Function. def hostname_display(): hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].rstrip('\n') output ('Hostname', hostname) -# CPU Function +# CPU Function. def cpu_display(): file = open('/proc/cpuinfo').readlines() cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) output ('CPU', cpuinfo) -# Uptime Function +# Uptime Function. def uptime_display(): fuptime = int(open('/proc/uptime').read().split('.')[0]) day = int(fuptime / 86400) @@ -164,7 +180,7 @@ def uptime_display(): uptime += '%d:%02d' % (hour, minute) output('Uptime', uptime) -# Desktop Environment Function +# Desktop Environment Function. def de_display(): de = 'None found' for key in de_dict.keys(): @@ -172,7 +188,7 @@ def de_display(): de = de_dict[key] output ('Desktop Environment', de) -# Window Manager Function +# Window Manager Function. def wm_display(): wm = 'None found' for key in wm_dict.keys(): @@ -180,31 +196,31 @@ def wm_display(): wm = wm_dict[key] output ('Window Manager', wm) -# Shell Function +# Shell Function. def sh_display(): sh = os.getenv("SHELL").split('/')[-1].capitalize() output ('Shell', sh) -# Terminal Function +# Terminal Function. def term_display(): term = os.getenv("TERM").split('/')[-1].capitalize() output ('Terminal', term) -# Packages Function +# Packages Function. def packages_display(): - if Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE): + if DetectUbuntu: p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) packages = p3.communicate()[0].rstrip('\n') output ('Packages', packages) - if os.path.exists('/etc/arch-release'): + if DetectArch: p1 = Popen(['pacman', '-Q'], stdout=PIPE) p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) packages = p2.communicate()[0].rstrip('\n') output ('Packages', packages) -# File System Function +# File System Function. def fs_display(): supported = ('ext2', 'ext3', 'ext4', 'reiserfs', 'jfs', 'ntfs', 'fat32', 'btrfs') p1 = Popen(['df', '-TPh'], stdout=PIPE).communicate()[0] @@ -232,15 +248,8 @@ for x in display: # Array containing values. result.extend(['']*(20 - len(display))) -###### Result ####### - -## Ubuntu -# Colors -ucolor = '\x1b[1;33m' -ucolor2 = '\x1b[1;31m' -ucolor3 = '\x1b[0;31m' - -if Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE): +# Result. +if DetectUbuntu: print """ %s ++++++ %s %s ++++++++ %s @@ -269,13 +278,7 @@ if Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE): %s ++++++ %s """ % (ucolor3, result[0], ucolor3, result[1], ucolor2, ucolor3, result[2], ucolor2, ucolor3, result[3], ucolor, ucolor2, ucolor3, result[4], ucolor, ucolor2, ucolor3, result[5], ucolor, ucolor2, result[6], ucolor, ucolor2, result[7], ucolor, ucolor2, result[8], ucolor, ucolor2, result[9], ucolor2, ucolor, ucolor2, result[10], ucolor2, ucolor, ucolor2, result[11], ucolor2, ucolor, result[12], ucolor2, ucolor, ucolor3, result[13], ucolor2, ucolor, ucolor3, result[14], ucolor, ucolor3, result[15], ucolor, ucolor3, result[16], ucolor, ucolor3, ucolor, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor, ucolor, clear) - -## Arch Linux -# Colors -acolor = '\x1b[1;34m' -acolor2 = '\x1b[0;34m' - -if os.path.exists('/etc/arch-release'): +if DetectArch: print """%s %s + %s %s # %s -- cgit v1.2.3-54-g00ecf From 57f8e864f07ad82829826bd384eb8aa48320de46 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Mon, 23 Aug 2010 12:58:03 -0700 Subject: more cleanup --- archey | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/archey b/archey index dc4d386..b9e2392 100644 --- a/archey +++ b/archey @@ -41,9 +41,6 @@ if __name__=='__main__': action='store_true', dest='screenshot', help='take a screenshot') (options, args) = parser.parse_args() -# Clear -clear = '\x1b[0m' - # Define processes for identifying Desktop Environmentss, Window Managers, Shells. de_dict = { 'gnome-session': 'GNOME', @@ -86,6 +83,9 @@ sh_dict = { # Define Color Schemes. +# Clear +clear = '\x1b[0m' + # Arch Linux. acolor = '\x1b[1;34m' acolor2 = '\x1b[0;34m' -- cgit v1.2.3-54-g00ecf From 802d3df689157bcd490ed26ac2e8d1cde5a9788c Mon Sep 17 00:00:00 2001 From: DjMelik Date: Mon, 23 Aug 2010 14:48:16 -0700 Subject: Fixed urelease bug --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index b9e2392..6d00958 100644 --- a/archey +++ b/archey @@ -141,8 +141,8 @@ def screenshot(): def distro_display(): arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n' ) - urelease = linecache.getline('/etc/lsb-release', 2).rstrip('\n').split('=')[1].title() if DetectUbuntu: + urelease = linecache.getline('/etc/lsb-release', 2).rstrip('\n').split('=')[1].title() distro = 'Ubuntu %s %s' % (urelease, arch) if DetectArch: distro = 'Arch Linux %s' % arch -- cgit v1.2.3-54-g00ecf From 2aec7d8692fe1fdd7c5201f21760ee856949421a Mon Sep 17 00:00:00 2001 From: DjMelik Date: Mon, 23 Aug 2010 19:25:47 -0700 Subject: Fixed another bug --- archey | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/archey b/archey index 6d00958..fe3f802 100644 --- a/archey +++ b/archey @@ -104,7 +104,9 @@ processes = map(xmonadfix, [process.split()[3] for process in p1 if process]) p1 = None # Find Distro. -DetectUbuntu = Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE) +DetectLsb = os.path.exists('/etc/lsb-release') +if DetectLsb: + DetectUbuntu = Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE) DetectArch = os.path.exists('/etc/arch-release') # Print coloured key with normal value. -- cgit v1.2.3-54-g00ecf From 8f28c264cf375a55ce17f6cddfc3d591c2715713 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Mon, 23 Aug 2010 19:55:43 -0700 Subject: Added support for Debian --- archey | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/archey b/archey index fe3f802..57227f0 100644 --- a/archey +++ b/archey @@ -1,8 +1,9 @@ #!/usr/bin/env python # -# archey [version 0.2.4] +# archey [version 0.2.5] # # Maintained by Melik Manukyan +# Changes Jérôme Launay # Distributed under the terms of the GNU General Public License v3. # See http://www.gnu.org/licenses/gpl.txt for the full license text. # @@ -95,6 +96,10 @@ ucolor = '\x1b[1;33m' ucolor2 = '\x1b[1;31m' ucolor3 = '\x1b[0;31m' +# Debian +dcolor = '\x1b[1;31m' +dcolor2 = '\x1b[0;31m' + # Find running processes. def xmonadfix(str): if re.compile("xmonad").match(str): return "xmonad" @@ -104,11 +109,15 @@ processes = map(xmonadfix, [process.split()[3] for process in p1 if process]) p1 = None # Find Distro. -DetectLsb = os.path.exists('/etc/lsb-release') -if DetectLsb: +DetectUbuntu = os.path.exists('/etc/lsb-release') +if DetectUbuntu: DetectUbuntu = Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE) + DetectArch = os.path.exists('/etc/arch-release') +DetectDebian = os.path.exists('/etc/debian_version') + + # Print coloured key with normal value. def output(key, value): if DetectUbuntu: @@ -117,6 +126,9 @@ def output(key, value): if DetectArch: ucolor = '\x1b[1;34m' output = '%s%s:%s %s' % (acolor, key, clear, value) + if DetectDebian: + ucolor = '\x1b[1;33m' + output = '%s%s:%s %s' % (acolor, key, clear, value) result.append(output) # RAM Function. @@ -141,11 +153,13 @@ def screenshot(): # Operating System Function. def distro_display(): - arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n' - ) + arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') if DetectUbuntu: urelease = linecache.getline('/etc/lsb-release', 2).rstrip('\n').split('=')[1].title() distro = 'Ubuntu %s %s' % (urelease, arch) + if DetectDebian: + urelease = linecache.getline('/etc/debian_version', 1).rstrip('\n') + distro = 'Debian %s %s' % (urelease, arch) if DetectArch: distro = 'Arch Linux %s' % arch output('OS', distro) @@ -221,6 +235,12 @@ def packages_display(): p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) packages = p2.communicate()[0].rstrip('\n') output ('Packages', packages) + if DetectDebian: + p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) + p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) + p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) + packages = p3.communicate()[0].rstrip('\n') + output ('Packages', packages) # File System Function. def fs_display(): @@ -302,5 +322,28 @@ if DetectArch: %s #' `# %s %s """ % (acolor, acolor, result[0], acolor, result[1], acolor, result[2], acolor, result[3], acolor, result[4], acolor, result[5], acolor, result[6], acolor, result[7], acolor, acolor2, acolor, result[8], acolor, acolor2, acolor, result[9], acolor, acolor2, result[10], acolor2, result[11], acolor2, result[12], acolor2, result[13], acolor2, result[14], acolor2, result[15], acolor2, result[16], acolor2, result[17], clear) +if DetectDebian: + print """%s +%s %s +%s _sudZUZ#Z#XZo=_ %s +%s _jmZZ2!!~---~!!X##wx %s +%s . -]Xb/ ~ __#2( %s +%s -Zo; +!4ZwerfgnZZXY' %s +%s *#[, ~-?!!!!!!-~ %s +%s XUb;. %s +%s )YXL,, %s +%s +3#bc, %s +%s -)SSL,, %s +%s ~~~~~ %s +%s %s +%s """ %(dcolor, dcolor, result[0], dcolor, result[1], dcolor, result[2], dcolor, result[3], dcolor, result[4], dcolor, result[5], dcolor, result[6], dcolor, result[7], dcolor, result[8], dcolor2, result[9], dcolor2, result[10], dcolor2, result[11], dcolor2, result[12], dcolor2, result[13], dcolor2, result[14], dcolor2, result[15], dcolor2, result[16], dcolor2, result[17], clear) + + if screen == 'True': screenshot() -- cgit v1.2.3-54-g00ecf From 954aba731e746dbeebcf78adb2bbcf04a7f1cd2c Mon Sep 17 00:00:00 2001 From: DjMelik Date: Tue, 24 Aug 2010 10:17:58 -0700 Subject: fixed double output bug for debian/ubuntu --- archey | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/archey b/archey index 57227f0..90537b0 100644 --- a/archey +++ b/archey @@ -3,7 +3,7 @@ # archey [version 0.2.5] # # Maintained by Melik Manukyan -# Changes Jérôme Launay +# Changes Jerome Launay # Distributed under the terms of the GNU General Public License v3. # See http://www.gnu.org/licenses/gpl.txt for the full license text. # @@ -37,7 +37,7 @@ result = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.4") + parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.5") parser.add_option('-s', '--screenshot', action='store_true', dest='screenshot', help='take a screenshot') (options, args) = parser.parse_args() @@ -111,24 +111,22 @@ p1 = None # Find Distro. DetectUbuntu = os.path.exists('/etc/lsb-release') if DetectUbuntu: + DetectDebian = False DetectUbuntu = Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE) DetectArch = os.path.exists('/etc/arch-release') -DetectDebian = os.path.exists('/etc/debian_version') - +if not DetectUbuntu: + DetectDebian = os.path.exists('/etc/debian_version') # Print coloured key with normal value. def output(key, value): if DetectUbuntu: - ucolor = '\x1b[1;31m' - output ='%s%s:%s %s' % (ucolor, key, clear, value) + output ='%s%s:%s %s' % (ucolor2, key, clear, value) if DetectArch: - ucolor = '\x1b[1;34m' output = '%s%s:%s %s' % (acolor, key, clear, value) if DetectDebian: - ucolor = '\x1b[1;33m' - output = '%s%s:%s %s' % (acolor, key, clear, value) + output = '%s%s:%s %s' % (dcolor, key, clear, value) result.append(output) # RAM Function. -- cgit v1.2.3-54-g00ecf From 05d160e2424982ed2f95f979a9615a3becb6e652 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Thu, 26 Aug 2010 14:52:03 -0700 Subject: redid distro detection using lsb_release --- archey | 89 ++++++++++++++++++++++++++++-------------------------------------- 1 file changed, 38 insertions(+), 51 deletions(-) diff --git a/archey b/archey index 90537b0..68a3092 100644 --- a/archey +++ b/archey @@ -94,7 +94,7 @@ acolor2 = '\x1b[0;34m' # Ubuntu. ucolor = '\x1b[1;33m' ucolor2 = '\x1b[1;31m' -ucolor3 = '\x1b[0;31m' +ucolor3 = '\x1b[0;31m' # Debian dcolor = '\x1b[1;31m' @@ -109,23 +109,15 @@ processes = map(xmonadfix, [process.split()[3] for process in p1 if process]) p1 = None # Find Distro. -DetectUbuntu = os.path.exists('/etc/lsb-release') -if DetectUbuntu: - DetectDebian = False - DetectUbuntu = Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE) - -DetectArch = os.path.exists('/etc/arch-release') - -if not DetectUbuntu: - DetectDebian = os.path.exists('/etc/debian_version') +DetectDistro = Popen(['lsb_release', '-i'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') # Print coloured key with normal value. def output(key, value): - if DetectUbuntu: + if DetectDistro == 'Ubuntu': output ='%s%s:%s %s' % (ucolor2, key, clear, value) - if DetectArch: + if DetectDistro == 'Arch': output = '%s%s:%s %s' % (acolor, key, clear, value) - if DetectDebian: + if DetectDistro == 'Debian': output = '%s%s:%s %s' % (dcolor, key, clear, value) result.append(output) @@ -152,13 +144,13 @@ def screenshot(): # Operating System Function. def distro_display(): arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') - if DetectUbuntu: - urelease = linecache.getline('/etc/lsb-release', 2).rstrip('\n').split('=')[1].title() - distro = 'Ubuntu %s %s' % (urelease, arch) - if DetectDebian: + if DetectDistro == 'Debian': urelease = linecache.getline('/etc/debian_version', 1).rstrip('\n') distro = 'Debian %s %s' % (urelease, arch) - if DetectArch: + if DetectDistro == 'Ubuntu': + urelease = linecache.getline('/etc/lsb-release', 2).rstrip('\n').split('=')[1].title() + distro = 'Ubuntu %s %s' % (urelease, arch) + if DetectDistro == 'Arch': distro = 'Arch Linux %s' % arch output('OS', distro) @@ -222,18 +214,18 @@ def term_display(): # Packages Function. def packages_display(): - if DetectUbuntu: + if DetectDistro == 'Ubuntu': p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) packages = p3.communicate()[0].rstrip('\n') output ('Packages', packages) - if DetectArch: + if DetectDistro == 'Arch': p1 = Popen(['pacman', '-Q'], stdout=PIPE) p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) packages = p2.communicate()[0].rstrip('\n') output ('Packages', packages) - if DetectDebian: + if DetectDistro == 'Debian': p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) @@ -269,36 +261,31 @@ for x in display: result.extend(['']*(20 - len(display))) # Result. -if DetectUbuntu: +if DetectDistro == 'Ubuntu': print """ -%s ++++++ %s -%s ++++++++ %s -%s ++++++++++ %s++++++++ %s -%s ++++++++++++ %s++++++++ %s -%s ++ %s++++++++++++ %s++++++ %s -%s +++++ %s++++++++++++ %s**** %s -%s +++++++ %s+++++++++++++++++++ %s -%s +++++++++ %s+++++++++++ %s -%s ++++++++++ %s++++++++++ %s -%s ++++++++ %s++++++++++ %s -%s ++++++ %s++++++ %s++++++++++ %s -%s ++++++++ %s+++++ %s+++++++++ %s -%s +++++++++ %s++++ %s -%s ++++++++ %s+++++ %s+++++++++ %s -%s ++++++ %s++++++ %s++++++++++ %s -%s ++++++++ %s++++++++++ %s -%s +++++++++ %s++++++++++ %s -%s +++++++++ %s++++++++++++ %s -%s +++++++ %s+++++++++++++++++++ -%s +++++ %s++++++++++++ %s,,,, -%s ++ %s++++++++++++ %s++++++ -%s ++++++++++++ %s++++++++ -%s ++++++++++ %s++++++++ -%s ++++++++ -%s ++++++ -%s """ % (ucolor3, result[0], ucolor3, result[1], ucolor2, ucolor3, result[2], ucolor2, ucolor3, result[3], ucolor, ucolor2, ucolor3, result[4], ucolor, ucolor2, ucolor3, result[5], ucolor, ucolor2, result[6], ucolor, ucolor2, result[7], ucolor, ucolor2, result[8], ucolor, ucolor2, result[9], ucolor2, ucolor, ucolor2, result[10], ucolor2, ucolor, ucolor2, result[11], ucolor2, ucolor, result[12], ucolor2, ucolor, ucolor3, result[13], ucolor2, ucolor, ucolor3, result[14], ucolor, ucolor3, result[15], ucolor, ucolor3, result[16], ucolor, ucolor3, ucolor, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor, ucolor, clear) - -if DetectArch: +%s .oyhhs: %s +%s ..--.., %sshhhhhh- %s +%s -+++++++++`:%syyhhyo` %s +%s .-- %s-++++++++/-.-%s::-` %s +%s .::::- %s:-----:/+++/++/. %s +%s -:::::-. %s.:++++++: %s +%s ,,, %s.:::::-` %s.++++++- %s +%s./+++/-%s`-::- %s./////: %s +%s+++++++ %s.::- %s +%s./+++/-`%s-::- %s:yyyyyo %s +%s ``` `%s-::::-` %s:yhhhhh: %s +%s -:::::-. %s`-ohhhhhh+ %s +%s .::::-` %s-o+///+oyhhyyyhy: %s +%s `.-- %s/yhhhhhhhy+%s,.... %s +%s /hhhhhhhhh%s-.-:::; %s +%s `.:://::- %s-:::::; %s +%s `.-:-' %s +%s %s +%s""" % ( ucolor3, result[0], ucolor2, ucolor3, result[1], ucolor2, ucolor3, result[2], ucolor, ucolor2, ucolor3, result[3], ucolor, ucolor2, result[4], ucolor, ucolor2, result[5], +ucolor2, ucolor, ucolor2, result[6], ucolor2, ucolor, ucolor2, result[7], ucolor2, ucolor, result[8], ucolor2, ucolor, ucolor3, result[9], ucolor2, ucolor, ucolor3, result[10], +ucolor, ucolor3, result[11], ucolor, ucolor3, result[12], ucolor, ucolor3, ucolor, result[13], ucolor3, ucolor, result[14], ucolor3, ucolor, result[15], ucolor, result[16], ucolor, result[17], clear ) + +if DetectDistro == 'Arch': print """%s %s + %s %s # %s @@ -320,7 +307,7 @@ if DetectArch: %s #' `# %s %s """ % (acolor, acolor, result[0], acolor, result[1], acolor, result[2], acolor, result[3], acolor, result[4], acolor, result[5], acolor, result[6], acolor, result[7], acolor, acolor2, acolor, result[8], acolor, acolor2, acolor, result[9], acolor, acolor2, result[10], acolor2, result[11], acolor2, result[12], acolor2, result[13], acolor2, result[14], acolor2, result[15], acolor2, result[16], acolor2, result[17], clear) -if DetectDebian: +if DetectDistro == 'Debian': print """%s %s %s %s _sudZUZ#Z#XZo=_ %s -- cgit v1.2.3-54-g00ecf From 9a92449c97def5273d3f5ca12820b87ab061cdf6 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Thu, 26 Aug 2010 16:04:09 -0700 Subject: added fuseblk filesystem support --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 68a3092..66c94ba 100644 --- a/archey +++ b/archey @@ -234,7 +234,7 @@ def packages_display(): # File System Function. def fs_display(): - supported = ('ext2', 'ext3', 'ext4', 'reiserfs', 'jfs', 'ntfs', 'fat32', 'btrfs') + supported = ('ext2', 'ext3', 'ext4', 'reiserfs', 'jfs', 'ntfs', 'fat32', 'btrfs'. 'fuseblk') p1 = Popen(['df', '-TPh'], stdout=PIPE).communicate()[0] filesystems = p1.rstrip().split('\n') del filesystems[0] -- cgit v1.2.3-54-g00ecf From c02c0d704cf082d3d87fc0a2d623914767d00023 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Thu, 26 Aug 2010 16:05:56 -0700 Subject: . > , --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 66c94ba..386452f 100644 --- a/archey +++ b/archey @@ -234,7 +234,7 @@ def packages_display(): # File System Function. def fs_display(): - supported = ('ext2', 'ext3', 'ext4', 'reiserfs', 'jfs', 'ntfs', 'fat32', 'btrfs'. 'fuseblk') + supported = ('ext2', 'ext3', 'ext4', 'reiserfs', 'jfs', 'ntfs', 'fat32', 'btrfs', 'fuseblk') p1 = Popen(['df', '-TPh'], stdout=PIPE).communicate()[0] filesystems = p1.rstrip().split('\n') del filesystems[0] -- cgit v1.2.3-54-g00ecf From 41455b9bddea4f6db6e99830f9e26eef2f1fb0a1 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Fri, 27 Aug 2010 13:29:07 -0700 Subject: Added support for Fedora --- archey | 57 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/archey b/archey index 386452f..bb53069 100644 --- a/archey +++ b/archey @@ -1,12 +1,13 @@ #!/usr/bin/env python # -# archey [version 0.2.5] +# archey [version 0.2.6] # # Maintained by Melik Manukyan +# ASCII art by Brett Bohnenkamper # Changes Jerome Launay +# Fedora support by YeOK < > # Distributed under the terms of the GNU General Public License v3. # See http://www.gnu.org/licenses/gpl.txt for the full license text. -# # System information tool for Archlinux written in python. # Import libraries @@ -37,7 +38,7 @@ result = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.5") + parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.6") parser.add_option('-s', '--screenshot', action='store_true', dest='screenshot', help='take a screenshot') (options, args) = parser.parse_args() @@ -100,6 +101,11 @@ ucolor3 = '\x1b[0;31m' dcolor = '\x1b[1;31m' dcolor2 = '\x1b[0;31m' +# Fedora +fcolor = '\x1b[1;37m' +fcolor2 = '\x1b[1;34m' +fcolor3 = '\x1b[0;34m' + # Find running processes. def xmonadfix(str): if re.compile("xmonad").match(str): return "xmonad" @@ -119,6 +125,8 @@ def output(key, value): output = '%s%s:%s %s' % (acolor, key, clear, value) if DetectDistro == 'Debian': output = '%s%s:%s %s' % (dcolor, key, clear, value) + if DetectDistro == 'Fedora': + output = '%s%s:%s %s' % (fcolor2, key, clear, value) result.append(output) # RAM Function. @@ -145,13 +153,16 @@ def screenshot(): def distro_display(): arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') if DetectDistro == 'Debian': - urelease = linecache.getline('/etc/debian_version', 1).rstrip('\n') - distro = 'Debian %s %s' % (urelease, arch) + release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') + distro = 'Debian %s %s' % (release, arch) if DetectDistro == 'Ubuntu': - urelease = linecache.getline('/etc/lsb-release', 2).rstrip('\n').split('=')[1].title() - distro = 'Ubuntu %s %s' % (urelease, arch) + release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') + distro = 'Ubuntu %s %s' % (release, arch) if DetectDistro == 'Arch': distro = 'Arch Linux %s' % arch + if DetectDistro == 'Fedora': + release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') + distro = 'Fedora %s %s' % (release, arch) output('OS', distro) # Kernel Function. @@ -231,6 +242,11 @@ def packages_display(): p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) packages = p3.communicate()[0].rstrip('\n') output ('Packages', packages) + if DetectDistro == 'Fedora': + p1 = Popen(['rpm', '-qa'], stdout=PIPE) + p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) + packages = p3.communicate()[0].rstrip('\n') + output ('Packages', packages) # File System Function. def fs_display(): @@ -327,8 +343,31 @@ if DetectDistro == 'Debian': %s -)SSL,, %s %s ~~~~~ %s %s %s -%s """ %(dcolor, dcolor, result[0], dcolor, result[1], dcolor, result[2], dcolor, result[3], dcolor, result[4], dcolor, result[5], dcolor, result[6], dcolor, result[7], dcolor, result[8], dcolor2, result[9], dcolor2, result[10], dcolor2, result[11], dcolor2, result[12], dcolor2, result[13], dcolor2, result[14], dcolor2, result[15], dcolor2, result[16], dcolor2, result[17], clear) - +%s """ % (dcolor, dcolor, result[0], dcolor, result[1], dcolor, result[2], dcolor, result[3], dcolor, result[4], dcolor, result[5], dcolor, result[6], dcolor, result[7], dcolor, result[8], dcolor2, result[9], dcolor2, result[10], dcolor2, result[11], dcolor2, result[12], dcolor2, result[13], dcolor2, result[14], dcolor2, result[15], dcolor2, result[16], dcolor2, result[17], clear) +if DetectDistro == 'Fedora': + print """ +%s :/------------:// %s +%s :------------------:// %s +%s :-----------%s/shhdhyo/%s-:// %s +%s /-----------%somMMMNNNMMMd/%s-:/ %s +%s :-----------%ssMMMdo:/%s -:/ %s +%s :-----------%s:MMMd%s------- --:/ %s +%s /-----------%s:MMMy%s------- ---/ %s +%s :------ --%s/+MMMh/%s-- ---: %s +%s :--- %soNMMMMMMMMMNho%s -----: %s +%s :-- %s+shhhMMMmhhy++%s ------: %s +%s :- -----%s:MMMy%s--------------/ %s +%s :- ------%s/MMMy%s-------------: %s +%s :- ----%s/hMMM+%s------------: %s +%s :--%s:dMMNdhhdNMMNo%s-----------: %s +%s :---%s:sdNMMMMNds:%s----------: %s +%s :------%s:://:%s-----------:// %s +%s :--------------------:// %s +%s %s +%s """ % ( fcolor3, result[0], fcolor3, result[1], fcolor3, fcolor, fcolor3, result[2], fcolor3, fcolor, fcolor3, result[3], fcolor3, fcolor, fcolor3, result[4], fcolor3, fcolor, fcolor3, result[5], +fcolor3, fcolor, fcolor3, result[6], fcolor3, fcolor, fcolor3, result[7], fcolor3, fcolor, fcolor3, result[8], fcolor3, fcolor, fcolor3, result[9], fcolor3, fcolor, fcolor3, result[10], +fcolor3, fcolor, fcolor3, result[11], fcolor3, fcolor, fcolor3, result[12], fcolor3, fcolor, fcolor3, result[13], fcolor3, fcolor, fcolor3, result[14], fcolor3, fcolor, fcolor3, result[15], +fcolor3, result[16], fcolor3, result[17], clear ) if screen == 'True': screenshot() -- cgit v1.2.3-54-g00ecf From 409d3137ec925cbadfab1591332384da98184f6b Mon Sep 17 00:00:00 2001 From: DjMelik Date: Fri, 27 Aug 2010 15:02:14 -0700 Subject: added support for crunchbang --- archey | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/archey b/archey index bb53069..548dada 100644 --- a/archey +++ b/archey @@ -5,7 +5,7 @@ # Maintained by Melik Manukyan # ASCII art by Brett Bohnenkamper # Changes Jerome Launay -# Fedora support by YeOK < > +# Fedora support by YeOK # Distributed under the terms of the GNU General Public License v3. # See http://www.gnu.org/licenses/gpl.txt for the full license text. # System information tool for Archlinux written in python. @@ -106,6 +106,10 @@ fcolor = '\x1b[1;37m' fcolor2 = '\x1b[1;34m' fcolor3 = '\x1b[0;34m' +# CrunchBang +ccolor = '\x1b[0;37m' +ccolor2 = '\x1b[1;37m' + # Find running processes. def xmonadfix(str): if re.compile("xmonad").match(str): return "xmonad" @@ -127,6 +131,8 @@ def output(key, value): output = '%s%s:%s %s' % (dcolor, key, clear, value) if DetectDistro == 'Fedora': output = '%s%s:%s %s' % (fcolor2, key, clear, value) + if DetectDistro == 'CrunchBang': + output = '%s%s:%s %s' % (ccolor, key, clear, value) result.append(output) # RAM Function. @@ -161,8 +167,12 @@ def distro_display(): if DetectDistro == 'Arch': distro = 'Arch Linux %s' % arch if DetectDistro == 'Fedora': + release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') + distro = 'Fedora %s %s' % (release, arch) + if DetectDistro == 'CrunchBang': release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') distro = 'Fedora %s %s' % (release, arch) + output('OS', distro) # Kernel Function. @@ -242,10 +252,16 @@ def packages_display(): p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) packages = p3.communicate()[0].rstrip('\n') output ('Packages', packages) + if DetectDistro == 'CrunchBang': + p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) + p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) + p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) + packages = p3.communicate()[0].rstrip('\n') + output ('Packages', packages) if DetectDistro == 'Fedora': p1 = Popen(['rpm', '-qa'], stdout=PIPE) p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) - packages = p3.communicate()[0].rstrip('\n') + packages = p2.communicate()[0].rstrip('\n') output ('Packages', packages) # File System Function. @@ -369,5 +385,27 @@ if DetectDistro == 'Fedora': fcolor3, fcolor, fcolor3, result[6], fcolor3, fcolor, fcolor3, result[7], fcolor3, fcolor, fcolor3, result[8], fcolor3, fcolor, fcolor3, result[9], fcolor3, fcolor, fcolor3, result[10], fcolor3, fcolor, fcolor3, result[11], fcolor3, fcolor, fcolor3, result[12], fcolor3, fcolor, fcolor3, result[13], fcolor3, fcolor, fcolor3, result[14], fcolor3, fcolor, fcolor3, result[15], fcolor3, result[16], fcolor3, result[17], clear ) + +if DetectDistro == 'CrunchBang': + print """ +%s ___ ___ _ %s +%s / / / / | | %s +%s / / / / | | %s +%s / / / / | | %s +%s _______/ /______/ /______ | | %s +%s /______ _______ _______/ | | %s +%s / / / / | | %s +%s / / / / | | %s +%s / / / / | | %s +%s ______/ /______/ /______ | | %s +%s/_____ _______ _______/ | | %s +%s / / / / | | %s +%s / / / / |_| %s +%s / / / / _ %s +%s / / / / | | %s +%s /__/ /__/ |_| %s +%s %s +%s %s +%s""" % ( ccolor, result[0], ccolor, result[1], ccolor, result[2], ccolor, result[3], ccolor, result[4], ccolor, result[5], ccolor, result[6], ccolor, result[7], ccolor, result[8], ccolor, result[9], ccolor, result[10], ccolor, result[11], ccolor, result[12], ccolor, result[13], ccolor, result[14], ccolor, result[15], ccolor, result[16], ccolor, result[17], clear ) if screen == 'True': screenshot() -- cgit v1.2.3-54-g00ecf From 2a8754d05af55e2f7859ab4e2b9ea6bbc944d39e Mon Sep 17 00:00:00 2001 From: DjMelik Date: Fri, 27 Aug 2010 15:15:45 -0700 Subject: crunchbang bug fixed, minor cleanup --- archey | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/archey b/archey index 548dada..eb4388c 100644 --- a/archey +++ b/archey @@ -171,7 +171,7 @@ def distro_display(): distro = 'Fedora %s %s' % (release, arch) if DetectDistro == 'CrunchBang': release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') - distro = 'Fedora %s %s' % (release, arch) + distro = 'CrunchBang %s %s' % (release, arch) output('OS', distro) @@ -381,10 +381,7 @@ if DetectDistro == 'Fedora': %s :------%s:://:%s-----------:// %s %s :--------------------:// %s %s %s -%s """ % ( fcolor3, result[0], fcolor3, result[1], fcolor3, fcolor, fcolor3, result[2], fcolor3, fcolor, fcolor3, result[3], fcolor3, fcolor, fcolor3, result[4], fcolor3, fcolor, fcolor3, result[5], -fcolor3, fcolor, fcolor3, result[6], fcolor3, fcolor, fcolor3, result[7], fcolor3, fcolor, fcolor3, result[8], fcolor3, fcolor, fcolor3, result[9], fcolor3, fcolor, fcolor3, result[10], -fcolor3, fcolor, fcolor3, result[11], fcolor3, fcolor, fcolor3, result[12], fcolor3, fcolor, fcolor3, result[13], fcolor3, fcolor, fcolor3, result[14], fcolor3, fcolor, fcolor3, result[15], -fcolor3, result[16], fcolor3, result[17], clear ) +%s """ % ( fcolor3, result[0], fcolor3, result[1], fcolor3, fcolor, fcolor3, result[2], fcolor3, fcolor, fcolor3, result[3], fcolor3, fcolor, fcolor3, result[4], fcolor3, fcolor, fcolor3, result[5], fcolor3, fcolor, fcolor3, result[6], fcolor3, fcolor, fcolor3, result[7], fcolor3, fcolor, fcolor3, result[8], fcolor3, fcolor, fcolor3, result[9], fcolor3, fcolor, fcolor3, result[10], fcolor3, fcolor, fcolor3, result[11], fcolor3, fcolor, fcolor3, result[12], fcolor3, fcolor, fcolor3, result[13], fcolor3, fcolor, fcolor3, result[14], fcolor3, fcolor, fcolor3, result[15], fcolor3, result[16], fcolor3, result[17], clear ) if DetectDistro == 'CrunchBang': print """ @@ -407,5 +404,6 @@ if DetectDistro == 'CrunchBang': %s %s %s %s %s""" % ( ccolor, result[0], ccolor, result[1], ccolor, result[2], ccolor, result[3], ccolor, result[4], ccolor, result[5], ccolor, result[6], ccolor, result[7], ccolor, result[8], ccolor, result[9], ccolor, result[10], ccolor, result[11], ccolor, result[12], ccolor, result[13], ccolor, result[14], ccolor, result[15], ccolor, result[16], ccolor, result[17], clear ) + if screen == 'True': screenshot() -- cgit v1.2.3-54-g00ecf From 3e749dcd756d5c07584d27d1a090ea680a4b0226 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 30 Aug 2010 13:45:43 -0700 Subject: Support for Linux Mint added --- archey | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/archey b/archey index eb4388c..06f5e95 100644 --- a/archey +++ b/archey @@ -1,14 +1,16 @@ #!/usr/bin/env python # -# archey [version 0.2.6] +# Archey [version 0.2.7] +# +# Archey is a system information tool written in Python. # # Maintained by Melik Manukyan # ASCII art by Brett Bohnenkamper # Changes Jerome Launay # Fedora support by YeOK + # Distributed under the terms of the GNU General Public License v3. # See http://www.gnu.org/licenses/gpl.txt for the full license text. -# System information tool for Archlinux written in python. # Import libraries import os, sys, subprocess, optparse, re, linecache @@ -38,7 +40,7 @@ result = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.6") + parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.7") parser.add_option('-s', '--screenshot', action='store_true', dest='screenshot', help='take a screenshot') (options, args) = parser.parse_args() @@ -110,6 +112,10 @@ fcolor3 = '\x1b[0;34m' ccolor = '\x1b[0;37m' ccolor2 = '\x1b[1;37m' +# Mint +mcolor = '\x1b[1;37m' +mcolor2 = '\x1b[1;32m' + # Find running processes. def xmonadfix(str): if re.compile("xmonad").match(str): return "xmonad" @@ -133,6 +139,8 @@ def output(key, value): output = '%s%s:%s %s' % (fcolor2, key, clear, value) if DetectDistro == 'CrunchBang': output = '%s%s:%s %s' % (ccolor, key, clear, value) + if DetectDistro == 'LinuxMint': + output = '%s%s:%s %s' % (mcolor2, key, clear, value) result.append(output) # RAM Function. @@ -171,8 +179,9 @@ def distro_display(): distro = 'Fedora %s %s' % (release, arch) if DetectDistro == 'CrunchBang': release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') - distro = 'CrunchBang %s %s' % (release, arch) - + if DetectDistro == 'LinuxMint': + release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') + distro = 'Mint %s %s' % (release, arch) output('OS', distro) # Kernel Function. @@ -262,6 +271,11 @@ def packages_display(): p1 = Popen(['rpm', '-qa'], stdout=PIPE) p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) packages = p2.communicate()[0].rstrip('\n') + if DetectDistro == 'LinuxMint': + p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) + p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) + p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) + packages = p3.communicate()[0].rstrip('\n') output ('Packages', packages) # File System Function. @@ -313,9 +327,7 @@ if DetectDistro == 'Ubuntu': %s `.:://::- %s-:::::; %s %s `.-:-' %s %s %s -%s""" % ( ucolor3, result[0], ucolor2, ucolor3, result[1], ucolor2, ucolor3, result[2], ucolor, ucolor2, ucolor3, result[3], ucolor, ucolor2, result[4], ucolor, ucolor2, result[5], -ucolor2, ucolor, ucolor2, result[6], ucolor2, ucolor, ucolor2, result[7], ucolor2, ucolor, result[8], ucolor2, ucolor, ucolor3, result[9], ucolor2, ucolor, ucolor3, result[10], -ucolor, ucolor3, result[11], ucolor, ucolor3, result[12], ucolor, ucolor3, ucolor, result[13], ucolor3, ucolor, result[14], ucolor3, ucolor, result[15], ucolor, result[16], ucolor, result[17], clear ) +%s""" % ( ucolor3, result[0], ucolor2, ucolor3, result[1], ucolor2, ucolor3, result[2], ucolor, ucolor2, ucolor3, result[3], ucolor, ucolor2, result[4], ucolor, ucolor2, result[5], ucolor2, ucolor, ucolor2, result[6], ucolor2, ucolor, ucolor2, result[7], ucolor2, ucolor, result[8], ucolor2, ucolor, ucolor3, result[9], ucolor2, ucolor, ucolor3, result[10], ucolor, ucolor3, result[11], ucolor, ucolor3, result[12], ucolor, ucolor3, ucolor, result[13], ucolor3, ucolor, result[14], ucolor3, ucolor, result[15], ucolor, result[16], ucolor, result[17], clear ) if DetectDistro == 'Arch': print """%s @@ -336,8 +348,7 @@ if DetectDistro == 'Arch': %s ######' '###### %s %s ;#### ####; %s %s ##' '## %s -%s #' `# %s -%s """ % (acolor, acolor, result[0], acolor, result[1], acolor, result[2], acolor, result[3], acolor, result[4], acolor, result[5], acolor, result[6], acolor, result[7], acolor, acolor2, acolor, result[8], acolor, acolor2, acolor, result[9], acolor, acolor2, result[10], acolor2, result[11], acolor2, result[12], acolor2, result[13], acolor2, result[14], acolor2, result[15], acolor2, result[16], acolor2, result[17], clear) +%s #' `# %s%s """ % (acolor, acolor, result[0], acolor, result[1], acolor, result[2], acolor, result[3], acolor, result[4], acolor, result[5], acolor, result[6], acolor, result[7], acolor, acolor2, acolor, result[8], acolor, acolor2, acolor, result[9], acolor, acolor2, result[10], acolor2, result[11], acolor2, result[12], acolor2, result[13], acolor2, result[14], acolor2, result[15], acolor2, result[16], acolor2, result[17], clear) if DetectDistro == 'Debian': print """%s @@ -404,6 +415,26 @@ if DetectDistro == 'CrunchBang': %s %s %s %s %s""" % ( ccolor, result[0], ccolor, result[1], ccolor, result[2], ccolor, result[3], ccolor, result[4], ccolor, result[5], ccolor, result[6], ccolor, result[7], ccolor, result[8], ccolor, result[9], ccolor, result[10], ccolor, result[11], ccolor, result[12], ccolor, result[13], ccolor, result[14], ccolor, result[15], ccolor, result[16], ccolor, result[17], clear ) +if DetectDistro == 'LinuxMint': + print """%s %s +%s MMMMMMMMMMMMMMMMMMMMMMMMMmds+. %s +%s MMm----::-://////////////oymNMd+` %s +%s MMd %s/++ %s-sNMd: %s +%s MMNso/` %sdMM `.::-. .-::.` %s.hMN: %s +%s ddddMMh %sdMM :hNMNMNhNMNMNh: `%sNMm %s +%s NMm %sdMM .NMN/-+MMM+-/NMN` %sdMM %s +%s NMm %sdMM -MMm `MMM dMM. %sdMM %s +%s NMm %sdMM -MMm `MMM dMM. %sdMM %s +%s NMm %sdMM .mmd `mmm yMM. %sdMM %s +%s NMm %sdMM` ..` ... ydm. %sdMM %s +%s hMM- %s+MMd/-------...-:sdds %sMMM %s +%s -NMm- %s:hNMNNNmdddddddddy/` %sdMM %s +%s -dMNs-``%s-::::-------.`` %sdMM %s +%s `/dMNmy+/:-------------:/yMMM %s +%s ./ydNMMMMMMMMMMMMMMMMMMMMM %s +%s %s +%s %s +%s""" % ( mcolor, result[0], mcolor, result[1], mcolor, result[2], mcolor, mcolor2, mcolor, result[3], mcolor, mcolor2, mcolor, result[4], mcolor, mcolor2, mcolor, result[5], mcolor, mcolor2, mcolor, result[6], mcolor, mcolor2, mcolor, result[7], mcolor, mcolor2, mcolor, result[8], mcolor, mcolor2, mcolor, result[9], mcolor, mcolor2, mcolor, result[10], mcolor, mcolor2, mcolor, result[11], mcolor, mcolor2, mcolor, result[12], mcolor, mcolor2, mcolor, result[13], mcolor, result[14], mcolor, result[15], mcolor, result[16], mcolor, result[17], clear ) if screen == 'True': screenshot() -- cgit v1.2.3-54-g00ecf From 720ee511d3a4792cc04e7d9f49713649895770de Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 20 Sep 2010 11:29:56 -0700 Subject: replace xfconfd with xfce4-session --- archey | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archey b/archey index 06f5e95..d92c3f0 100644 --- a/archey +++ b/archey @@ -49,7 +49,7 @@ if __name__=='__main__': de_dict = { 'gnome-session': 'GNOME', 'ksmserver': 'KDE', - 'xfconfd': 'Xfce'} + 'xfce4-session': 'Xfce'} wm_dict = { 'awesome': 'Awesome', @@ -415,6 +415,7 @@ if DetectDistro == 'CrunchBang': %s %s %s %s %s""" % ( ccolor, result[0], ccolor, result[1], ccolor, result[2], ccolor, result[3], ccolor, result[4], ccolor, result[5], ccolor, result[6], ccolor, result[7], ccolor, result[8], ccolor, result[9], ccolor, result[10], ccolor, result[11], ccolor, result[12], ccolor, result[13], ccolor, result[14], ccolor, result[15], ccolor, result[16], ccolor, result[17], clear ) + if DetectDistro == 'LinuxMint': print """%s %s %s MMMMMMMMMMMMMMMMMMMMMMMMMmds+. %s -- cgit v1.2.3-54-g00ecf From b716c609f9d63dc97bb25d2840e50944739f14ae Mon Sep 17 00:00:00 2001 From: DjMelik Date: Mon, 4 Oct 2010 22:27:25 -0700 Subject: reworked filesytem function, added color to RAM/Disk --- archey | 136 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/archey b/archey index d92c3f0..e345b78 100644 --- a/archey +++ b/archey @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Archey [version 0.2.7] +# Archey [version 0.2.8] # # Archey is a system information tool written in Python. # @@ -21,8 +21,9 @@ from time import ctime, sleep # Display [Comment/Uncomment to Enable/Disable information.] display = [ - 'distro', # Display Distribution + 'user', # Display Username 'hostname', # Display Machine Hostname + 'distro', # Display Distribution 'kernel', # Display Kernel Version 'uptime', # Display System Uptime 'wm', # Display Window Manager @@ -32,7 +33,7 @@ display = [ 'cpu', # Display CPU Model 'sh', # Display Current Shell 'term', # Display Current Terminal - 'fs' # Display / Partition Usage + 'disk' # Display / Partition Usage ] # Array containing Values @@ -40,7 +41,7 @@ result = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.7") + parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.8") parser.add_option('-s', '--screenshot', action='store_true', dest='screenshot', help='take a screenshot') (options, args) = parser.parse_args() @@ -85,36 +86,25 @@ sh_dict = { 'jsh': 'Jsh', 'tcsh': 'Tcsh'} -# Define Color Schemes. +# Define Colour Scheme -# Clear clear = '\x1b[0m' - -# Arch Linux. -acolor = '\x1b[1;34m' -acolor2 = '\x1b[0;34m' - -# Ubuntu. -ucolor = '\x1b[1;33m' -ucolor2 = '\x1b[1;31m' -ucolor3 = '\x1b[0;31m' - -# Debian -dcolor = '\x1b[1;31m' -dcolor2 = '\x1b[0;31m' - -# Fedora -fcolor = '\x1b[1;37m' -fcolor2 = '\x1b[1;34m' -fcolor3 = '\x1b[0;34m' - -# CrunchBang -ccolor = '\x1b[0;37m' -ccolor2 = '\x1b[1;37m' - -# Mint -mcolor = '\x1b[1;37m' -mcolor2 = '\x1b[1;32m' +blackB = '\x1b[0;30m' +blackB = '\x1b[1;30m' +redN = '\x1b[0;31m' +redB = '\x1b[1;31m' +greenN = '\x1b[0;32m' +greenB = '\x1b[1;32m' +yellowN = '\x1b[0;33m' +yellowB = '\x1b[1;33m' +blueN = '\x1b[0;34m' +blueB = '\x1b[1;34m' +magentaN = '\x1b[0;35m' +magentaB = '\x1b[1;35m' +cyanN = '\x1b[0;36m' +cyanB = '\x1b[1;36m' +whiteN = '\x1b[0;37m' +whiteB = '\x1b[1;37m' # Find running processes. def xmonadfix(str): @@ -130,17 +120,17 @@ DetectDistro = Popen(['lsb_release', '-i'], stdout=PIPE).communicate()[0].split( # Print coloured key with normal value. def output(key, value): if DetectDistro == 'Ubuntu': - output ='%s%s:%s %s' % (ucolor2, key, clear, value) + output ='%s%s:%s %s' % (redB, key, clear, value) if DetectDistro == 'Arch': - output = '%s%s:%s %s' % (acolor, key, clear, value) + output = '%s%s:%s %s' % (blueB, key, clear, value) if DetectDistro == 'Debian': - output = '%s%s:%s %s' % (dcolor, key, clear, value) + output = '%s%s:%s %s' % (redB, key, clear, value) if DetectDistro == 'Fedora': - output = '%s%s:%s %s' % (fcolor2, key, clear, value) + output = '%s%s:%s %s' % (blueB, key, clear, value) if DetectDistro == 'CrunchBang': - output = '%s%s:%s %s' % (ccolor, key, clear, value) + output = '%s%s:%s %s' % (whiteN, key, clear, value) if DetectDistro == 'LinuxMint': - output = '%s%s:%s %s' % (mcolor2, key, clear, value) + output = '%s%s:%s %s' % (greenB, key, clear, value) result.append(output) # RAM Function. @@ -148,8 +138,17 @@ def ram_display(): raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].split('\n') ram = ''.join(filter(re.compile('M').search, raminfo)).split() used = int(ram[2]) - int(ram[5]) - int(ram[6]) - output ('RAM', '%s MB / %s MB' % (used, ram[1])) - + usedpercent = ((float(used) / float(ram[1])) * 100) + if usedpercent <= 33: + ramdisplay = '%s%s MB %s/ %s MB' % (greenB, used, clear, ram[1]) + output('RAM', ramdisplay) + if usedpercent >= 34 <= 66: + ramdisplay = '%s%s MB %s/ %s MB' % (whiteB, used, clear, ram[1]) + output('RAM', ramdisplay) + if usedpercent >= 67: + ramdisplay = '%s%s MB %s/ %s MB' % (redB, used, clear, ram[1]) + output('RAM', ramdisplay) + # Screenshot Function. screen = '%s' % options.screenshot def screenshot(): @@ -189,10 +188,14 @@ def kernel_display(): kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') output ('Kernel', kernel) +def user_display(): + username= os.getenv('USER') + output ('User', username) + # Hostname Function. def hostname_display(): hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].rstrip('\n') - output ('Hostname', hostname) + output('Hostname', hostname) # CPU Function. def cpu_display(): @@ -218,7 +221,6 @@ def uptime_display(): # Desktop Environment Function. def de_display(): - de = 'None found' for key in de_dict.keys(): if key in processes: de = de_dict[key] @@ -226,7 +228,6 @@ def de_display(): # Window Manager Function. def wm_display(): - wm = 'None found' for key in wm_dict.keys(): if key in processes: wm = wm_dict[key] @@ -278,25 +279,24 @@ def packages_display(): packages = p3.communicate()[0].rstrip('\n') output ('Packages', packages) -# File System Function. -def fs_display(): - supported = ('ext2', 'ext3', 'ext4', 'reiserfs', 'jfs', 'ntfs', 'fat32', 'btrfs', 'fuseblk') - p1 = Popen(['df', '-TPh'], stdout=PIPE).communicate()[0] - filesystems = p1.rstrip().split('\n') - del filesystems[0] - - for fs in filesystems: - fs_split = fs.split() - used = fs_split[3] - total = fs_split[2] - type = fs_split[1] - name = fs_split[6] - part = '%s / %s (%s)' % (used, total, type) - if name == '/': name = '/root' - fs = name.rpartition('/')[2].title() + " FS" - if type in supported: - output (fs, part) - +# Disk Function. +def disk_display(): + p1 = Popen(['df', '-Tlh', '--total', '-t', 'ext4', '-t', 'ext3', '-t', 'ext2', '-t', 'reiserfs', '-t', 'jfs', '-t', 'ntfs', '-t', 'fat32', '-t', 'btrfs', '-t', 'fuseblk'], stdout=PIPE).communicate()[0] + total = p1.splitlines()[-1] + used = total.split()[3] + size = total.split()[2] + usedpercentage = float(re.sub("[A-Z]", "", used)) / float(re.sub("[A-Z]", "", size)) * 100 + if usedpercentage <= 33: + fs = '%s%s %s/ %s' % (greenB, used, clear, size) + output ('Disk', fs) + if usedpercentage > 33 < 67: + fs = '%s%s %s/ %s' % (yellowB, used, clear, size) + output ('Disk', fs) + if usedpercentage >= 67: + fs = '%s%s %s/ %s' % (redB, used, clear, size) + output ('Disk', fs) + + # Run functions found in 'display' array. for x in display: funcname=x+'_display' @@ -327,7 +327,7 @@ if DetectDistro == 'Ubuntu': %s `.:://::- %s-:::::; %s %s `.-:-' %s %s %s -%s""" % ( ucolor3, result[0], ucolor2, ucolor3, result[1], ucolor2, ucolor3, result[2], ucolor, ucolor2, ucolor3, result[3], ucolor, ucolor2, result[4], ucolor, ucolor2, result[5], ucolor2, ucolor, ucolor2, result[6], ucolor2, ucolor, ucolor2, result[7], ucolor2, ucolor, result[8], ucolor2, ucolor, ucolor3, result[9], ucolor2, ucolor, ucolor3, result[10], ucolor, ucolor3, result[11], ucolor, ucolor3, result[12], ucolor, ucolor3, ucolor, result[13], ucolor3, ucolor, result[14], ucolor3, ucolor, result[15], ucolor, result[16], ucolor, result[17], clear ) +%s""" % ( redN, result[0], redB, redN, result[1], redB, redN, result[2], yellowB, redB, redN, result[3], yellowB, redB, result[4], yellowB, redB, result[5], redB, yellowB, redB, result[6], redB, yellowB, redB, result[7], redB, yellowB, result[8], redB, yellowB, redN, result[9], redB, yellowB, redN, result[10], yellowB, redN, result[11], yellowB, redN, result[12], yellowB, redN, yellowB, result[13], redN, yellowB, result[14], redN, yellowB, result[15], yellowB, result[16], yellowB, result[17], clear ) if DetectDistro == 'Arch': print """%s @@ -348,7 +348,7 @@ if DetectDistro == 'Arch': %s ######' '###### %s %s ;#### ####; %s %s ##' '## %s -%s #' `# %s%s """ % (acolor, acolor, result[0], acolor, result[1], acolor, result[2], acolor, result[3], acolor, result[4], acolor, result[5], acolor, result[6], acolor, result[7], acolor, acolor2, acolor, result[8], acolor, acolor2, acolor, result[9], acolor, acolor2, result[10], acolor2, result[11], acolor2, result[12], acolor2, result[13], acolor2, result[14], acolor2, result[15], acolor2, result[16], acolor2, result[17], clear) +%s #' `# %s%s """ % (blueB, blueB, result[0], blueB, result[1], blueB, result[2], blueB, result[3], blueB, result[4], blueB, result[5], blueB, result[6], blueB, result[7], blueB, blueN, blueB, result[8], blueB, blueN, blueB, result[9], blueB, blueN, result[10], blueN, result[11], blueN, result[12], blueN, result[13], blueN, result[14], blueN, result[15], blueN, result[16], blueN, result[17], clear) if DetectDistro == 'Debian': print """%s @@ -370,7 +370,7 @@ if DetectDistro == 'Debian': %s -)SSL,, %s %s ~~~~~ %s %s %s -%s """ % (dcolor, dcolor, result[0], dcolor, result[1], dcolor, result[2], dcolor, result[3], dcolor, result[4], dcolor, result[5], dcolor, result[6], dcolor, result[7], dcolor, result[8], dcolor2, result[9], dcolor2, result[10], dcolor2, result[11], dcolor2, result[12], dcolor2, result[13], dcolor2, result[14], dcolor2, result[15], dcolor2, result[16], dcolor2, result[17], clear) +%s """ % (redB, redB, result[0], redB, result[1], redB, result[2], redB, result[3], redB, result[4], redB, result[5], redB, result[6], redB, result[7], redB, result[8], redN, result[9], redN, result[10], redN, result[11], redN, result[12], redN, result[13], redN, result[14], redN, result[15], redN, result[16], redN, result[17], clear) if DetectDistro == 'Fedora': print """ @@ -392,7 +392,7 @@ if DetectDistro == 'Fedora': %s :------%s:://:%s-----------:// %s %s :--------------------:// %s %s %s -%s """ % ( fcolor3, result[0], fcolor3, result[1], fcolor3, fcolor, fcolor3, result[2], fcolor3, fcolor, fcolor3, result[3], fcolor3, fcolor, fcolor3, result[4], fcolor3, fcolor, fcolor3, result[5], fcolor3, fcolor, fcolor3, result[6], fcolor3, fcolor, fcolor3, result[7], fcolor3, fcolor, fcolor3, result[8], fcolor3, fcolor, fcolor3, result[9], fcolor3, fcolor, fcolor3, result[10], fcolor3, fcolor, fcolor3, result[11], fcolor3, fcolor, fcolor3, result[12], fcolor3, fcolor, fcolor3, result[13], fcolor3, fcolor, fcolor3, result[14], fcolor3, fcolor, fcolor3, result[15], fcolor3, result[16], fcolor3, result[17], clear ) +%s """ % ( blueN, result[0], blueN, result[1], blueN, whiteB, blueN, result[2], blueN, whiteB, blueN, result[3], blueN, whiteB, blueN, result[4], blueN, whiteB, blueN, result[5], blueN, whiteB, blueN, result[6], blueN, whiteB, blueN, result[7], blueN, whiteB, blueN, result[8], blueN, whiteB, blueN, result[9], blueN, whiteB, blueN, result[10], blueN, whiteB, blueN, result[11], blueN, whiteB, blueN, result[12], blueN, whiteB, blueN, result[13], blueN, whiteB, blueN, result[14], blueN, whiteB, blueN, result[15], blueN, result[16], blueN, result[17], clear ) if DetectDistro == 'CrunchBang': print """ @@ -414,7 +414,7 @@ if DetectDistro == 'CrunchBang': %s /__/ /__/ |_| %s %s %s %s %s -%s""" % ( ccolor, result[0], ccolor, result[1], ccolor, result[2], ccolor, result[3], ccolor, result[4], ccolor, result[5], ccolor, result[6], ccolor, result[7], ccolor, result[8], ccolor, result[9], ccolor, result[10], ccolor, result[11], ccolor, result[12], ccolor, result[13], ccolor, result[14], ccolor, result[15], ccolor, result[16], ccolor, result[17], clear ) +%s""" % ( whiteN, result[0], whiteN, result[1], whiteN, result[2], whiteN, result[3], whiteN, result[4], whiteN, result[5], whiteN, result[6], whiteN, result[7], whiteN, result[8], whiteN, result[9], whiteN, result[10], whiteN, result[11], whiteN, result[12], whiteN, result[13], whiteN, result[14], whiteN, result[15], whiteN, result[16], whiteN, result[17], clear ) if DetectDistro == 'LinuxMint': print """%s %s @@ -435,7 +435,7 @@ if DetectDistro == 'LinuxMint': %s ./ydNMMMMMMMMMMMMMMMMMMMMM %s %s %s %s %s -%s""" % ( mcolor, result[0], mcolor, result[1], mcolor, result[2], mcolor, mcolor2, mcolor, result[3], mcolor, mcolor2, mcolor, result[4], mcolor, mcolor2, mcolor, result[5], mcolor, mcolor2, mcolor, result[6], mcolor, mcolor2, mcolor, result[7], mcolor, mcolor2, mcolor, result[8], mcolor, mcolor2, mcolor, result[9], mcolor, mcolor2, mcolor, result[10], mcolor, mcolor2, mcolor, result[11], mcolor, mcolor2, mcolor, result[12], mcolor, mcolor2, mcolor, result[13], mcolor, result[14], mcolor, result[15], mcolor, result[16], mcolor, result[17], clear ) +%s""" % ( whiteB, result[0], whiteB, result[1], whiteB, result[2], whiteB, greenB, whiteB, result[3], whiteB, greenB, whiteB, result[4], whiteB, greenB, whiteB, result[5], whiteB, greenB, whiteB, result[6], whiteB, greenB, whiteB, result[7], whiteB, greenB, whiteB, result[8], whiteB, greenB, whiteB, result[9], whiteB, greenB, whiteB, result[10], whiteB, greenB, whiteB, result[11], whiteB, greenB, whiteB, result[12], whiteB, greenB, whiteB, result[13], whiteB, result[14], whiteB, result[15], whiteB, result[16], whiteB, result[17], clear ) if screen == 'True': screenshot() -- cgit v1.2.3-54-g00ecf From 2637eb7e8f4a31e5aa2df00ef5cd9c41453b1644 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Mon, 4 Oct 2010 23:06:39 -0700 Subject: minor bug fix in disk function --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index e345b78..431e88e 100644 --- a/archey +++ b/archey @@ -289,7 +289,7 @@ def disk_display(): if usedpercentage <= 33: fs = '%s%s %s/ %s' % (greenB, used, clear, size) output ('Disk', fs) - if usedpercentage > 33 < 67: + if usedpercentage > 33 and usedpercentage < 67: fs = '%s%s %s/ %s' % (yellowB, used, clear, size) output ('Disk', fs) if usedpercentage >= 67: -- cgit v1.2.3-54-g00ecf From e163e7d79396d8899dc6f3e225faaaa0668f3299 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 4 Oct 2010 23:09:14 -0700 Subject: fixed minor bug in ram function --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 431e88e..89f1a58 100644 --- a/archey +++ b/archey @@ -142,7 +142,7 @@ def ram_display(): if usedpercent <= 33: ramdisplay = '%s%s MB %s/ %s MB' % (greenB, used, clear, ram[1]) output('RAM', ramdisplay) - if usedpercent >= 34 <= 66: +if usedpercentage > 33 and usedpercentage < 67: ramdisplay = '%s%s MB %s/ %s MB' % (whiteB, used, clear, ram[1]) output('RAM', ramdisplay) if usedpercent >= 67: -- cgit v1.2.3-54-g00ecf From 4a64fa86cd9805816d98ab029ba86ee4489ce41c Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 4 Oct 2010 23:10:11 -0700 Subject: indentation error --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 89f1a58..5ca668b 100644 --- a/archey +++ b/archey @@ -142,7 +142,7 @@ def ram_display(): if usedpercent <= 33: ramdisplay = '%s%s MB %s/ %s MB' % (greenB, used, clear, ram[1]) output('RAM', ramdisplay) -if usedpercentage > 33 and usedpercentage < 67: + if usedpercentage > 33 and usedpercentage < 67: ramdisplay = '%s%s MB %s/ %s MB' % (whiteB, used, clear, ram[1]) output('RAM', ramdisplay) if usedpercent >= 67: -- cgit v1.2.3-54-g00ecf From 4b07219fb7f0b22a735da5c1ecef627dd9c08500 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 4 Oct 2010 23:11:41 -0700 Subject: small cleanup --- archey | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/archey b/archey index 5ca668b..a584106 100644 --- a/archey +++ b/archey @@ -142,7 +142,7 @@ def ram_display(): if usedpercent <= 33: ramdisplay = '%s%s MB %s/ %s MB' % (greenB, used, clear, ram[1]) output('RAM', ramdisplay) - if usedpercentage > 33 and usedpercentage < 67: + if usedpercent > 33 and usedpercentage < 67: ramdisplay = '%s%s MB %s/ %s MB' % (whiteB, used, clear, ram[1]) output('RAM', ramdisplay) if usedpercent >= 67: @@ -285,14 +285,14 @@ def disk_display(): total = p1.splitlines()[-1] used = total.split()[3] size = total.split()[2] - usedpercentage = float(re.sub("[A-Z]", "", used)) / float(re.sub("[A-Z]", "", size)) * 100 - if usedpercentage <= 33: + usedpercent = float(re.sub("[A-Z]", "", used)) / float(re.sub("[A-Z]", "", size)) * 100 + if usedpercent <= 33: fs = '%s%s %s/ %s' % (greenB, used, clear, size) output ('Disk', fs) - if usedpercentage > 33 and usedpercentage < 67: + if usedpercent > 33 and usedpercentage < 67: fs = '%s%s %s/ %s' % (yellowB, used, clear, size) output ('Disk', fs) - if usedpercentage >= 67: + if usedpercent >= 67: fs = '%s%s %s/ %s' % (redB, used, clear, size) output ('Disk', fs) -- cgit v1.2.3-54-g00ecf From 52fcf570a3ba2ed013e4fa50d42528c0d46fd2cd Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 4 Oct 2010 23:12:54 -0700 Subject: im stupid --- archey | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archey b/archey index a584106..48a034a 100644 --- a/archey +++ b/archey @@ -142,7 +142,7 @@ def ram_display(): if usedpercent <= 33: ramdisplay = '%s%s MB %s/ %s MB' % (greenB, used, clear, ram[1]) output('RAM', ramdisplay) - if usedpercent > 33 and usedpercentage < 67: + if usedpercent > 33 and usedpercent < 67: ramdisplay = '%s%s MB %s/ %s MB' % (whiteB, used, clear, ram[1]) output('RAM', ramdisplay) if usedpercent >= 67: @@ -289,7 +289,7 @@ def disk_display(): if usedpercent <= 33: fs = '%s%s %s/ %s' % (greenB, used, clear, size) output ('Disk', fs) - if usedpercent > 33 and usedpercentage < 67: + if usedpercent > 33 and usedpercent < 67: fs = '%s%s %s/ %s' % (yellowB, used, clear, size) output ('Disk', fs) if usedpercent >= 67: -- cgit v1.2.3-54-g00ecf From d58a59df9803e3a1769e969cd7d539c2df52bc5a Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 4 Oct 2010 23:15:12 -0700 Subject: changed ramdisplay color from white to yellow --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 48a034a..db584b5 100644 --- a/archey +++ b/archey @@ -143,7 +143,7 @@ def ram_display(): ramdisplay = '%s%s MB %s/ %s MB' % (greenB, used, clear, ram[1]) output('RAM', ramdisplay) if usedpercent > 33 and usedpercent < 67: - ramdisplay = '%s%s MB %s/ %s MB' % (whiteB, used, clear, ram[1]) + ramdisplay = '%s%s MB %s/ %s MB' % (yellowB, used, clear, ram[1]) output('RAM', ramdisplay) if usedpercent >= 67: ramdisplay = '%s%s MB %s/ %s MB' % (redB, used, clear, ram[1]) -- cgit v1.2.3-54-g00ecf From acde2bdbfd2e529c2740e63096ceb6bf348dc053 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Tue, 5 Oct 2010 15:55:11 -0700 Subject: reordered output --- archey | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/archey b/archey index db584b5..f37ead8 100644 --- a/archey +++ b/archey @@ -28,12 +28,12 @@ display = [ 'uptime', # Display System Uptime 'wm', # Display Window Manager 'de', # Display Desktop Environment - 'packages', # Display Number of Packages Installed - 'ram', # Display RAM Usage - 'cpu', # Display CPU Model 'sh', # Display Current Shell 'term', # Display Current Terminal - 'disk' # Display / Partition Usage + 'packages', # Display Number of Packages Installed + 'cpu', # Display CPU Model + 'ram', # Display RAM Usage + 'disk' # Display Disk Usage ] # Array containing Values -- cgit v1.2.3-54-g00ecf From 77d72c8a9738bdac3dece9546e144febd78ccafd Mon Sep 17 00:00:00 2001 From: DjMelik Date: Thu, 21 Oct 2010 12:38:06 -0700 Subject: Python to Python2 --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index f37ead8..239b000 100644 --- a/archey +++ b/archey @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # # Archey [version 0.2.8] # -- cgit v1.2.3-54-g00ecf From d96d929bfbd4812504565f430fbf0a5d3cf8642e Mon Sep 17 00:00:00 2001 From: DjMelik Date: Wed, 17 Nov 2010 01:44:44 -0800 Subject: initial push for archey in puthon3 --- archey.new | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 archey.new diff --git a/archey.new b/archey.new new file mode 100644 index 0000000..8ece278 --- /dev/null +++ b/archey.new @@ -0,0 +1,206 @@ +#!/usr/bin/env python +# +# Archey [version 0.3.0] +# +# Archey is a simple system information tool written in Python. +# +# Copyright 2010 Melik Manukyan +# +# ASCII art by Brett Bohnenkamper +# Changes Jerome Launay +# Fedora support by YeOK +# +# Distributed under the terms of the GNU General Public License v3. +# See http://www.gnu.org/licenses/gpl.txt for the full license text. + +# Import libraries +import os, sys, subprocess, optparse, re, linecache +from subprocess import Popen, PIPE +from optparse import OptionParser +from getpass import getuser +from time import ctime, sleep + +# Output [Comment/Uncomment to Enable/Disable information.] + +output = [ + 'User', # Output Username + 'Hostname', # Output Machine Hostname + 'Distro', # Output Distribution + 'Kernel', # Output Kernel Version + 'Uptime', # Output System Uptime + 'WindowManager', # Output Window Manager + 'DesktopEnvironment', # Output Desktop Environment + 'Shell', # Output Current Shell + 'Terminal', # Output Current Terminal + 'Packages', # Output Number of Packages Installed + 'CPU', # Output CPU Model + 'RAM', # Output RAM Usage + 'Disk' # Output Disk Usage + ] + +#---------------Dictionaries---------------# + +colorDict = { + 'Arch Linux': ['\x1b[0;34m', '\x1b[1;34m'], + 'Ubuntu': ['\x1b[0;31m', '\x1b[1;31m', '\x1b[0;33m'], + 'Debian': ['\x1b[0;31m', '\x1b[1;31m'], + 'Mint': ['\x1b[0;32m', '\x1b[1;37m'], + 'Crunchbang': ['\x1b[1;37m'], + 'Fedora': ['\x1b[0;34m', '\x1b[1;37m'], + 'Clear': ['\x1b[0m'] + } + +deDict = { + 'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfce4-session': 'Xfce', + 'lxsession': 'LXDE' + } +wmDict = { + 'awesome': 'Awesome', + 'beryl': 'Beryl', + 'blackbox': 'Blackbox', + 'compiz': 'Compiz', + 'dwm': 'DWM', + 'enlightenment': 'Enlightenment', + 'fluxbox': 'Fluxbox', + 'fvwm': 'FVWM', + 'i3': 'i3', + 'icewm': 'IceWM', + 'kwin': 'KWin', + 'metacity': 'Metacity', + 'musca': 'Musca', + 'openbox': 'Openbox', + 'pekwm': 'PekWM', + 'ratpoison': 'ratpoison', + 'scrotwm': 'ScrotWM', + 'wmaker': 'Window Maker', + 'wmfs': 'Wmfs', + 'wmii': 'wmii', + 'xfwm4': 'Xfwm', + 'xmonad': 'xmonad' + } + +# Logos # +logos = {'Arch Linux': '''{color[1]} +{color[1]} + {results[0]} +{color[1]} # {results[1]} +{color[1]} ### {results[2]} +{color[1]} ##### {results[3]} +{color[1]} ###### {results[4]} +{color[1]} ; #####; {results[5]} +{color[1]} +##.##### {results[6]} +{color[1]} +########## {results[7]} +{color[1]} ######{color[0]}#####{color[1]}##; {results[8]} +{color[1]} ###{color[0]}############{color[1]}+ {results[9]} +{color[1]} #{color[0]}###### ####### {results[10]} +{color[0]} .######; ;###;`\". {results[11]} +{color[0]} .#######; ;#####. {results[12]} +{color[0]} #########. .########` {results[13]} +{color[0]} ######' '###### {results[14]} +{color[0]} ;#### ####; {results[15]} +{color[0]} ##' '## {results[16]} +{color[0]} #' `# {results[17]} +\x1b[0m''' +} + +#---------------Classes---------------# +class Output: + results = [] + results.extend(['']*(14)) + + def __init__(self): + self.distro = self.__detectDistro() + + def __detectDistro(self): + if open('/etc/pacman.conf'): + return 'Arch Linux' + + def append(self, display): + self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) + + def output(self): + print(logos[self.distro].format(color = colorDict[self.distro], results = self.results)) + +class User(Output): + def __init__(self): + self.key = 'User' + self.value = os.getenv('USER') + +#class Hostname(Output): +# def __init__(self): + +#class Distro(Output): +# def __init__(self): + +#class Kernel(Output): +# def __init__(self): + +class Uptime(Output): + def __init__(self): + fuptime = int(open('/proc/uptime').read().split('.')[0]) + day = int(fuptime / 86400) + fuptime = fuptime % 86400 + hour = int(fuptime / 3600) + fuptime = fuptime % 3600 + minute = int(fuptime / 60) + uptime = '' + if day == 1: + uptime += '%d day, ' % day + if day > 1: + uptime += '%d days, ' % day + uptime += '%d:%02d' % (hour, minute) + self.key = 'Uptime' + self.value = uptime + +#class WindowManager(Output): +# def __init__(self): +# wm = '' +# for key in wmDict.keys(): +# if processes(key): +# wm = key +# break +# +# self.key = 'Window Manager' +# self.value = wm + +#class DesktopEnvironment(Output): +# def __init__(self): +# de = '' +# for key in deDict.keys(): +# if processes(key): +# wm = key +# break +# +# self.key = 'Desktop Environment' +# self.value = de + +class Shell(Output): + def __init__(self): + self.key = 'Shell' + self.value = os.getenv('SHELL') + +class Terminal(Output): + def __init__(self): + self.key = 'Terminal' + self.value = os.getenv('TERM') + +#class Packages(Output): +# def __init__(self): + +#class CPU(Output): +# def __init__(self): + +#class RAM(Output): +# def __init__(self): + +#class Disk(Output): +# def __init__(self): + + +out = Output() +out.append(Shell()) +out.append(User()) +out.append(Terminal()) +out.append(Uptime()) +out.output() -- cgit v1.2.3-54-g00ecf From 66ad07848e4447bfac54eeac936b61c60e9c3a0b Mon Sep 17 00:00:00 2001 From: DjMelik Date: Wed, 17 Nov 2010 01:48:07 -0800 Subject: cleanup --- archey.new | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/archey.new b/archey.new index 8ece278..dd157ad 100644 --- a/archey.new +++ b/archey.new @@ -55,7 +55,8 @@ deDict = { 'ksmserver': 'KDE', 'xfce4-session': 'Xfce', 'lxsession': 'LXDE' - } + } + wmDict = { 'awesome': 'Awesome', 'beryl': 'Beryl', @@ -128,13 +129,13 @@ class User(Output): self.value = os.getenv('USER') #class Hostname(Output): -# def __init__(self): +# def __init__(self): #class Distro(Output): -# def __init__(self): +# def __init__(self): #class Kernel(Output): -# def __init__(self): +# def __init__(self): class Uptime(Output): def __init__(self): @@ -165,34 +166,34 @@ class Uptime(Output): # self.value = wm #class DesktopEnvironment(Output): -# def __init__(self): -# de = '' -# for key in deDict.keys(): -# if processes(key): -# wm = key -# break +# def __init__(self): +# de = '' +# for key in deDict.keys(): +# if processes(key): +# wm = key +# break # -# self.key = 'Desktop Environment' -# self.value = de +# self.key = 'Desktop Environment' +# self.value = de class Shell(Output): - def __init__(self): - self.key = 'Shell' - self.value = os.getenv('SHELL') + def __init__(self): + self.key = 'Shell' + self.value = os.getenv('SHELL') class Terminal(Output): - def __init__(self): - self.key = 'Terminal' - self.value = os.getenv('TERM') + def __init__(self): + self.key = 'Terminal' + self.value = os.getenv('TERM') #class Packages(Output): -# def __init__(self): +# def __init__(self): #class CPU(Output): -# def __init__(self): +# def __init__(self): #class RAM(Output): -# def __init__(self): +# def __init__(self): #class Disk(Output): # def __init__(self): -- cgit v1.2.3-54-g00ecf From 97b6966efc517825d0d6a8d25decac33bc5e4ff1 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 17 Nov 2010 01:59:05 -0800 Subject: Check if file exists instead of opening it. --- archey.new | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey.new b/archey.new index dd157ad..b3b2521 100644 --- a/archey.new +++ b/archey.new @@ -114,7 +114,7 @@ class Output: self.distro = self.__detectDistro() def __detectDistro(self): - if open('/etc/pacman.conf'): + if os.path.exists('/etc/pacman.conf'): return 'Arch Linux' def append(self, display): -- cgit v1.2.3-54-g00ecf From 5e77c74057e2167bbebabacd14790aa10476d93e Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 17 Nov 2010 02:03:00 -0800 Subject: No need to inherit from Output class. --- archey.new | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/archey.new b/archey.new index b3b2521..1a7ced6 100644 --- a/archey.new +++ b/archey.new @@ -123,21 +123,21 @@ class Output: def output(self): print(logos[self.distro].format(color = colorDict[self.distro], results = self.results)) -class User(Output): +class User: def __init__(self): self.key = 'User' self.value = os.getenv('USER') -#class Hostname(Output): +#class Hostname: # def __init__(self): -#class Distro(Output): +#class Distro: # def __init__(self): -#class Kernel(Output): +#class Kernel: # def __init__(self): -class Uptime(Output): +class Uptime: def __init__(self): fuptime = int(open('/proc/uptime').read().split('.')[0]) day = int(fuptime / 86400) @@ -154,7 +154,7 @@ class Uptime(Output): self.key = 'Uptime' self.value = uptime -#class WindowManager(Output): +#class WindowManager: # def __init__(self): # wm = '' # for key in wmDict.keys(): @@ -165,7 +165,7 @@ class Uptime(Output): # self.key = 'Window Manager' # self.value = wm -#class DesktopEnvironment(Output): +#class DesktopEnvironment: # def __init__(self): # de = '' # for key in deDict.keys(): @@ -176,26 +176,26 @@ class Uptime(Output): # self.key = 'Desktop Environment' # self.value = de -class Shell(Output): +class Shell: def __init__(self): self.key = 'Shell' self.value = os.getenv('SHELL') -class Terminal(Output): +class Terminal: def __init__(self): self.key = 'Terminal' self.value = os.getenv('TERM') -#class Packages(Output): +#class Packages: # def __init__(self): -#class CPU(Output): +#class CPU: # def __init__(self): -#class RAM(Output): +#class RAM: # def __init__(self): -#class Disk(Output): +#class Disk: # def __init__(self): -- cgit v1.2.3-54-g00ecf From 8a937f9c9706accce14022b1252784fa45677b69 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 17 Nov 2010 02:06:28 -0800 Subject: If distro not detected, exit with error exit code. --- archey.new | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archey.new b/archey.new index 1a7ced6..70a40b3 100644 --- a/archey.new +++ b/archey.new @@ -116,6 +116,8 @@ class Output: def __detectDistro(self): if os.path.exists('/etc/pacman.conf'): return 'Arch Linux' + else: + sys.exit(1) def append(self, display): self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) -- cgit v1.2.3-54-g00ecf From 1603bfb709671eeabc690ed93b461e152cccde6c Mon Sep 17 00:00:00 2001 From: DjMelik Date: Wed, 17 Nov 2010 02:06:28 -0800 Subject: removed a tab --- archey | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) mode change 100644 => 100755 archey diff --git a/archey b/archey old mode 100644 new mode 100755 index 239b000..ecb82f1 --- a/archey +++ b/archey @@ -88,7 +88,6 @@ sh_dict = { # Define Colour Scheme -clear = '\x1b[0m' blackB = '\x1b[0;30m' blackB = '\x1b[1;30m' redN = '\x1b[0;31m' @@ -287,7 +286,7 @@ def disk_display(): size = total.split()[2] usedpercent = float(re.sub("[A-Z]", "", used)) / float(re.sub("[A-Z]", "", size)) * 100 if usedpercent <= 33: - fs = '%s%s %s/ %s' % (greenB, used, clear, size) + fs = '%s%s %s/ %s' % (greenB, used, , size) output ('Disk', fs) if usedpercent > 33 and usedpercent < 67: fs = '%s%s %s/ %s' % (yellowB, used, clear, size) -- cgit v1.2.3-54-g00ecf From 2448c9325e51e51b8af5f7d7c669fcf7aa9d8947 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Wed, 17 Nov 2010 02:19:43 -0800 Subject: cleanup --- archey.new | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/archey.new b/archey.new index 1a7ced6..373d3b2 100644 --- a/archey.new +++ b/archey.new @@ -20,22 +20,22 @@ from optparse import OptionParser from getpass import getuser from time import ctime, sleep -# Output [Comment/Uncomment to Enable/Disable information.] +#---------------Output---------------# output = [ - 'User', # Output Username - 'Hostname', # Output Machine Hostname - 'Distro', # Output Distribution - 'Kernel', # Output Kernel Version - 'Uptime', # Output System Uptime - 'WindowManager', # Output Window Manager - 'DesktopEnvironment', # Output Desktop Environment - 'Shell', # Output Current Shell - 'Terminal', # Output Current Terminal - 'Packages', # Output Number of Packages Installed - 'CPU', # Output CPU Model - 'RAM', # Output RAM Usage - 'Disk' # Output Disk Usage + 'User', + 'Hostname', + 'Distro', + 'Kernel', + 'Uptime', + 'WindowManager', + 'DesktopEnvironment', + 'Shell', + 'Terminal', + 'Packages', + 'CPU', + 'RAM', + 'Disk' ] #---------------Dictionaries---------------# @@ -51,7 +51,7 @@ colorDict = { } deDict = { - 'gnome-session': 'GNOME', + 'gnome-session': 'GNOME', 'ksmserver': 'KDE', 'xfce4-session': 'Xfce', 'lxsession': 'LXDE' @@ -82,8 +82,7 @@ wmDict = { 'xmonad': 'xmonad' } -# Logos # -logos = {'Arch Linux': '''{color[1]} +logosDict = {'Arch Linux': '''{color[1]} {color[1]} + {results[0]} {color[1]} # {results[1]} {color[1]} ### {results[2]} @@ -106,6 +105,7 @@ logos = {'Arch Linux': '''{color[1]} } #---------------Classes---------------# + class Output: results = [] results.extend(['']*(14)) @@ -121,7 +121,7 @@ class Output: self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) def output(self): - print(logos[self.distro].format(color = colorDict[self.distro], results = self.results)) + print(logosDict[self.distro].format(color = colorDict[self.distro], results = self.results)) class User: def __init__(self): @@ -199,6 +199,7 @@ class Terminal: # def __init__(self): +## TEST ## <<< TEMPORARY out = Output() out.append(Shell()) out.append(User()) -- cgit v1.2.3-54-g00ecf From 29ef86981e54c03488219d425407f50d6fd8b946 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Wed, 17 Nov 2010 02:21:45 -0800 Subject: more cleanup --- archey.new | 2 -- 1 file changed, 2 deletions(-) diff --git a/archey.new b/archey.new index 16e945d..373d3b2 100644 --- a/archey.new +++ b/archey.new @@ -116,8 +116,6 @@ class Output: def __detectDistro(self): if os.path.exists('/etc/pacman.conf'): return 'Arch Linux' - else: - sys.exit(1) def append(self, display): self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) -- cgit v1.2.3-54-g00ecf From fd19001e5f855a26b13eed0674223a96faf65a69 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Wed, 17 Nov 2010 11:41:15 -0800 Subject: added process detection --- archey.new | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/archey.new b/archey.new index 373d3b2..d744d20 100644 --- a/archey.new +++ b/archey.new @@ -104,11 +104,13 @@ logosDict = {'Arch Linux': '''{color[1]} \x1b[0m''' } +processes = Popen(['ps', '-u', getuser()],stdout=PIPE).communicate()[0].split(b'\n') + #---------------Classes---------------# class Output: results = [] - results.extend(['']*(14)) + results.extend(['']*(13)) def __init__(self): self.distro = self.__detectDistro() @@ -116,6 +118,8 @@ class Output: def __detectDistro(self): if os.path.exists('/etc/pacman.conf'): return 'Arch Linux' + else: + sys.exit(1) def append(self, display): self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) @@ -154,27 +158,27 @@ class Uptime: self.key = 'Uptime' self.value = uptime -#class WindowManager: -# def __init__(self): -# wm = '' -# for key in wmDict.keys(): -# if processes(key): -# wm = key -# break -# -# self.key = 'Window Manager' -# self.value = wm +class WindowManager: + def __init__(self): + wm = '' + for key in wmDict.keys(): + if key in processes: + wm = key + break + + self.key = 'Window Manager' + self.value = wm -#class DesktopEnvironment: -# def __init__(self): -# de = '' -# for key in deDict.keys(): -# if processes(key): -# wm = key -# break -# -# self.key = 'Desktop Environment' -# self.value = de +class DesktopEnvironment: + def __init__(self): + de = '' + for key in deDict.keys(): + if key in processes: + wm = wmDict[key] + break + + self.key = 'Desktop Environment' + self.value = de class Shell: def __init__(self): @@ -205,4 +209,6 @@ out.append(Shell()) out.append(User()) out.append(Terminal()) out.append(Uptime()) +out.append(WindowManager()) +#out.append(DesktopEnvirornment()) out.output() -- cgit v1.2.3-54-g00ecf From 1ab3c80e26429b964f41deefba2a831442bdb486 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Wed, 17 Nov 2010 11:49:59 -0800 Subject: spaces > tabs --- archey.new | 76 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/archey.new b/archey.new index d744d20..72a5b3c 100644 --- a/archey.new +++ b/archey.new @@ -51,36 +51,36 @@ colorDict = { } deDict = { - 'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfce4-session': 'Xfce', - 'lxsession': 'LXDE' - } + 'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfce4-session': 'Xfce', + 'lxsession': 'LXDE' + } wmDict = { - 'awesome': 'Awesome', - 'beryl': 'Beryl', - 'blackbox': 'Blackbox', - 'compiz': 'Compiz', - 'dwm': 'DWM', - 'enlightenment': 'Enlightenment', - 'fluxbox': 'Fluxbox', - 'fvwm': 'FVWM', - 'i3': 'i3', - 'icewm': 'IceWM', - 'kwin': 'KWin', - 'metacity': 'Metacity', - 'musca': 'Musca', - 'openbox': 'Openbox', - 'pekwm': 'PekWM', - 'ratpoison': 'ratpoison', - 'scrotwm': 'ScrotWM', - 'wmaker': 'Window Maker', - 'wmfs': 'Wmfs', - 'wmii': 'wmii', - 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad' - } + 'awesome': 'Awesome', + 'beryl': 'Beryl', + 'blackbox': 'Blackbox', + 'compiz': 'Compiz', + 'dwm': 'DWM', + 'enlightenment': 'Enlightenment', + 'fluxbox': 'Fluxbox', + 'fvwm': 'FVWM', + 'i3': 'i3', + 'icewm': 'IceWM', + 'kwin': 'KWin', + 'metacity': 'Metacity', + 'musca': 'Musca', + 'openbox': 'Openbox', + 'pekwm': 'PekWM', + 'ratpoison': 'ratpoison', + 'scrotwm': 'ScrotWM', + 'wmaker': 'Window Maker', + 'wmfs': 'Wmfs', + wmii': 'wmii', + 'xfwm4': 'Xfwm', + 'xmonad': 'xmonad' + } logosDict = {'Arch Linux': '''{color[1]} {color[1]} + {results[0]} @@ -118,8 +118,8 @@ class Output: def __detectDistro(self): if os.path.exists('/etc/pacman.conf'): return 'Arch Linux' - else: - sys.exit(1) + else: + sys.exit(1) def append(self, display): self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) @@ -159,15 +159,15 @@ class Uptime: self.value = uptime class WindowManager: - def __init__(self): - wm = '' - for key in wmDict.keys(): - if key in processes: - wm = key - break + def __init__(self): + wm = '' + for key in wmDict.keys(): + if key in processes: + wm = wmDict[key] + break - self.key = 'Window Manager' - self.value = wm + self.key = 'Window Manager' + self.value = wm class DesktopEnvironment: def __init__(self): -- cgit v1.2.3-54-g00ecf From c86576973cc2a1fca3a83b6ab55e25b2f4d26790 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Wed, 17 Nov 2010 11:52:31 -0800 Subject: added missing ' --- archey.new | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archey.new b/archey.new index 72a5b3c..362dae9 100644 --- a/archey.new +++ b/archey.new @@ -77,7 +77,7 @@ wmDict = { 'scrotwm': 'ScrotWM', 'wmaker': 'Window Maker', 'wmfs': 'Wmfs', - wmii': 'wmii', + 'wmii': 'wmii', 'xfwm4': 'Xfwm', 'xmonad': 'xmonad' } @@ -118,7 +118,7 @@ class Output: def __detectDistro(self): if os.path.exists('/etc/pacman.conf'): return 'Arch Linux' - else: + else: sys.exit(1) def append(self, display): -- cgit v1.2.3-54-g00ecf From 0b79c4fb5fa4b880b95451d90046ead8dc2699e5 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 17 Nov 2010 22:19:37 -0800 Subject: Get a list of processes that actually works. --- archey.new | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archey.new b/archey.new index 362dae9..19d9926 100644 --- a/archey.new +++ b/archey.new @@ -104,7 +104,8 @@ logosDict = {'Arch Linux': '''{color[1]} \x1b[0m''' } -processes = Popen(['ps', '-u', getuser()],stdout=PIPE).communicate()[0].split(b'\n') +processes = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', + '--no-headers')), encoding='utf8').rstrip('\n').split('\n') #---------------Classes---------------# -- cgit v1.2.3-54-g00ecf From 27b9b0cb00bb3912964e8e24b86d310e44e9f35d Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 17 Nov 2010 22:23:15 -0800 Subject: We don't need these imports anymore. --- archey.new | 1 - 1 file changed, 1 deletion(-) diff --git a/archey.new b/archey.new index 19d9926..d5d3450 100644 --- a/archey.new +++ b/archey.new @@ -15,7 +15,6 @@ # Import libraries import os, sys, subprocess, optparse, re, linecache -from subprocess import Popen, PIPE from optparse import OptionParser from getpass import getuser from time import ctime, sleep -- cgit v1.2.3-54-g00ecf From c1de733df7d60518a5309d3602e8e8e601bf87af Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Thu, 18 Nov 2010 17:08:20 +0000 Subject: Converted classes to new style classes. Old style classes (with out a pair of brackets at the end of their name) are due to be depreciated some time in the future. --- archey.new | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/archey.new b/archey.new index d5d3450..2f7a77d 100644 --- a/archey.new +++ b/archey.new @@ -108,7 +108,7 @@ processes = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', #---------------Classes---------------# -class Output: +class Output(): results = [] results.extend(['']*(13)) @@ -127,7 +127,7 @@ class Output: def output(self): print(logosDict[self.distro].format(color = colorDict[self.distro], results = self.results)) -class User: +class User(): def __init__(self): self.key = 'User' self.value = os.getenv('USER') @@ -141,7 +141,7 @@ class User: #class Kernel: # def __init__(self): -class Uptime: +class Uptime(): def __init__(self): fuptime = int(open('/proc/uptime').read().split('.')[0]) day = int(fuptime / 86400) @@ -158,7 +158,7 @@ class Uptime: self.key = 'Uptime' self.value = uptime -class WindowManager: +class WindowManager(): def __init__(self): wm = '' for key in wmDict.keys(): @@ -169,7 +169,7 @@ class WindowManager: self.key = 'Window Manager' self.value = wm -class DesktopEnvironment: +class DesktopEnvironment(): def __init__(self): de = '' for key in deDict.keys(): @@ -180,26 +180,26 @@ class DesktopEnvironment: self.key = 'Desktop Environment' self.value = de -class Shell: +class Shell(): def __init__(self): self.key = 'Shell' self.value = os.getenv('SHELL') -class Terminal: +class Terminal(): def __init__(self): self.key = 'Terminal' self.value = os.getenv('TERM') -#class Packages: +#class Packages(): # def __init__(self): -#class CPU: +#class CPU(): # def __init__(self): -#class RAM: +#class RAM(): # def __init__(self): -#class Disk: +#class Disk(): # def __init__(self): -- cgit v1.2.3-54-g00ecf From 1ba9dc18dcd50e3cbacd42aad53c9ed8a386b122 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Thu, 18 Nov 2010 17:34:36 +0000 Subject: Added @enviromental_variable class decorator. The @enviromental_variable class decorator automaticly generates the value of a class, aslong as it has both a 'key' and a 'env' variable. See the docstring for more info, and example usage. --- archey.new | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/archey.new b/archey.new index 2f7a77d..a67c961 100644 --- a/archey.new +++ b/archey.new @@ -106,6 +106,11 @@ logosDict = {'Arch Linux': '''{color[1]} processes = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', '--no-headers')), encoding='utf8').rstrip('\n').split('\n') + +#--------------Exceptions-------------# + +class ArcheyException(Exception): pass + #---------------Classes---------------# class Output(): @@ -119,7 +124,7 @@ class Output(): if os.path.exists('/etc/pacman.conf'): return 'Arch Linux' else: - sys.exit(1) + sys.exit("Unsupported distro") def append(self, display): self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) @@ -179,16 +184,48 @@ class DesktopEnvironment(): self.key = 'Desktop Environment' self.value = de - -class Shell(): + +def enviroment_variable(klass): + """ + Decorate classes with this decorator. Classes decorated with enviroment_variable will + have their __init__ function automaticly generated. This makes it very easy to write + a class that returns an enviroment variable. + + >>>@enviroment_variable + ...class Lang(): + ... key = 'Language' + ... env = 'LANG' + ... + >>>test = Lang() + >>>import os + >>>assert test.value == os.getenv('LANG') + """ + def __init__(self): - self.key = 'Shell' - self.value = os.getenv('SHELL') - + self.value = os.getenv(self.env) + + if hasattr(klass, 'key') and hasattr(klass, 'env'): + klass.__init__ = __init__ + else: + raise ArcheyException('Classes decorated with @enviroment_variable must have' + 'key and env attributes') + + return klass + +@enviroment_variable +class Shell(): + key = 'Shell' + env = 'SHELL' + +@enviroment_variable class Terminal(): - def __init__(self): - self.key = 'Terminal' - self.value = os.getenv('TERM') + key = 'Terminal' + env = 'TERM' + +@enviroment_variable +class User(): + key = 'User' + env = 'USER' #class Packages(): # def __init__(self): -- cgit v1.2.3-54-g00ecf From 9df585e1a3c97facc97690039c5041d8c548ec6e Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Thu, 18 Nov 2010 18:15:11 +0000 Subject: Added BaseDisplay base class. This class should be inherited by all Display classes. It implements generic display functions, though only repr currently. See help(BaseDisplay) for more info. --- archey.new | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/archey.new b/archey.new index a67c961..7e8b9ab 100644 --- a/archey.new +++ b/archey.new @@ -131,11 +131,28 @@ class Output(): def output(self): print(logosDict[self.distro].format(color = colorDict[self.distro], results = self.results)) - -class User(): + +class BaseDisplay(): + """ + All display classes should inherit this. It defigns several base functions that can be overwritten by any child classes + + >>>import random + >>>class RandomNumber(BaseDisplay): + ... key = 'Random Number' + ... value = random.random() * 1000 + ... + >>>r = RandomNumber() + >>>print `r` + """ + + key = None + value = None + def __init__(self): - self.key = 'User' - self.value = os.getenv('USER') + raise NotImplemented('Display classes must implements their own __init__ function') + + def __repr__(self): + return '<{0}: key={1}, value={2}>'.format(self.__class__.__name__, self.key, self.value) #class Hostname: # def __init__(self): @@ -146,7 +163,7 @@ class User(): #class Kernel: # def __init__(self): -class Uptime(): +class Uptime(BaseDisplay): def __init__(self): fuptime = int(open('/proc/uptime').read().split('.')[0]) day = int(fuptime / 86400) @@ -163,7 +180,7 @@ class Uptime(): self.key = 'Uptime' self.value = uptime -class WindowManager(): +class WindowManager(BaseDisplay): def __init__(self): wm = '' for key in wmDict.keys(): @@ -174,7 +191,7 @@ class WindowManager(): self.key = 'Window Manager' self.value = wm -class DesktopEnvironment(): +class DesktopEnvironment(BaseDisplay): def __init__(self): de = '' for key in deDict.keys(): @@ -213,17 +230,17 @@ def enviroment_variable(klass): return klass @enviroment_variable -class Shell(): +class Shell(BaseDisplay): key = 'Shell' env = 'SHELL' @enviroment_variable -class Terminal(): +class Terminal(BaseDisplay): key = 'Terminal' env = 'TERM' @enviroment_variable -class User(): +class User(BaseDisplay): key = 'User' env = 'USER' -- cgit v1.2.3-54-g00ecf From b05053f73048a8db3383239d882f6efdae50915e Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Thu, 18 Nov 2010 21:20:21 +0000 Subject: Output is now aligned from the center outwards. Renamed globals to uppercase to allow for better understanding. Added Output._getlogo in anticipation of configuration system, and Output._color for convinience. Output._center_results centers a list inside another list of ' 's. Length out outputed list can be given via max_length kwarg. --- archey.new | 104 ++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 83 insertions(+), 21 deletions(-) diff --git a/archey.new b/archey.new index 7e8b9ab..e7dcd3a 100644 --- a/archey.new +++ b/archey.new @@ -39,24 +39,45 @@ output = [ #---------------Dictionaries---------------# -colorDict = { +class NoDeleteDict(dict): + """ + This dict silently disables deletions. This is because allthough we will want users to be able to + edit these dicts from their config files, we don't want them to muck up somthing important, so we + disable deletions to protect them from themselves. + + >>>dic = NoDeleteDict({'a':1, 'b':2}) + + We can still access items normally: + >>>dic['a'] + 1 + + But when we delete items, nothing happens: + >>>del dic['b'] + >>>dic['b'] + 2 + """ + + def __delitem__(self, name): + return + +COLOR_DICT = NoDeleteDict({ 'Arch Linux': ['\x1b[0;34m', '\x1b[1;34m'], 'Ubuntu': ['\x1b[0;31m', '\x1b[1;31m', '\x1b[0;33m'], 'Debian': ['\x1b[0;31m', '\x1b[1;31m'], 'Mint': ['\x1b[0;32m', '\x1b[1;37m'], 'Crunchbang': ['\x1b[1;37m'], 'Fedora': ['\x1b[0;34m', '\x1b[1;37m'], - 'Clear': ['\x1b[0m'] - } + 'Clear': '\x1b[0m' + }) -deDict = { +DE_DICT = NoDeleteDict({ 'gnome-session': 'GNOME', 'ksmserver': 'KDE', 'xfce4-session': 'Xfce', 'lxsession': 'LXDE' - } + }) -wmDict = { +WM_DICT = NoDeleteDict({ 'awesome': 'Awesome', 'beryl': 'Beryl', 'blackbox': 'Blackbox', @@ -79,9 +100,10 @@ wmDict = { 'wmii': 'wmii', 'xfwm4': 'Xfwm', 'xmonad': 'xmonad' - } + }) + -logosDict = {'Arch Linux': '''{color[1]} +LOGO_DICT = NoDeleteDict({'Arch Linux': '''{color[1]} {color[1]} + {results[0]} {color[1]} # {results[1]} {color[1]} ### {results[2]} @@ -100,10 +122,9 @@ logosDict = {'Arch Linux': '''{color[1]} {color[0]} ;#### ####; {results[15]} {color[0]} ##' '## {results[16]} {color[0]} #' `# {results[17]} -\x1b[0m''' -} +\x1b[0m'''}) -processes = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', +PROCESSES = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', '--no-headers')), encoding='utf8').rstrip('\n').split('\n') @@ -115,7 +136,6 @@ class ArcheyException(Exception): pass class Output(): results = [] - results.extend(['']*(13)) def __init__(self): self.distro = self.__detectDistro() @@ -125,12 +145,54 @@ class Output(): return 'Arch Linux' else: sys.exit("Unsupported distro") - + + def _color(self, index): + """ + Returns the escape code for either: + a) The color scheme of the distro value stored in self.distro + or + b) The value of the entry in COLOR_DICT for the key passed + + >>out = Output() + >>out._color(1) == COLOR_DICT[out.distro][1] + >>out._color(out.distro) == COLOR_DICT[out.distro] + """ + + if isinstance(index, str): + return COLOR_DICT[index] + return COLOR_DICT[self.distro][index] + + def _get_logo(self): + return LOGO_DICT[self.distro] + + def _center_results(self, results, max_length=17): + """ + Centers a list of results. Length of desired list can be given via max_length kwarg. + + >>>out = Output() + >>>out._center_results([1]) + [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 1, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] + >>>out._center_results([1], max_length=3) + [' ', 1, ' '] + """ + + length = len(results) + if length > max_length: + return results[:max_length + 1] + + center = int(max_length/2) + start = int(center - length/2) + new_results = list(' ' * max_length) + new_results[start:start + length - 1] = results + + return new_results + def append(self, display): - self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) + self.results.append('%s%s: %s%s' % (self._color(1), display.key, self._color('Clear'), display.value)) def output(self): - print(logosDict[self.distro].format(color = colorDict[self.distro], results = self.results)) + results = self._center_results(self.results) + print(self._get_logo().format(color=self._color(self.distro), results=results)) class BaseDisplay(): """ @@ -183,9 +245,9 @@ class Uptime(BaseDisplay): class WindowManager(BaseDisplay): def __init__(self): wm = '' - for key in wmDict.keys(): - if key in processes: - wm = wmDict[key] + for key in WM_DICT.keys(): + if key in PROCESSES: + wm = WM_DICT[key] break self.key = 'Window Manager' @@ -194,9 +256,9 @@ class WindowManager(BaseDisplay): class DesktopEnvironment(BaseDisplay): def __init__(self): de = '' - for key in deDict.keys(): - if key in processes: - wm = wmDict[key] + for key in DE_DICT.keys(): + if key in PROCESSES: + wm = WM_DICT[key] break self.key = 'Desktop Environment' -- cgit v1.2.3-54-g00ecf From a60f8bed7e85693774951cb4877d793539b6c363 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Thu, 18 Nov 2010 21:25:02 +0000 Subject: Added main function and conditional execution --- archey.new | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/archey.new b/archey.new index e7dcd3a..ec72334 100644 --- a/archey.new +++ b/archey.new @@ -320,11 +320,15 @@ class User(BaseDisplay): ## TEST ## <<< TEMPORARY -out = Output() -out.append(Shell()) -out.append(User()) -out.append(Terminal()) -out.append(Uptime()) -out.append(WindowManager()) -#out.append(DesktopEnvirornment()) -out.output() +def main(): + out = Output() + out.append(Shell()) + out.append(User()) + out.append(Terminal()) + out.append(Uptime()) + out.append(WindowManager()) + #out.append(DesktopEnvirornment()) + out.output() + +if __name__ == '__main__': + main() -- cgit v1.2.3-54-g00ecf From 3e92ed801be456782f0b327d79c7db117a1c40f8 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 13:23:16 +0000 Subject: Base the Output class on the list type for a small speed up. Basing a class on a type implemented in C makes the derived class much faster. It's not much use here, but it's a good habbit. --- archey.new | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/archey.new b/archey.new index ec72334..a5d2a4e 100644 --- a/archey.new +++ b/archey.new @@ -134,11 +134,12 @@ class ArcheyException(Exception): pass #---------------Classes---------------# -class Output(): +class Output(list): results = [] def __init__(self): self.distro = self.__detectDistro() + super().__init__() def __detectDistro(self): if os.path.exists('/etc/pacman.conf'): @@ -188,10 +189,10 @@ class Output(): return new_results def append(self, display): - self.results.append('%s%s: %s%s' % (self._color(1), display.key, self._color('Clear'), display.value)) + super().append('%s%s: %s%s' % (self._color(1), display.key, self._color('Clear'), display.value)) def output(self): - results = self._center_results(self.results) + results = self._center_results(self) print(self._get_logo().format(color=self._color(self.distro), results=results)) class BaseDisplay(): -- cgit v1.2.3-54-g00ecf From a629b153f8d889133e2fb5984321b0626e94443e Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 13:49:19 +0000 Subject: Evaluate display classes at the last minute, and via an accessor function. This allows display classes to implement functions to return their key value pairs, instead of forcing them to do it in the __init__ function. Output.append has been removed, as it is implemented by the inherited list. --- archey.new | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/archey.new b/archey.new index a5d2a4e..8bace5c 100644 --- a/archey.new +++ b/archey.new @@ -187,13 +187,39 @@ class Output(list): new_results[start:start + length - 1] = results return new_results + + def _get_results(self): + """ + Returns a dict of the keys and values of the currently registered display classes. + NOTE: Will not include any key value pairs where either evaluates to False. - def append(self, display): - super().append('%s%s: %s%s' % (self._color(1), display.key, self._color('Clear'), display.value)) + >>>out = Output() + >>>class TestDisplay(): + ... key = 'Foo' + ... value = 'Bar' + ... key_value_pair = lambda self: {self.key: self.value} + ... + >>>out.append(TestDisplay()) + >>>out._get_results() + {'Foo': 'Bar'} + """ + return {key:value for key, value in [disp.key_value_pair() for disp in self] if key and value} def output(self): - results = self._center_results(self) - print(self._get_logo().format(color=self._color(self.distro), results=results)) + """ + Outputs the archey logo and information. Reads Display classes from the internal list, + and formats them, adding color. The final pretty list is then centered (though other alignments + may be added) and printed. + """ + + results = self._get_results() + + unformatted_stn = '{color}{key}: {clear}{value}{clear}' + pretty_results = [unformatted_stn.format(color=self._color(1), key=key, value=value, clear=self._color('Clear')) + for key, value in results.items()] + + centered_results = self._center_results(pretty_results) + print(self._get_logo().format(color=self._color(self.distro), results=centered_results)) class BaseDisplay(): """ @@ -216,6 +242,18 @@ class BaseDisplay(): def __repr__(self): return '<{0}: key={1}, value={2}>'.format(self.__class__.__name__, self.key, self.value) + + def key_value_pair(self): + """ + Returns a tuple of the key and value of the current display. + + >>>disp = BaseDisplay() + >>>disp.key = 'Foo' + >>>disp.value = 'Bar' + >>>disp.key_value_pair() + ('Foo', 'Bar') + """ + return (self.key, self.value) #class Hostname: # def __init__(self): -- cgit v1.2.3-54-g00ecf From 4eba993739576ffd8ba78b7aa76382a344267800 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 14:17:10 +0000 Subject: Added get_value and get_key functions to BaseDisplay class. These allow the key/value to be generated seperatly from the other, as if they are not overridden, they will simply return either the classes key or value attribute. This way they are fully backwards compatible. See the relevent docstring for more information. --- archey.new | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/archey.new b/archey.new index 8bace5c..eb90243 100644 --- a/archey.new +++ b/archey.new @@ -243,6 +243,20 @@ class BaseDisplay(): def __repr__(self): return '<{0}: key={1}, value={2}>'.format(self.__class__.__name__, self.key, self.value) + def get_key(self): + """ + Return the value of the class' key attribute. If classes wish to customise key generation, + they should override this method + """ + return self.key + + def get_value(self): + """ + Return the value of the class' value attribute. If classes wish to customise value generation, + they should override this method + """ + return self.value + def key_value_pair(self): """ Returns a tuple of the key and value of the current display. @@ -253,7 +267,7 @@ class BaseDisplay(): >>>disp.key_value_pair() ('Foo', 'Bar') """ - return (self.key, self.value) + return (self.get_key(), self.get_value()) #class Hostname: # def __init__(self): -- cgit v1.2.3-54-g00ecf From d578a10a5156ad81bb7192f20c39a724437fc021 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 14:30:31 +0000 Subject: Migrated existing display classes to new get_value format. --- archey.new | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/archey.new b/archey.new index eb90243..2f69914 100644 --- a/archey.new +++ b/archey.new @@ -237,9 +237,6 @@ class BaseDisplay(): key = None value = None - def __init__(self): - raise NotImplemented('Display classes must implements their own __init__ function') - def __repr__(self): return '<{0}: key={1}, value={2}>'.format(self.__class__.__name__, self.key, self.value) @@ -278,44 +275,51 @@ class BaseDisplay(): #class Kernel: # def __init__(self): -class Uptime(BaseDisplay): - def __init__(self): +class Uptime(BaseDisplay): + key = 'Uptime' + + def get_uptime(self): fuptime = int(open('/proc/uptime').read().split('.')[0]) day = int(fuptime / 86400) fuptime = fuptime % 86400 hour = int(fuptime / 3600) fuptime = fuptime % 3600 minute = int(fuptime / 60) - uptime = '' - if day == 1: - uptime += '%d day, ' % day - if day > 1: - uptime += '%d days, ' % day - uptime += '%d:%02d' % (hour, minute) - self.key = 'Uptime' - self.value = uptime + + return {'day': day, 'hour': hour, 'minute': minute} + + def get_value(self): + uptime = self.get_uptime() + + if uptime['day']: + value = '{day}{suffix}'.format(day=uptime['day'], suffix='s' if day > 1 else '') + else: + value = '' + value += '{hours}:{mins:02d}'.format(hours=uptime['hour'], mins=uptime['minute']) + return value class WindowManager(BaseDisplay): - def __init__(self): + key = 'Window Manager' + + def get_value(self): wm = '' for key in WM_DICT.keys(): if key in PROCESSES: wm = WM_DICT[key] break - self.key = 'Window Manager' - self.value = wm + return wm class DesktopEnvironment(BaseDisplay): - def __init__(self): + key = 'Desktop Environment' + + def get_value(self): de = '' for key in DE_DICT.keys(): if key in PROCESSES: wm = WM_DICT[key] break - - self.key = 'Desktop Environment' - self.value = de + return wm def enviroment_variable(klass): """ @@ -333,11 +337,11 @@ def enviroment_variable(klass): >>>assert test.value == os.getenv('LANG') """ - def __init__(self): - self.value = os.getenv(self.env) + def get_value(self): + return os.getenv(self.env) if hasattr(klass, 'key') and hasattr(klass, 'env'): - klass.__init__ = __init__ + klass.get_value = get_value else: raise ArcheyException('Classes decorated with @enviroment_variable must have' 'key and env attributes') -- cgit v1.2.3-54-g00ecf From 889f7f0fc2f845df0991ff50e9704b139dacba14 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 14:35:43 +0000 Subject: Allow display classes to fail silently when rendering. --- archey.new | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/archey.new b/archey.new index 2f69914..ed399bc 100644 --- a/archey.new +++ b/archey.new @@ -215,8 +215,16 @@ class Output(list): results = self._get_results() unformatted_stn = '{color}{key}: {clear}{value}{clear}' - pretty_results = [unformatted_stn.format(color=self._color(1), key=key, value=value, clear=self._color('Clear')) - for key, value in results.items()] + pretty_results = [] + for key, value in results.items(): + try: + formatted_stn = unformatted_stn.format(color=self._color(1), key=key, value=value, + clear=self._color('Clear')) + except: + #Fail silently, have a debug option later for noisy fail? + pass + else: + pretty_results.append(formatted_stn) centered_results = self._center_results(pretty_results) print(self._get_logo().format(color=self._color(self.distro), results=centered_results)) -- cgit v1.2.3-54-g00ecf From 661ddb91c49a689e458938d4a1b546ede1f42f44 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 14:42:46 +0000 Subject: Moved the Output.distro variable into a global DISTRO variable. This will allow display classes to calculate output taking into account the distro we are running on. --- archey.new | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/archey.new b/archey.new index ed399bc..f342a08 100644 --- a/archey.new +++ b/archey.new @@ -36,6 +36,10 @@ output = [ 'RAM', 'Disk' ] + +#--------------Exceptions-------------# + +class ArcheyException(Exception): pass #---------------Dictionaries---------------# @@ -127,25 +131,18 @@ LOGO_DICT = NoDeleteDict({'Arch Linux': '''{color[1]} PROCESSES = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', '--no-headers')), encoding='utf8').rstrip('\n').split('\n') - -#--------------Exceptions-------------# - -class ArcheyException(Exception): pass + +def detect_distro(): + if os.path.exists('/etc/pacman.conf'): + return 'Arch Linux' + else: + raise ArcheyException("Unsupported distro") + +DISTRO = detect_distro() #---------------Classes---------------# class Output(list): - results = [] - - def __init__(self): - self.distro = self.__detectDistro() - super().__init__() - - def __detectDistro(self): - if os.path.exists('/etc/pacman.conf'): - return 'Arch Linux' - else: - sys.exit("Unsupported distro") def _color(self, index): """ @@ -161,10 +158,10 @@ class Output(list): if isinstance(index, str): return COLOR_DICT[index] - return COLOR_DICT[self.distro][index] + return COLOR_DICT[DISTRO][index] def _get_logo(self): - return LOGO_DICT[self.distro] + return LOGO_DICT[DISTRO] def _center_results(self, results, max_length=17): """ @@ -227,7 +224,7 @@ class Output(list): pretty_results.append(formatted_stn) centered_results = self._center_results(pretty_results) - print(self._get_logo().format(color=self._color(self.distro), results=centered_results)) + print(self._get_logo().format(color=self._color(DISTRO), results=centered_results)) class BaseDisplay(): """ -- cgit v1.2.3-54-g00ecf From 2509e25926e289ad97febc0e724a9eb4d9006fbe Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 16:17:55 +0000 Subject: Added @shell_command class decorator to make dealing with Display classes. See help(shell_command) for more info --- archey.new | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/archey.new b/archey.new index f342a08..b506264 100644 --- a/archey.new +++ b/archey.new @@ -367,9 +367,45 @@ class Terminal(BaseDisplay): class User(BaseDisplay): key = 'User' env = 'USER' - -#class Packages(): -# def __init__(self): + +def shell_command(klass): + """ + A class decorated with @shell_command will be treated as a class that runs a command, and then parses the output. + + It should have two string members, "command", the command that will be run, and "key", the key for the display. + It should also implement one method, process_output, which should take two arguments, stdout, and stderr, and return + a value to be displayed. + """ + def get_value(self): + cmd = subprocess.Popen(self.command.split(), + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = cmd.communicate() + return self.process_output(stdout.decode('ascii'), stderr.decode('ascii')) + + if not all(hasattr(klass, name) for name in ('command', 'key', 'process_output')): + raise ArcheyException("Classes decorated with @shell_command must have " + "a key and command attributes, and the process_output method") + else: + klass.get_value = get_value + + return klass + +@shell_command +class Packages(BaseDisplay): + key = 'Packman packages' + command = 'pacman -Q' + + def process_output(self, stdout, stderr): + #Return nothing if pacman returns errors + if stderr: + return None + + no_of_packages = len(stdout.split('\n')) + + return str(no_of_packages) + #class CPU(): # def __init__(self): @@ -389,6 +425,7 @@ def main(): out.append(Terminal()) out.append(Uptime()) out.append(WindowManager()) + out.append(Packages()) #out.append(DesktopEnvirornment()) out.output() -- cgit v1.2.3-54-g00ecf From 81aa06f90db4c3560b082a0c5d3c0f9b36e23704 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 19:42:34 +0000 Subject: Allowed classes to take arguments from the display list, with the syntax 'cmdname:arg1,arg2' with no limit on the amount of args. This gives us a flexible framework to give the users more options for our Display classes. Display classes can be acsessed via the Display's 'arguments' attribute. --- archey.new | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/archey.new b/archey.new index b506264..c535262 100644 --- a/archey.new +++ b/archey.new @@ -23,18 +23,12 @@ from time import ctime, sleep output = [ 'User', - 'Hostname', - 'Distro', - 'Kernel', 'Uptime', 'WindowManager', 'DesktopEnvironment', 'Shell', 'Terminal', 'Packages', - 'CPU', - 'RAM', - 'Disk' ] #--------------Exceptions-------------# @@ -242,6 +236,9 @@ class BaseDisplay(): key = None value = None + def __init__(self, args=None): + self.arguments = args or [] + def __repr__(self): return '<{0}: key={1}, value={2}>'.format(self.__class__.__name__, self.key, self.value) @@ -420,14 +417,36 @@ class Packages(BaseDisplay): ## TEST ## <<< TEMPORARY def main(): out = Output() - out.append(Shell()) - out.append(User()) - out.append(Terminal()) - out.append(Uptime()) - out.append(WindowManager()) - out.append(Packages()) - #out.append(DesktopEnvirornment()) + + displays = get_display_objects(output) + + out.extend(displays) out.output() - + +def get_display_objects(names): + """ + Returns a list of display objects, from the names in the list passed to the + function as the first argument. + """ + for raw in names: + if ':' in raw: + name, *raw_arguments = raw.split(':') + if len(raw_arguments) > 1: + raise ArcheyException('Badly formatted argument in "{0}"'.format(raw)) + else: + arguments = [arg for arg in raw_arguments.split(',') if arg] + else: + name = raw + arguments = [] + try: + klass = eval(name) + except: + try: + klass = eval(name.capitalize()) + except: + raise ArcheyException('Could not find display class {0} to use'.format(name)) + + yield klass(arguments) + if __name__ == '__main__': main() -- cgit v1.2.3-54-g00ecf From d499100fff5c8aab3c48aa0c9f1c4628e64a2657 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 19:58:50 +0000 Subject: Added missing comma between uptime days and hours. --- archey.new | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey.new b/archey.new index c535262..5d4a134 100644 --- a/archey.new +++ b/archey.new @@ -294,7 +294,7 @@ class Uptime(BaseDisplay): uptime = self.get_uptime() if uptime['day']: - value = '{day}{suffix}'.format(day=uptime['day'], suffix='s' if day > 1 else '') + value = '{day}{suffix}, '.format(day=uptime['day'], suffix='s' if day > 1 else '') else: value = '' value += '{hours}:{mins:02d}'.format(hours=uptime['hour'], mins=uptime['minute']) -- cgit v1.2.3-54-g00ecf From 5f23927c3beaec3c0e14a7cae5e96eb6a0f97d3e Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 20:00:00 +0000 Subject: DesktopEnvironment was causing exceptions. --- archey.new | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey.new b/archey.new index 5d4a134..a6095c9 100644 --- a/archey.new +++ b/archey.new @@ -319,7 +319,7 @@ class DesktopEnvironment(BaseDisplay): de = '' for key in DE_DICT.keys(): if key in PROCESSES: - wm = WM_DICT[key] + wm = DE_DICT[key] break return wm -- cgit v1.2.3-54-g00ecf From 2572b4e4c55750ec92e4a6f0c00a9dd35db071b8 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 20:08:16 +0000 Subject: Removed 'key' from forced attributes when using @shell_command. --- archey.new | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/archey.new b/archey.new index a6095c9..bb66030 100644 --- a/archey.new +++ b/archey.new @@ -319,9 +319,9 @@ class DesktopEnvironment(BaseDisplay): de = '' for key in DE_DICT.keys(): if key in PROCESSES: - wm = DE_DICT[key] + de = DE_DICT[key] break - return wm + return de def enviroment_variable(klass): """ @@ -381,7 +381,7 @@ def shell_command(klass): stdout, stderr = cmd.communicate() return self.process_output(stdout.decode('ascii'), stderr.decode('ascii')) - if not all(hasattr(klass, name) for name in ('command', 'key', 'process_output')): + if not all(hasattr(klass, name) for name in ('command', 'process_output')): raise ArcheyException("Classes decorated with @shell_command must have " "a key and command attributes, and the process_output method") else: -- cgit v1.2.3-54-g00ecf From be31b219fba56697fa34d43f7b24eb961e53fbc6 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 19 Nov 2010 21:08:59 +0000 Subject: Added file system display class --- archey.new | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/archey.new b/archey.new index bb66030..613f0e2 100644 --- a/archey.new +++ b/archey.new @@ -29,6 +29,7 @@ output = [ 'Shell', 'Terminal', 'Packages', + 'FileSystem:/home', ] #--------------Exceptions-------------# @@ -374,7 +375,8 @@ def shell_command(klass): a value to be displayed. """ def get_value(self): - cmd = subprocess.Popen(self.command.split(), + command = self.command.format(arguments=self.arguments) + cmd = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) @@ -402,7 +404,41 @@ class Packages(BaseDisplay): no_of_packages = len(stdout.split('\n')) return str(no_of_packages) + + +@shell_command +class FileSystem(BaseDisplay): + command = 'df -TPh {arguments[0]}' + + conversions = { + 'k': 2**10, + 'M': 2**20, + 'G': 2**30, + 'T': 2**40, + 'P': 2**50, + } + def get_key(self): + path = self.arguments[0] + name = path.split('/')[-1] + return '{0} FS'.format(name.capitalize()) + + def process_output(self, stdout, stderr): + #Return nothing if pacman returns errors + if stderr: + return None + + stdout = stdout.split('\n') + line = stdout[1] + line = re.sub(r'( +)', r' ', line) + line = line.split(' ') + + persentage = int(line[5][:-1]) + used = line[3] + total = line[2] + fstype = line[1] + + return '{used}/{total} ({fstype})'.format(used=used, total=total, fstype=fstype) #class CPU(): # def __init__(self): @@ -434,7 +470,7 @@ def get_display_objects(names): if len(raw_arguments) > 1: raise ArcheyException('Badly formatted argument in "{0}"'.format(raw)) else: - arguments = [arg for arg in raw_arguments.split(',') if arg] + arguments = [arg for arg in raw_arguments[0].split(',') if arg] else: name = raw arguments = [] -- cgit v1.2.3-54-g00ecf From 8d44e50fe48e049f6c0bc1837c9c4e9d8d8026fe Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 21 Nov 2010 11:32:11 +0000 Subject: Fix syntax error in archey introduced in commit 1603bfb --- archey | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archey b/archey index ecb82f1..239b000 100755 --- a/archey +++ b/archey @@ -88,6 +88,7 @@ sh_dict = { # Define Colour Scheme +clear = '\x1b[0m' blackB = '\x1b[0;30m' blackB = '\x1b[1;30m' redN = '\x1b[0;31m' @@ -286,7 +287,7 @@ def disk_display(): size = total.split()[2] usedpercent = float(re.sub("[A-Z]", "", used)) / float(re.sub("[A-Z]", "", size)) * 100 if usedpercent <= 33: - fs = '%s%s %s/ %s' % (greenB, used, , size) + fs = '%s%s %s/ %s' % (greenB, used, clear, size) output ('Disk', fs) if usedpercent > 33 and usedpercent < 67: fs = '%s%s %s/ %s' % (yellowB, used, clear, size) -- cgit v1.2.3-54-g00ecf From de5f0e186e15f8d29b3d44f54c75105732f21448 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 22 Nov 2010 13:27:15 +0000 Subject: Added config framework file loading. Config file is in $XDG_CONFIG_HOME/archey.py. The config file is non compulsary, and should be treated as dangerous. Currently allowed config options are 'results_align' which can be 'top', 'bottom' or (default) 'center'. 'custom' is also allowed, but the config file must defign a 'custom_align' function taking the list of results, and a max_length kwarg, and returning the aligned results to be outputted. --- archey.new | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/archey.new b/archey.new index 613f0e2..ee03679 100644 --- a/archey.new +++ b/archey.new @@ -180,6 +180,35 @@ class Output(list): return new_results + def _top_results(self, results, max_length=17): + """ + Aligns a list of results to the top. Length of output list given via max_length kwarg. + + >>>out = Output() + >>>out._top_results([1]) + [1, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] + >>>out._top_results([1], max_length=3) + [1, ' ', ' '] + """ + out = results + out.extend(' ' * (max_length - len(results)+1)) + return out + + def _bottom_results(self, results, max_length=17): + """ + Aligns a list of results to the bottom. Length of output list given via max_length kwarg. + + >>>out = Output() + >>>out._bottom_results([1]) + [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 1] + >>>out._bottom_results([1], max_length=3) + [' ', ' ', 1] + """ + out = [] + out.extend(' ' * (max_length - len(results)+1)) + out.extend(results) + return out + def _get_results(self): """ Returns a dict of the keys and values of the currently registered display classes. @@ -196,6 +225,25 @@ class Output(list): {'Foo': 'Bar'} """ return {key:value for key, value in [disp.key_value_pair() for disp in self] if key and value} + + def align_results(self, results, maxsize=17): + alignment_builtins = ['top', 'bottom', 'center', 'custom'] + + try: + align = config.results_align + if align == None or align not in alignment_builtins: + raise Exception() + if align == 'top': + out = self._top_results(results, max_length=17) + elif align == 'bottom': + out = self._bottom_results(results, max_length=17) + elif align == 'custom': + out = config.custom_align(results, max_length=17) + else: + out = self._center_results(results, max_length=17) + except: + out = self._center_results(results, max_length=17) + return out def output(self): """ @@ -218,8 +266,9 @@ class Output(list): else: pretty_results.append(formatted_stn) - centered_results = self._center_results(pretty_results) - print(self._get_logo().format(color=self._color(DISTRO), results=centered_results)) + aligned_results = self.align_results(pretty_results) + + print(self._get_logo().format(color=self._color(DISTRO), results=aligned_results)) class BaseDisplay(): """ @@ -452,6 +501,9 @@ class FileSystem(BaseDisplay): ## TEST ## <<< TEMPORARY def main(): + global config + config = load_config() + out = Output() displays = get_display_objects(output) @@ -483,6 +535,27 @@ def get_display_objects(names): raise ArcheyException('Could not find display class {0} to use'.format(name)) yield klass(arguments) + +def load_config(): + """ + Imports the config file. + """ + config_dir = os.getenv('XDG_CONFIG_HOME') + sys.path.append(config_dir) + try: + import archey as config + except ImportError: + class config(): + defaults = {} + + def __getattr__(self, name): + if name in self.defaults.keys(): + return self.defaults[name] + else: + return None + + return config + if __name__ == '__main__': main() -- cgit v1.2.3-54-g00ecf From 918cdeb222e4bdb936f9c21e9108877215565f2b Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 22 Nov 2010 13:41:53 +0000 Subject: Display modules can now be configured in the configuration file. The configuration file show defign a list of strings refering to display classes named 'display'. --- archey.new | 55 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/archey.new b/archey.new index ee03679..5d2b25f 100644 --- a/archey.new +++ b/archey.new @@ -21,16 +21,7 @@ from time import ctime, sleep #---------------Output---------------# -output = [ - 'User', - 'Uptime', - 'WindowManager', - 'DesktopEnvironment', - 'Shell', - 'Terminal', - 'Packages', - 'FileSystem:/home', - ] + #--------------Exceptions-------------# @@ -506,16 +497,17 @@ def main(): out = Output() - displays = get_display_objects(output) + displays = get_display_objects() out.extend(displays) out.output() -def get_display_objects(names): +def get_display_objects(): """ Returns a list of display objects, from the names in the list passed to the function as the first argument. """ + names = config.display for raw in names: if ':' in raw: name, *raw_arguments = raw.split(':') @@ -542,19 +534,34 @@ def load_config(): """ config_dir = os.getenv('XDG_CONFIG_HOME') sys.path.append(config_dir) - try: - import archey as config - except ImportError: - class config(): - defaults = {} - - def __getattr__(self, name): - if name in self.defaults.keys(): - return self.defaults[name] - else: - return None - return config + class _config(): + defaults = {'display': + ['User', + 'Uptime', + 'WindowManager', + 'DesktopEnvironment', + 'Shell', + 'Terminal', + 'Packages', + 'FileSystem:/home', + ] + } + + try: + import archey as _config + except ImportError: + _config = None + + def __getattr__(self, name): + if hasattr(self._config, name): + return getattr(self._config, name) + elif name in self.defaults.keys(): + return self.defaults[name] + else: + return None + + return _config() if __name__ == '__main__': -- cgit v1.2.3-54-g00ecf From bfb4574c23208a536e9f879006fd320d96483840 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 22 Nov 2010 13:56:44 +0000 Subject: Fixed small problem with FS display module when showing root FS --- archey.new | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey.new b/archey.new index 5d2b25f..edae67e 100644 --- a/archey.new +++ b/archey.new @@ -460,7 +460,7 @@ class FileSystem(BaseDisplay): def get_key(self): path = self.arguments[0] - name = path.split('/')[-1] + name = path.split('/')[-1] or 'Root' return '{0} FS'.format(name.capitalize()) def process_output(self, stdout, stderr): -- cgit v1.2.3-54-g00ecf From e9e54dcfea7b370642acb6503e31b8695ab81e9a Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 22 Nov 2010 15:08:55 +0000 Subject: Added color to fs display function, and added a _color function for BaseDisplay class. --- archey.new | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/archey.new b/archey.new index edae67e..e0ae9f5 100644 --- a/archey.new +++ b/archey.new @@ -14,7 +14,13 @@ # See http://www.gnu.org/licenses/gpl.txt for the full license text. # Import libraries -import os, sys, subprocess, optparse, re, linecache +import os +import sys +import subprocess +import optparse +import re +import linecache +import collections from optparse import OptionParser from getpass import getuser from time import ctime, sleep @@ -215,7 +221,12 @@ class Output(list): >>>out._get_results() {'Foo': 'Bar'} """ - return {key:value for key, value in [disp.key_value_pair() for disp in self] if key and value} + od = collections.OrderedDict() + for key, value in (disp.key_value_pair() for disp in self): + if not (key and value): + continue + od[key] = value + return od def align_results(self, results, maxsize=17): alignment_builtins = ['top', 'bottom', 'center', 'custom'] @@ -283,6 +294,14 @@ class BaseDisplay(): def __repr__(self): return '<{0}: key={1}, value={2}>'.format(self.__class__.__name__, self.key, self.value) + def _color(self, color, bold=False): + """ + Returns a shell escape code for the color given as a string. + """ + colors = dict(zip(('BLACK', 'RED', 'GREEN', 'YELLOW', 'BLUE', 'MAGENTA', 'CYAN', 'WHITE'), range(8))) + p = colors.get(color.upper(), None) + return '\x1b[{0};3{1}m'.format(int(bold), p) if p else '\x1b[0m' + def get_key(self): """ Return the value of the class' key attribute. If classes wish to customise key generation, @@ -477,8 +496,14 @@ class FileSystem(BaseDisplay): used = line[3] total = line[2] fstype = line[1] + if persentage < (1/3) * 100: + color = self._color('green', bold=True) + elif persentage < (2/3) * 100: + color = self._color('blue', bold=True) + else: + color = self._color('red', bold=True) - return '{used}/{total} ({fstype})'.format(used=used, total=total, fstype=fstype) + return '{color}{used}{clear}/{total} ({fstype})'.format(color=color, used=used, clear=self._color('clear'), total=total, fstype=fstype) #class CPU(): # def __init__(self): -- cgit v1.2.3-54-g00ecf From a0bb405c6535d9b6619bfccad91f848e45bf4a84 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 23 Nov 2010 16:00:20 +0000 Subject: Fixed error calculating persentage used reported by tvieira --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 239b000..a46d848 100755 --- a/archey +++ b/archey @@ -285,7 +285,7 @@ def disk_display(): total = p1.splitlines()[-1] used = total.split()[3] size = total.split()[2] - usedpercent = float(re.sub("[A-Z]", "", used)) / float(re.sub("[A-Z]", "", size)) * 100 + usedpercent = float(total.split()[5][:-1]) if usedpercent <= 33: fs = '%s%s %s/ %s' % (greenB, used, clear, size) output ('Disk', fs) -- cgit v1.2.3-54-g00ecf From eda92485a33efee53dc6daebdeadad8086962c79 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Wed, 12 Jan 2011 22:33:23 -0800 Subject: reverted to old version, bluepeppers see me --- archey.new | 634 +++++++++++++++---------------------------------------------- 1 file changed, 150 insertions(+), 484 deletions(-) diff --git a/archey.new b/archey.new index e0ae9f5..2af3405 100644 --- a/archey.new +++ b/archey.new @@ -14,66 +14,51 @@ # See http://www.gnu.org/licenses/gpl.txt for the full license text. # Import libraries -import os -import sys -import subprocess -import optparse -import re -import linecache -import collections +import os, sys, subprocess, optparse, re, linecache +from subprocess import Popen, PIPE from optparse import OptionParser from getpass import getuser from time import ctime, sleep #---------------Output---------------# - - -#--------------Exceptions-------------# - -class ArcheyException(Exception): pass +output = [ + 'User', + 'Hostname', + 'Distro', + 'Kernel', + 'Uptime', + 'WindowManager', + 'DesktopEnvironment', + 'Shell', + 'Terminal', + 'Packages', + 'CPU', + 'RAM', + 'Disk' + ] #---------------Dictionaries---------------# -class NoDeleteDict(dict): - """ - This dict silently disables deletions. This is because allthough we will want users to be able to - edit these dicts from their config files, we don't want them to muck up somthing important, so we - disable deletions to protect them from themselves. - - >>>dic = NoDeleteDict({'a':1, 'b':2}) - - We can still access items normally: - >>>dic['a'] - 1 - - But when we delete items, nothing happens: - >>>del dic['b'] - >>>dic['b'] - 2 - """ - - def __delitem__(self, name): - return - -COLOR_DICT = NoDeleteDict({ +colorDict = { 'Arch Linux': ['\x1b[0;34m', '\x1b[1;34m'], 'Ubuntu': ['\x1b[0;31m', '\x1b[1;31m', '\x1b[0;33m'], 'Debian': ['\x1b[0;31m', '\x1b[1;31m'], 'Mint': ['\x1b[0;32m', '\x1b[1;37m'], 'Crunchbang': ['\x1b[1;37m'], 'Fedora': ['\x1b[0;34m', '\x1b[1;37m'], - 'Clear': '\x1b[0m' - }) + 'Sensors': ['\x1b[0;31m', '\x1b[0;32m', '\x1b[0;33m'], + 'Clear': ['\x1b[0m'] + } -DE_DICT = NoDeleteDict({ +deDict = { 'gnome-session': 'GNOME', 'ksmserver': 'KDE', 'xfce4-session': 'Xfce', 'lxsession': 'LXDE' - }) + } -WM_DICT = NoDeleteDict({ +wmDict = { 'awesome': 'Awesome', 'beryl': 'Beryl', 'blackbox': 'Blackbox', @@ -96,10 +81,9 @@ WM_DICT = NoDeleteDict({ 'wmii': 'wmii', 'xfwm4': 'Xfwm', 'xmonad': 'xmonad' - }) - + } -LOGO_DICT = NoDeleteDict({'Arch Linux': '''{color[1]} +logosDict = {'Arch Linux': '''{color[1]} {color[1]} + {results[0]} {color[1]} # {results[1]} {color[1]} ### {results[2]} @@ -118,476 +102,158 @@ LOGO_DICT = NoDeleteDict({'Arch Linux': '''{color[1]} {color[0]} ;#### ####; {results[15]} {color[0]} ##' '## {results[16]} {color[0]} #' `# {results[17]} -\x1b[0m'''}) +\x1b[0m''' +} -PROCESSES = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', +processes = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', '--no-headers')), encoding='utf8').rstrip('\n').split('\n') - -def detect_distro(): - if os.path.exists('/etc/pacman.conf'): - return 'Arch Linux' - else: - raise ArcheyException("Unsupported distro") - -DISTRO = detect_distro() - #---------------Classes---------------# -class Output(list): - - def _color(self, index): - """ - Returns the escape code for either: - a) The color scheme of the distro value stored in self.distro - or - b) The value of the entry in COLOR_DICT for the key passed - - >>out = Output() - >>out._color(1) == COLOR_DICT[out.distro][1] - >>out._color(out.distro) == COLOR_DICT[out.distro] - """ - - if isinstance(index, str): - return COLOR_DICT[index] - return COLOR_DICT[DISTRO][index] - - def _get_logo(self): - return LOGO_DICT[DISTRO] - - def _center_results(self, results, max_length=17): - """ - Centers a list of results. Length of desired list can be given via max_length kwarg. - - >>>out = Output() - >>>out._center_results([1]) - [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 1, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] - >>>out._center_results([1], max_length=3) - [' ', 1, ' '] - """ - - length = len(results) - if length > max_length: - return results[:max_length + 1] - - center = int(max_length/2) - start = int(center - length/2) - new_results = list(' ' * max_length) - new_results[start:start + length - 1] = results - - return new_results - - def _top_results(self, results, max_length=17): - """ - Aligns a list of results to the top. Length of output list given via max_length kwarg. - - >>>out = Output() - >>>out._top_results([1]) - [1, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] - >>>out._top_results([1], max_length=3) - [1, ' ', ' '] - """ - out = results - out.extend(' ' * (max_length - len(results)+1)) - return out - - def _bottom_results(self, results, max_length=17): - """ - Aligns a list of results to the bottom. Length of output list given via max_length kwarg. - - >>>out = Output() - >>>out._bottom_results([1]) - [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 1] - >>>out._bottom_results([1], max_length=3) - [' ', ' ', 1] - """ - out = [] - out.extend(' ' * (max_length - len(results)+1)) - out.extend(results) - return out +class Output: + results = [] + results.extend(['']*(13)) - def _get_results(self): - """ - Returns a dict of the keys and values of the currently registered display classes. - NOTE: Will not include any key value pairs where either evaluates to False. + def __init__(self): + self.distro = self.__detectDistro() - >>>out = Output() - >>>class TestDisplay(): - ... key = 'Foo' - ... value = 'Bar' - ... key_value_pair = lambda self: {self.key: self.value} - ... - >>>out.append(TestDisplay()) - >>>out._get_results() - {'Foo': 'Bar'} - """ - od = collections.OrderedDict() - for key, value in (disp.key_value_pair() for disp in self): - if not (key and value): - continue - od[key] = value - return od - - def align_results(self, results, maxsize=17): - alignment_builtins = ['top', 'bottom', 'center', 'custom'] - - try: - align = config.results_align - if align == None or align not in alignment_builtins: - raise Exception() - if align == 'top': - out = self._top_results(results, max_length=17) - elif align == 'bottom': - out = self._bottom_results(results, max_length=17) - elif align == 'custom': - out = config.custom_align(results, max_length=17) - else: - out = self._center_results(results, max_length=17) - except: - out = self._center_results(results, max_length=17) - return out + def __detectDistro(self): + if os.path.exists('/etc/pacman.conf'): + return 'Arch Linux' + else: + sys.exit(1) + + def append(self, display): + self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) def output(self): - """ - Outputs the archey logo and information. Reads Display classes from the internal list, - and formats them, adding color. The final pretty list is then centered (though other alignments - may be added) and printed. - """ - - results = self._get_results() - - unformatted_stn = '{color}{key}: {clear}{value}{clear}' - pretty_results = [] - for key, value in results.items(): - try: - formatted_stn = unformatted_stn.format(color=self._color(1), key=key, value=value, - clear=self._color('Clear')) - except: - #Fail silently, have a debug option later for noisy fail? - pass - else: - pretty_results.append(formatted_stn) - - aligned_results = self.align_results(pretty_results) - - print(self._get_logo().format(color=self._color(DISTRO), results=aligned_results)) - -class BaseDisplay(): - """ - All display classes should inherit this. It defigns several base functions that can be overwritten by any child classes - - >>>import random - >>>class RandomNumber(BaseDisplay): - ... key = 'Random Number' - ... value = random.random() * 1000 - ... - >>>r = RandomNumber() - >>>print `r` - """ - - key = None - value = None - - def __init__(self, args=None): - self.arguments = args or [] - - def __repr__(self): - return '<{0}: key={1}, value={2}>'.format(self.__class__.__name__, self.key, self.value) - - def _color(self, color, bold=False): - """ - Returns a shell escape code for the color given as a string. - """ - colors = dict(zip(('BLACK', 'RED', 'GREEN', 'YELLOW', 'BLUE', 'MAGENTA', 'CYAN', 'WHITE'), range(8))) - p = colors.get(color.upper(), None) - return '\x1b[{0};3{1}m'.format(int(bold), p) if p else '\x1b[0m' - - def get_key(self): - """ - Return the value of the class' key attribute. If classes wish to customise key generation, - they should override this method - """ - return self.key - - def get_value(self): - """ - Return the value of the class' value attribute. If classes wish to customise value generation, - they should override this method - """ - return self.value - - def key_value_pair(self): - """ - Returns a tuple of the key and value of the current display. - - >>>disp = BaseDisplay() - >>>disp.key = 'Foo' - >>>disp.value = 'Bar' - >>>disp.key_value_pair() - ('Foo', 'Bar') - """ - return (self.get_key(), self.get_value()) + print(logosDict[self.distro].format(color = colorDict[self.distro], results = self.results)) + +class User: + def __init__(self): + self.key = 'User' + self.value = os.getenv('USER') -#class Hostname: -# def __init__(self): +class Hostname: + def __init__(self): + hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].decode('Utf-8').rstrip('\n') + self.key = 'Hostname' + self.value = hostname -#class Distro: -# def __init__(self): +class Distro: + def __init__(self): + if os.path.exists('/etc/pacman.conf'): + distro = 'Arch Linux' + self.key = 'Distro' + self.value = distro -#class Kernel: -# def __init__(self): +class Kernel: + def __init__(self): + kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].decode('Utf-8').rstrip('\n') + self.key = 'Kernel' + self.value = kernel -class Uptime(BaseDisplay): - key = 'Uptime' - - def get_uptime(self): +class Uptime: + def __init__(self): fuptime = int(open('/proc/uptime').read().split('.')[0]) day = int(fuptime / 86400) fuptime = fuptime % 86400 hour = int(fuptime / 3600) fuptime = fuptime % 3600 minute = int(fuptime / 60) - - return {'day': day, 'hour': hour, 'minute': minute} - - def get_value(self): - uptime = self.get_uptime() - - if uptime['day']: - value = '{day}{suffix}, '.format(day=uptime['day'], suffix='s' if day > 1 else '') - else: - value = '' - value += '{hours}:{mins:02d}'.format(hours=uptime['hour'], mins=uptime['minute']) - return value - -class WindowManager(BaseDisplay): - key = 'Window Manager' - - def get_value(self): + uptime = '' + if day == 1: + uptime += '%d day, ' % day + if day > 1: + uptime += '%d days, ' % day + uptime += '%d:%02d' % (hour, minute) + self.key = 'Uptime' + self.value = uptime + +class WindowManager: + def __init__(self): wm = '' - for key in WM_DICT.keys(): - if key in PROCESSES: - wm = WM_DICT[key] + for key in wmDict.keys(): + if key in processes: + wm = wmDict[key] break - return wm + self.key = 'Window Manager' + self.value = wm -class DesktopEnvironment(BaseDisplay): - key = 'Desktop Environment' - - def get_value(self): +class DesktopEnvironment: + def __init__(self): de = '' - for key in DE_DICT.keys(): - if key in PROCESSES: - de = DE_DICT[key] + for key in deDict.keys(): + if key in processes: + wm = wmDict[key] break - return de - -def enviroment_variable(klass): - """ - Decorate classes with this decorator. Classes decorated with enviroment_variable will - have their __init__ function automaticly generated. This makes it very easy to write - a class that returns an enviroment variable. - - >>>@enviroment_variable - ...class Lang(): - ... key = 'Language' - ... env = 'LANG' - ... - >>>test = Lang() - >>>import os - >>>assert test.value == os.getenv('LANG') - """ - - def get_value(self): - return os.getenv(self.env) - - if hasattr(klass, 'key') and hasattr(klass, 'env'): - klass.get_value = get_value - else: - raise ArcheyException('Classes decorated with @enviroment_variable must have' - 'key and env attributes') - - return klass - -@enviroment_variable -class Shell(BaseDisplay): - key = 'Shell' - env = 'SHELL' - -@enviroment_variable -class Terminal(BaseDisplay): - key = 'Terminal' - env = 'TERM' - -@enviroment_variable -class User(BaseDisplay): - key = 'User' - env = 'USER' - -def shell_command(klass): - """ - A class decorated with @shell_command will be treated as a class that runs a command, and then parses the output. - - It should have two string members, "command", the command that will be run, and "key", the key for the display. - It should also implement one method, process_output, which should take two arguments, stdout, and stderr, and return - a value to be displayed. - """ - def get_value(self): - command = self.command.format(arguments=self.arguments) - cmd = subprocess.Popen(command.split(), - stdout=subprocess.PIPE, - stdin=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, stderr = cmd.communicate() - return self.process_output(stdout.decode('ascii'), stderr.decode('ascii')) - - if not all(hasattr(klass, name) for name in ('command', 'process_output')): - raise ArcheyException("Classes decorated with @shell_command must have " - "a key and command attributes, and the process_output method") - else: - klass.get_value = get_value - - return klass - -@shell_command -class Packages(BaseDisplay): - key = 'Packman packages' - command = 'pacman -Q' - - def process_output(self, stdout, stderr): - #Return nothing if pacman returns errors - if stderr: - return None - - no_of_packages = len(stdout.split('\n')) - - return str(no_of_packages) - - -@shell_command -class FileSystem(BaseDisplay): - command = 'df -TPh {arguments[0]}' - - conversions = { - 'k': 2**10, - 'M': 2**20, - 'G': 2**30, - 'T': 2**40, - 'P': 2**50, - } - - def get_key(self): - path = self.arguments[0] - name = path.split('/')[-1] or 'Root' - return '{0} FS'.format(name.capitalize()) - - def process_output(self, stdout, stderr): - #Return nothing if pacman returns errors - if stderr: - return None - - stdout = stdout.split('\n') - line = stdout[1] - line = re.sub(r'( +)', r' ', line) - line = line.split(' ') - - persentage = int(line[5][:-1]) - used = line[3] - total = line[2] - fstype = line[1] - if persentage < (1/3) * 100: - color = self._color('green', bold=True) - elif persentage < (2/3) * 100: - color = self._color('blue', bold=True) - else: - color = self._color('red', bold=True) - - return '{color}{used}{clear}/{total} ({fstype})'.format(color=color, used=used, clear=self._color('clear'), total=total, fstype=fstype) + + self.key = 'Desktop Environment' + self.value = de -#class CPU(): -# def __init__(self): +class Shell: + def __init__(self): + self.key = 'Shell' + self.value = os.getenv('SHELL') -#class RAM(): -# def __init__(self): +class Terminal: + def __init__(self): + self.key = 'Terminal' + self.value = os.getenv('TERM') -#class Disk(): -# def __init__(self): +class Packages: + def __init__(self): + p1 = Popen(['pacman', '-Q'], stdout=PIPE).communicate()[0].decode("Utf-8") + packages = len(p1.rstrip('\n').split('\n')) + self.key = 'Packages' + self.value = packages + +class CPU: + def __init__(self): + file = open('/proc/cpuinfo').readlines() + cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) + output ('CPU', cpuinfo) +class RAM: + def __init__(self): + raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].decode('Utf-8').split('\n') + ram = ''.join(filter(re.compile('M').search, raminfo)).split() + used = int(ram[2]) - int(ram[5]) - int(ram[6]) + usedpercent = ((float(used) / float(ram[1])) * 100) + if usedpercent <= 33: + ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], ram[1]) + if usedpercent > 33 and usedpercent < 67: + ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][1], used, colorDict['Clear'][0], ram[1]) + if usedpercent >= 67: + ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][0], used, colorDict['Clear'][0], ram[1]) + self.key = 'RAM' + self.value = ramdisplay + +class Disk: + def __init__(self): + p1 = Popen(['df', '-Tlh', '--total', '-t', 'ext4', '-t', 'ext3', '-t', 'ext2', '-t', 'reiserfs', '-t', 'jfs', '-t', 'ntfs', '-t', 'fat32', '-t', 'btrfs', '-t', 'fuseblk'], stdout=PIPE).communicate()[0].decode("Utf-8") + total = p1.splitlines()[-1] + used = total.split()[3] + size = total.split()[2] + usedpercent = float(total.split()[5][:-1]) + + if usedpercent <= 33: + disk = '%s%s %s/ %s' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], size) + if usedpercent > 33 and usedpercent < 67: + disk = '%s%s %s/ %s' % (colorDict['Sensors'][1], used, colorDict['Clear'][0], size) + if usedpercent >= 67: + disk = '%s%s %s/ %s' % (colorDict['Sensors'][0], used, colorDict['Clear'][0], size) + self.key = 'Disk' + self.value = disk ## TEST ## <<< TEMPORARY -def main(): - global config - config = load_config() - - out = Output() - - displays = get_display_objects() - - out.extend(displays) - out.output() - -def get_display_objects(): - """ - Returns a list of display objects, from the names in the list passed to the - function as the first argument. - """ - names = config.display - for raw in names: - if ':' in raw: - name, *raw_arguments = raw.split(':') - if len(raw_arguments) > 1: - raise ArcheyException('Badly formatted argument in "{0}"'.format(raw)) - else: - arguments = [arg for arg in raw_arguments[0].split(',') if arg] - else: - name = raw - arguments = [] - try: - klass = eval(name) - except: - try: - klass = eval(name.capitalize()) - except: - raise ArcheyException('Could not find display class {0} to use'.format(name)) - - yield klass(arguments) - -def load_config(): - """ - Imports the config file. - """ - config_dir = os.getenv('XDG_CONFIG_HOME') - sys.path.append(config_dir) - - class _config(): - defaults = {'display': - ['User', - 'Uptime', - 'WindowManager', - 'DesktopEnvironment', - 'Shell', - 'Terminal', - 'Packages', - 'FileSystem:/home', - ] - } - - try: - import archey as _config - except ImportError: - _config = None - - def __getattr__(self, name): - if hasattr(self._config, name): - return getattr(self._config, name) - elif name in self.defaults.keys(): - return self.defaults[name] - else: - return None - - return _config() - - -if __name__ == '__main__': - main() +out = Output() +out.append(Shell()) +out.append(Packages()) +out.append(Disk()) +out.append(RAM()) +out.append(Distro()) +out.append(WindowManager()) +#out.append(DesktopEnvirornment()) +out.output() -- cgit v1.2.3-54-g00ecf From b8624558a9620b7bb2457fc668ace490a02ec4d3 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Fri, 14 Jan 2011 00:59:58 -0800 Subject: moved archey.new > archey --- archey | 661 ++++++++++++++++++++++++----------------------------------------- 1 file changed, 238 insertions(+), 423 deletions(-) mode change 100755 => 100644 archey diff --git a/archey b/archey old mode 100755 new mode 100644 index a46d848..e94f90c --- a/archey +++ b/archey @@ -1,14 +1,15 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # -# Archey [version 0.2.8] +# Archey [version 0.3.0] # -# Archey is a system information tool written in Python. +# Archey is a simple system information tool written in Python. +# +# Copyright 2010 Melik Manukyan # -# Maintained by Melik Manukyan # ASCII art by Brett Bohnenkamper # Changes Jerome Launay # Fedora support by YeOK - +# # Distributed under the terms of the GNU General Public License v3. # See http://www.gnu.org/licenses/gpl.txt for the full license text. @@ -19,423 +20,237 @@ from optparse import OptionParser from getpass import getuser from time import ctime, sleep -# Display [Comment/Uncomment to Enable/Disable information.] -display = [ - 'user', # Display Username - 'hostname', # Display Machine Hostname - 'distro', # Display Distribution - 'kernel', # Display Kernel Version - 'uptime', # Display System Uptime - 'wm', # Display Window Manager - 'de', # Display Desktop Environment - 'sh', # Display Current Shell - 'term', # Display Current Terminal - 'packages', # Display Number of Packages Installed - 'cpu', # Display CPU Model - 'ram', # Display RAM Usage - 'disk' # Display Disk Usage - ] - -# Array containing Values -result = [] - -# Options -if __name__=='__main__': - parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.8") - parser.add_option('-s', '--screenshot', - action='store_true', dest='screenshot', help='take a screenshot') - (options, args) = parser.parse_args() - -# Define processes for identifying Desktop Environmentss, Window Managers, Shells. -de_dict = { - 'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfce4-session': 'Xfce'} - -wm_dict = { - 'awesome': 'Awesome', - 'beryl': 'Beryl', - 'blackbox': 'Blackbox', - 'compiz': 'Compiz', - 'dwm': 'DWM', - 'enlightenment': 'Enlightenment', - 'fluxbox': 'Fluxbox', - 'fvwm': 'FVWM', - 'i3': 'i3', - 'icewm': 'IceWM', - 'kwin': 'KWin', - 'metacity': 'Metacity', - 'musca': 'Musca', - 'openbox': 'Openbox', - 'pekwm': 'PekWM', - 'ratpoison': 'ratpoison', - 'scrotwm': 'ScrotWM', - 'wmaker': 'Window Maker', - 'wmfs': 'Wmfs', - 'wmii': 'wmii', - 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad'} - -sh_dict = { - 'zsh': 'Zsh', - 'bash': 'Bash', - 'dash': 'Dash', - 'fish': 'Fish', - 'ksh': 'Ksh', - 'csh': 'Csh', - 'jsh': 'Jsh', - 'tcsh': 'Tcsh'} - -# Define Colour Scheme - -clear = '\x1b[0m' -blackB = '\x1b[0;30m' -blackB = '\x1b[1;30m' -redN = '\x1b[0;31m' -redB = '\x1b[1;31m' -greenN = '\x1b[0;32m' -greenB = '\x1b[1;32m' -yellowN = '\x1b[0;33m' -yellowB = '\x1b[1;33m' -blueN = '\x1b[0;34m' -blueB = '\x1b[1;34m' -magentaN = '\x1b[0;35m' -magentaB = '\x1b[1;35m' -cyanN = '\x1b[0;36m' -cyanB = '\x1b[1;36m' -whiteN = '\x1b[0;37m' -whiteB = '\x1b[1;37m' - -# Find running processes. -def xmonadfix(str): - if re.compile("xmonad").match(str): return "xmonad" - return str -p1 = Popen(['ps', '-u', getuser()], stdout=PIPE).communicate()[0].split('\n') -processes = map(xmonadfix, [process.split()[3] for process in p1 if process]) -p1 = None - -# Find Distro. -DetectDistro = Popen(['lsb_release', '-i'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') - -# Print coloured key with normal value. -def output(key, value): - if DetectDistro == 'Ubuntu': - output ='%s%s:%s %s' % (redB, key, clear, value) - if DetectDistro == 'Arch': - output = '%s%s:%s %s' % (blueB, key, clear, value) - if DetectDistro == 'Debian': - output = '%s%s:%s %s' % (redB, key, clear, value) - if DetectDistro == 'Fedora': - output = '%s%s:%s %s' % (blueB, key, clear, value) - if DetectDistro == 'CrunchBang': - output = '%s%s:%s %s' % (whiteN, key, clear, value) - if DetectDistro == 'LinuxMint': - output = '%s%s:%s %s' % (greenB, key, clear, value) - result.append(output) - -# RAM Function. -def ram_display(): - raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].split('\n') - ram = ''.join(filter(re.compile('M').search, raminfo)).split() - used = int(ram[2]) - int(ram[5]) - int(ram[6]) - usedpercent = ((float(used) / float(ram[1])) * 100) - if usedpercent <= 33: - ramdisplay = '%s%s MB %s/ %s MB' % (greenB, used, clear, ram[1]) - output('RAM', ramdisplay) - if usedpercent > 33 and usedpercent < 67: - ramdisplay = '%s%s MB %s/ %s MB' % (yellowB, used, clear, ram[1]) - output('RAM', ramdisplay) - if usedpercent >= 67: - ramdisplay = '%s%s MB %s/ %s MB' % (redB, used, clear, ram[1]) - output('RAM', ramdisplay) - -# Screenshot Function. -screen = '%s' % options.screenshot -def screenshot(): - print 'Taking shot in', - list = range(1,6) - list.reverse() - for x in list: - print '%s..' % x, - sys.stdout.flush() - sleep(1) - print 'Say Cheeze!' - subprocess.check_call(['scrot']) - -# Operating System Function. -def distro_display(): - arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') - if DetectDistro == 'Debian': - release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') - distro = 'Debian %s %s' % (release, arch) - if DetectDistro == 'Ubuntu': - release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') - distro = 'Ubuntu %s %s' % (release, arch) - if DetectDistro == 'Arch': - distro = 'Arch Linux %s' % arch - if DetectDistro == 'Fedora': - release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') - distro = 'Fedora %s %s' % (release, arch) - if DetectDistro == 'CrunchBang': - release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') - if DetectDistro == 'LinuxMint': - release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n') - distro = 'Mint %s %s' % (release, arch) - output('OS', distro) - -# Kernel Function. -def kernel_display(): - kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') - output ('Kernel', kernel) - -def user_display(): - username= os.getenv('USER') - output ('User', username) +#---------------Output---------------# -# Hostname Function. -def hostname_display(): - hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].rstrip('\n') - output('Hostname', hostname) - -# CPU Function. -def cpu_display(): - file = open('/proc/cpuinfo').readlines() - cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) - output ('CPU', cpuinfo) - -# Uptime Function. -def uptime_display(): - fuptime = int(open('/proc/uptime').read().split('.')[0]) - day = int(fuptime / 86400) - fuptime = fuptime % 86400 - hour = int(fuptime / 3600) - fuptime = fuptime % 3600 - minute = int(fuptime / 60) - uptime = '' - if day == 1: - uptime += '%d day, ' % day - if day > 1: - uptime += '%d days, ' % day - uptime += '%d:%02d' % (hour, minute) - output('Uptime', uptime) - -# Desktop Environment Function. -def de_display(): - for key in de_dict.keys(): - if key in processes: - de = de_dict[key] - output ('Desktop Environment', de) - -# Window Manager Function. -def wm_display(): - for key in wm_dict.keys(): - if key in processes: - wm = wm_dict[key] - output ('Window Manager', wm) - -# Shell Function. -def sh_display(): - sh = os.getenv("SHELL").split('/')[-1].capitalize() - output ('Shell', sh) - -# Terminal Function. -def term_display(): - term = os.getenv("TERM").split('/')[-1].capitalize() - output ('Terminal', term) - -# Packages Function. -def packages_display(): - if DetectDistro == 'Ubuntu': - p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) - p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) - p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) - packages = p3.communicate()[0].rstrip('\n') - output ('Packages', packages) - if DetectDistro == 'Arch': - p1 = Popen(['pacman', '-Q'], stdout=PIPE) - p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) - packages = p2.communicate()[0].rstrip('\n') - output ('Packages', packages) - if DetectDistro == 'Debian': - p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) - p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) - p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) - packages = p3.communicate()[0].rstrip('\n') - output ('Packages', packages) - if DetectDistro == 'CrunchBang': - p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) - p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) - p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) - packages = p3.communicate()[0].rstrip('\n') - output ('Packages', packages) - if DetectDistro == 'Fedora': - p1 = Popen(['rpm', '-qa'], stdout=PIPE) - p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) - packages = p2.communicate()[0].rstrip('\n') - if DetectDistro == 'LinuxMint': - p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE) - p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE) - p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE) - packages = p3.communicate()[0].rstrip('\n') - output ('Packages', packages) - -# Disk Function. -def disk_display(): - p1 = Popen(['df', '-Tlh', '--total', '-t', 'ext4', '-t', 'ext3', '-t', 'ext2', '-t', 'reiserfs', '-t', 'jfs', '-t', 'ntfs', '-t', 'fat32', '-t', 'btrfs', '-t', 'fuseblk'], stdout=PIPE).communicate()[0] - total = p1.splitlines()[-1] - used = total.split()[3] - size = total.split()[2] - usedpercent = float(total.split()[5][:-1]) - if usedpercent <= 33: - fs = '%s%s %s/ %s' % (greenB, used, clear, size) - output ('Disk', fs) - if usedpercent > 33 and usedpercent < 67: - fs = '%s%s %s/ %s' % (yellowB, used, clear, size) - output ('Disk', fs) - if usedpercent >= 67: - fs = '%s%s %s/ %s' % (redB, used, clear, size) - output ('Disk', fs) - +output = [ 'User', 'Hostname', 'Distro', 'Kernel', 'Uptime', 'WindowManager', 'DesktopEnvironment', 'Shell', 'Terminal', 'Packages', 'CPU', 'RAM', 'Disk' ] -# Run functions found in 'display' array. -for x in display: - funcname=x+'_display' - func=locals()[funcname] - func() - -# Array containing values. -result.extend(['']*(20 - len(display))) - -# Result. -if DetectDistro == 'Ubuntu': - print """ -%s .oyhhs: %s -%s ..--.., %sshhhhhh- %s -%s -+++++++++`:%syyhhyo` %s -%s .-- %s-++++++++/-.-%s::-` %s -%s .::::- %s:-----:/+++/++/. %s -%s -:::::-. %s.:++++++: %s -%s ,,, %s.:::::-` %s.++++++- %s -%s./+++/-%s`-::- %s./////: %s -%s+++++++ %s.::- %s -%s./+++/-`%s-::- %s:yyyyyo %s -%s ``` `%s-::::-` %s:yhhhhh: %s -%s -:::::-. %s`-ohhhhhh+ %s -%s .::::-` %s-o+///+oyhhyyyhy: %s -%s `.-- %s/yhhhhhhhy+%s,.... %s -%s /hhhhhhhhh%s-.-:::; %s -%s `.:://::- %s-:::::; %s -%s `.-:-' %s -%s %s -%s""" % ( redN, result[0], redB, redN, result[1], redB, redN, result[2], yellowB, redB, redN, result[3], yellowB, redB, result[4], yellowB, redB, result[5], redB, yellowB, redB, result[6], redB, yellowB, redB, result[7], redB, yellowB, result[8], redB, yellowB, redN, result[9], redB, yellowB, redN, result[10], yellowB, redN, result[11], yellowB, redN, result[12], yellowB, redN, yellowB, result[13], redN, yellowB, result[14], redN, yellowB, result[15], yellowB, result[16], yellowB, result[17], clear ) - -if DetectDistro == 'Arch': - print """%s -%s + %s -%s # %s -%s ### %s -%s ##### %s -%s ###### %s -%s ; #####; %s -%s +##.##### %s -%s +########## %s -%s ######%s#####%s##; %s -%s ###%s############%s+ %s -%s #%s###### ####### %s -%s .######; ;###;`\". %s -%s .#######; ;#####. %s -%s #########. .########` %s -%s ######' '###### %s -%s ;#### ####; %s -%s ##' '## %s -%s #' `# %s%s """ % (blueB, blueB, result[0], blueB, result[1], blueB, result[2], blueB, result[3], blueB, result[4], blueB, result[5], blueB, result[6], blueB, result[7], blueB, blueN, blueB, result[8], blueB, blueN, blueB, result[9], blueB, blueN, result[10], blueN, result[11], blueN, result[12], blueN, result[13], blueN, result[14], blueN, result[15], blueN, result[16], blueN, result[17], clear) - -if DetectDistro == 'Debian': - print """%s -%s %s -%s _sudZUZ#Z#XZo=_ %s -%s _jmZZ2!!~---~!!X##wx %s -%s . -]Xb/ ~ __#2( %s -%s -Zo; +!4ZwerfgnZZXY' %s -%s *#[, ~-?!!!!!!-~ %s -%s XUb;. %s -%s )YXL,, %s -%s +3#bc, %s -%s -)SSL,, %s -%s ~~~~~ %s -%s %s -%s """ % (redB, redB, result[0], redB, result[1], redB, result[2], redB, result[3], redB, result[4], redB, result[5], redB, result[6], redB, result[7], redB, result[8], redN, result[9], redN, result[10], redN, result[11], redN, result[12], redN, result[13], redN, result[14], redN, result[15], redN, result[16], redN, result[17], clear) - -if DetectDistro == 'Fedora': - print """ -%s :/------------:// %s -%s :------------------:// %s -%s :-----------%s/shhdhyo/%s-:// %s -%s /-----------%somMMMNNNMMMd/%s-:/ %s -%s :-----------%ssMMMdo:/%s -:/ %s -%s :-----------%s:MMMd%s------- --:/ %s -%s /-----------%s:MMMy%s------- ---/ %s -%s :------ --%s/+MMMh/%s-- ---: %s -%s :--- %soNMMMMMMMMMNho%s -----: %s -%s :-- %s+shhhMMMmhhy++%s ------: %s -%s :- -----%s:MMMy%s--------------/ %s -%s :- ------%s/MMMy%s-------------: %s -%s :- ----%s/hMMM+%s------------: %s -%s :--%s:dMMNdhhdNMMNo%s-----------: %s -%s :---%s:sdNMMMMNds:%s----------: %s -%s :------%s:://:%s-----------:// %s -%s :--------------------:// %s -%s %s -%s """ % ( blueN, result[0], blueN, result[1], blueN, whiteB, blueN, result[2], blueN, whiteB, blueN, result[3], blueN, whiteB, blueN, result[4], blueN, whiteB, blueN, result[5], blueN, whiteB, blueN, result[6], blueN, whiteB, blueN, result[7], blueN, whiteB, blueN, result[8], blueN, whiteB, blueN, result[9], blueN, whiteB, blueN, result[10], blueN, whiteB, blueN, result[11], blueN, whiteB, blueN, result[12], blueN, whiteB, blueN, result[13], blueN, whiteB, blueN, result[14], blueN, whiteB, blueN, result[15], blueN, result[16], blueN, result[17], clear ) - -if DetectDistro == 'CrunchBang': - print """ -%s ___ ___ _ %s -%s / / / / | | %s -%s / / / / | | %s -%s / / / / | | %s -%s _______/ /______/ /______ | | %s -%s /______ _______ _______/ | | %s -%s / / / / | | %s -%s / / / / | | %s -%s / / / / | | %s -%s ______/ /______/ /______ | | %s -%s/_____ _______ _______/ | | %s -%s / / / / | | %s -%s / / / / |_| %s -%s / / / / _ %s -%s / / / / | | %s -%s /__/ /__/ |_| %s -%s %s -%s %s -%s""" % ( whiteN, result[0], whiteN, result[1], whiteN, result[2], whiteN, result[3], whiteN, result[4], whiteN, result[5], whiteN, result[6], whiteN, result[7], whiteN, result[8], whiteN, result[9], whiteN, result[10], whiteN, result[11], whiteN, result[12], whiteN, result[13], whiteN, result[14], whiteN, result[15], whiteN, result[16], whiteN, result[17], clear ) - -if DetectDistro == 'LinuxMint': - print """%s %s -%s MMMMMMMMMMMMMMMMMMMMMMMMMmds+. %s -%s MMm----::-://////////////oymNMd+` %s -%s MMd %s/++ %s-sNMd: %s -%s MMNso/` %sdMM `.::-. .-::.` %s.hMN: %s -%s ddddMMh %sdMM :hNMNMNhNMNMNh: `%sNMm %s -%s NMm %sdMM .NMN/-+MMM+-/NMN` %sdMM %s -%s NMm %sdMM -MMm `MMM dMM. %sdMM %s -%s NMm %sdMM -MMm `MMM dMM. %sdMM %s -%s NMm %sdMM .mmd `mmm yMM. %sdMM %s -%s NMm %sdMM` ..` ... ydm. %sdMM %s -%s hMM- %s+MMd/-------...-:sdds %sMMM %s -%s -NMm- %s:hNMNNNmdddddddddy/` %sdMM %s -%s -dMNs-``%s-::::-------.`` %sdMM %s -%s `/dMNmy+/:-------------:/yMMM %s -%s ./ydNMMMMMMMMMMMMMMMMMMMMM %s -%s %s -%s %s -%s""" % ( whiteB, result[0], whiteB, result[1], whiteB, result[2], whiteB, greenB, whiteB, result[3], whiteB, greenB, whiteB, result[4], whiteB, greenB, whiteB, result[5], whiteB, greenB, whiteB, result[6], whiteB, greenB, whiteB, result[7], whiteB, greenB, whiteB, result[8], whiteB, greenB, whiteB, result[9], whiteB, greenB, whiteB, result[10], whiteB, greenB, whiteB, result[11], whiteB, greenB, whiteB, result[12], whiteB, greenB, whiteB, result[13], whiteB, result[14], whiteB, result[15], whiteB, result[16], whiteB, result[17], clear ) - -if screen == 'True': - screenshot() +#---------------Dictionaries---------------# + +colorDict = { + 'Arch Linux': ['\x1b[0;34m', '\x1b[1;34m'], + 'Ubuntu': ['\x1b[0;31m', '\x1b[1;31m', '\x1b[0;33m'], + 'Debian': ['\x1b[0;31m', '\x1b[1;31m'], + 'Mint': ['\x1b[0;32m', '\x1b[1;37m'], + 'Crunchbang': ['\x1b[1;37m'], + 'Fedora': ['\x1b[0;34m', '\x1b[1;37m'], + 'Sensors': ['\x1b[0;31m', '\x1b[0;32m', '\x1b[0;33m'], + 'Clear': ['\x1b[0m'] + } + +deDict = { + 'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfce4-session': 'Xfce', + 'lxsession': 'LXDE' + } + +wmDict = { + 'awesome': 'Awesome', + 'beryl': 'Beryl', + 'blackbox': 'Blackbox', + 'compiz': 'Compiz', + 'dwm': 'DWM', + 'enlightenment': 'Enlightenment', + 'fluxbox': 'Fluxbox', + 'fvwm': 'FVWM', + 'i3': 'i3', + 'icewm': 'IceWM', + 'kwin': 'KWin', + 'metacity': 'Metacity', + 'musca': 'Musca', + 'openbox': 'Openbox', + 'pekwm': 'PekWM', + 'ratpoison': 'ratpoison', + 'scrotwm': 'ScrotWM', + 'wmaker': 'Window Maker', + 'wmfs': 'Wmfs', + 'wmii': 'wmii', + 'xfwm4': 'Xfwm', + 'xmonad': 'xmonad' + } + +logosDict = {'Arch Linux': '''{color[1]} +{color[1]} + {results[0]} +{color[1]} # {results[1]} +{color[1]} ### {results[2]} +{color[1]} ##### {results[3]} +{color[1]} ###### {results[4]} +{color[1]} ; #####; {results[5]} +{color[1]} +##.##### {results[6]} +{color[1]} +########## {results[7]} +{color[1]} ######{color[0]}#####{color[1]}##; {results[8]} +{color[1]} ###{color[0]}############{color[1]}+ {results[9]} +{color[1]} #{color[0]}###### ####### {results[10]} +{color[0]} .######; ;###;`\". {results[11]} +{color[0]} .#######; ;#####. {results[12]} +{color[0]} #########. .########` {results[13]} +{color[0]} ######' '###### {results[14]} +{color[0]} ;#### ####; {results[15]} +{color[0]} ##' '## {results[16]} +{color[0]} #' `# {results[17]} +\x1b[0m''' +} + +processes = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', + '--no-headers')), encoding='utf8').rstrip('\n').split('\n') + +#---------------Classes---------------# + +class Output: + results = [] + results.extend(['']*(18-len(output))) + + def __init__(self): + self.distro = self.__detectDistro() + + def __detectDistro(self): + if os.path.exists('/etc/pacman.conf'): + return 'Arch Linux' + else: + sys.exit(1) + + def append(self, display): + self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) + + def output(self): + print(logosDict[self.distro].format(color = colorDict[self.distro], results = self.results)) + +class User: + def __init__(self): + self.key = 'User' + self.value = os.getenv('USER') + +class Hostname: + def __init__(self): + hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].decode('Utf-8').rstrip('\n') + self.key = 'Hostname' + self.value = hostname + +class Distro: + def __init__(self): + if os.path.exists('/etc/pacman.conf'): + distro = 'Arch Linux' + self.key = 'Distro' + self.value = distro + +class Kernel: + def __init__(self): + kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].decode('Utf-8').rstrip('\n') + self.key = 'Kernel' + self.value = kernel + +class Uptime: + def __init__(self): + fuptime = int(open('/proc/uptime').read().split('.')[0]) + day = int(fuptime / 86400) + fuptime = fuptime % 86400 + hour = int(fuptime / 3600) + fuptime = fuptime % 3600 + minute = int(fuptime / 60) + uptime = '' + if day == 1: + uptime += '%d day, ' % day + if day > 1: + uptime += '%d days, ' % day + uptime += '%d:%02d' % (hour, minute) + self.key = 'Uptime' + self.value = uptime + +class WindowManager: + def __init__(self): + wm = '' + for key in wmDict.keys(): + if key in processes: + wm = wmDict[key] + break + + self.key = 'Window Manager' + self.value = wm + +class DesktopEnvironment: + def __init__(self): + de = '' + for key in deDict.keys(): + if key in processes: + wm = wmDict[key] + break + + self.key = 'Desktop Environment' + self.value = de + +class Shell: + def __init__(self): + self.key = 'Shell' + self.value = os.getenv('SHELL') + +class Terminal: + def __init__(self): + self.key = 'Terminal' + self.value = os.getenv('TERM') + +class Packages: + def __init__(self): + p1 = Popen(['pacman', '-Q'], stdout=PIPE).communicate()[0].decode("Utf-8") + packages = len(p1.rstrip('\n').split('\n')) + self.key = 'Packages' + self.value = packages + +class CPU: + def __init__(self): + file = open('/proc/cpuinfo').readlines() + cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) + self.key = 'CPU' + self.value = cpuinfo + +class RAM: + def __init__(self): + raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].decode('Utf-8').split('\n') + ram = ''.join(filter(re.compile('M').search, raminfo)).split() + used = int(ram[2]) - int(ram[5]) - int(ram[6]) + usedpercent = ((float(used) / float(ram[1])) * 100) + if usedpercent <= 33: + ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], ram[1]) + if usedpercent > 33 and usedpercent < 67: + ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][1], used, colorDict['Clear'][0], ram[1]) + if usedpercent >= 67: + ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][0], used, colorDict['Clear'][0], ram[1]) + self.key = 'RAM' + self.value = ramdisplay + +class Disk: + def __init__(self): + p1 = Popen(['df', '-Tlh', '--total', '-t', 'ext4', '-t', 'ext3', '-t', 'ext2', '-t', 'reiserfs', '-t', 'jfs', '-t', 'ntfs', '-t', 'fat32', '-t', 'btrfs', '-t', 'fuseblk'], stdout=PIPE).communicate()[0].decode("Utf-8") + total = p1.splitlines()[-1] + used = total.split()[3] + size = total.split()[2] + usedpercent = float(total.split()[5][:-1]) + + if usedpercent <= 33: + disk = '%s%s %s/ %s' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], size) + if usedpercent > 33 and usedpercent < 67: + disk = '%s%s %s/ %s' % (colorDict['Sensors'][1], used, colorDict['Clear'][0], size) + if usedpercent >= 67: + disk = '%s%s %s/ %s' % (colorDict['Sensors'][0], used, colorDict['Clear'][0], size) + self.key = 'Disk' + self.value = disk + +classes = { + 'User': User, + 'Hostname': Hostname, + 'Distro': Distro, + 'Kernel': Kernel, + 'Uptime': Uptime, + 'WindowManager': WindowManager, + 'DesktopEnvironment': DesktopEnvironment, + 'Shell': Shell, + 'Terminal': Terminal, + 'Packages': Packages, + 'CPU': CPU, + 'RAM': RAM, + 'Disk': Disk + } + +out = Output() +for x in output: + out.append(classes[x]()) +out.output() -- cgit v1.2.3-54-g00ecf From a2b262e56b67d5575dc4d4f1c1b397240add6d90 Mon Sep 17 00:00:00 2001 From: DjMelik Date: Fri, 14 Jan 2011 01:05:30 -0800 Subject: fixed color output --- archey | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/archey b/archey index e94f90c..d52baf9 100644 --- a/archey +++ b/archey @@ -209,9 +209,9 @@ class RAM: used = int(ram[2]) - int(ram[5]) - int(ram[6]) usedpercent = ((float(used) / float(ram[1])) * 100) if usedpercent <= 33: - ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], ram[1]) - if usedpercent > 33 and usedpercent < 67: ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][1], used, colorDict['Clear'][0], ram[1]) + if usedpercent > 33 and usedpercent < 67: + ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], ram[1]) if usedpercent >= 67: ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][0], used, colorDict['Clear'][0], ram[1]) self.key = 'RAM' @@ -226,9 +226,9 @@ class Disk: usedpercent = float(total.split()[5][:-1]) if usedpercent <= 33: - disk = '%s%s %s/ %s' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], size) - if usedpercent > 33 and usedpercent < 67: disk = '%s%s %s/ %s' % (colorDict['Sensors'][1], used, colorDict['Clear'][0], size) + if usedpercent > 33 and usedpercent < 67: + disk = '%s%s %s/ %s' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], size) if usedpercent >= 67: disk = '%s%s %s/ %s' % (colorDict['Sensors'][0], used, colorDict['Clear'][0], size) self.key = 'Disk' -- cgit v1.2.3-54-g00ecf From 2da6f98c8b41e96ffcd1b76fc2e4ce500f8f42eb Mon Sep 17 00:00:00 2001 From: Lukas Niederbremer Date: Sat, 5 Mar 2011 16:48:39 +0100 Subject: Fix trying to get DE from WM dictionary --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index d52baf9..2faf33e 100644 --- a/archey +++ b/archey @@ -172,7 +172,7 @@ class DesktopEnvironment: de = '' for key in deDict.keys(): if key in processes: - wm = wmDict[key] + de = deDict[key] break self.key = 'Desktop Environment' -- cgit v1.2.3-54-g00ecf From e8139a308c664de2a11c27b0523303e2a4fddb83 Mon Sep 17 00:00:00 2001 From: William Ting Date: Sat, 12 May 2012 23:19:36 -1000 Subject: explicitly specify archey to use python3 --- archey | 2 +- archey.new | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/archey b/archey index 2faf33e..703764f 100644 --- a/archey +++ b/archey @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Archey [version 0.3.0] # diff --git a/archey.new b/archey.new index 2af3405..e8789e5 100644 --- a/archey.new +++ b/archey.new @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Archey [version 0.3.0] # -- cgit v1.2.3-54-g00ecf From 51838f1b197a61909d5d639a98d126c00bfd01a2 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Wed, 26 Jun 2013 23:42:01 +0200 Subject: add herbstluftwm to wms --- archey | 1 + 1 file changed, 1 insertion(+) diff --git a/archey b/archey index 703764f..8f57f1a 100644 --- a/archey +++ b/archey @@ -51,6 +51,7 @@ wmDict = { 'compiz': 'Compiz', 'dwm': 'DWM', 'enlightenment': 'Enlightenment', + 'herbstluftwm': 'herbstluftwm', 'fluxbox': 'Fluxbox', 'fvwm': 'FVWM', 'i3': 'i3', -- cgit v1.2.3-54-g00ecf From b5f528c08c575ed74ca41b8bc281a1a62812626e Mon Sep 17 00:00:00 2001 From: Dan Fuhry Date: Wed, 31 Jul 2013 14:23:38 -0400 Subject: Added desktop environment support: MATE --- archey | 1 + 1 file changed, 1 insertion(+) diff --git a/archey b/archey index 8f57f1a..167cd6d 100644 --- a/archey +++ b/archey @@ -39,6 +39,7 @@ colorDict = { deDict = { 'gnome-session': 'GNOME', + 'mate-session': 'MATE', 'ksmserver': 'KDE', 'xfce4-session': 'Xfce', 'lxsession': 'LXDE' -- cgit v1.2.3-54-g00ecf From 80ae452a4792014e203418cdf9efadbb2181b32c Mon Sep 17 00:00:00 2001 From: Aurélien DESBRIÈRES Date: Tue, 17 Jun 2014 17:05:09 +0200 Subject: paraboley the rebranded version of archey3 --- COPYING | 5 + PKGBUILD | 30 ++ README.md | 4 + paraboley | 865 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ paraboley.new | 261 ++++++++++++++++++ setup.py | 17 ++ 6 files changed, 1182 insertions(+) create mode 100644 COPYING create mode 100644 PKGBUILD create mode 100644 README.md create mode 100755 paraboley create mode 100755 paraboley.new create mode 100644 setup.py diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..5355640 --- /dev/null +++ b/COPYING @@ -0,0 +1,5 @@ +This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with this program. If not, see . diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..0767b86 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,30 @@ +# Maintainer (Parabola) : Aurélien DESBRIÈRES + +pkgname=paraboley +pkgver=0.1 +pkgrel=1 +pkgdesc="Python script to display system infomation alongside the Parabola GNU / Linux-libre logo." +arch=('any') +url="http://XL04D.github.com/paraboley" +license=('GPL') +depends=('python') +makedepends=('git' 'python-distribute') +optdepends=( +'python-mpd-git: python libary for mpd interaction', +'python-logbook-git: for logging' +'imagemagick: for default screenshot command' +) +conflicts=() +provides=('paraboley') +source="git://github.com/XL04D/paraboley.git" + +pkgver() { + cd ${pkgname} + git describe --always | sed 's|-|.|g' +} + +package() { + cd "$srcdir/$pkgname" + python setup.py install --root=${pkgdir} + install -D -m644 COPYING ${pkgdir}/usr/share/licenses/paraboley/COPYING +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..e24e8fe --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Paraboley +======== + +Paraboley is a system infomation printer, designed to be used when taking screenshots of computer desktops to provide additional infomation about the operating system setup. Paraboley is designed to be used for Parabola GNU / Linux-libre, and it acordingly prints out the Parabola GNU / Linux-libre logo along side the system infomation. \ No newline at end of file diff --git a/paraboley b/paraboley new file mode 100755 index 0000000..122b3cb --- /dev/null +++ b/paraboley @@ -0,0 +1,865 @@ +#!/usr/bin/env python +# +# Paraboley is a forked made by Aurélien DESBIRÈRES +# of archey3 to present the Parabola GNU / Linux-libre logo and informations +# +# archey3 [version 0.5] +# +# Copyright 2010 Melik Manukyan +# Copyright 2010-2012 Laurie Clark-Michalek +# Distributed under the terms of the GNU General Public License v3. +# See http://www.gnu.org/licenses/gpl.txt for the full license text. +# +# Simple python script to display an Archlinux logo in ASCII art +# Along with basic system information. + +# Import libraries + +import collections +import subprocess, optparse, re, sys, configparser +from subprocess import Popen, PIPE +from optparse import OptionParser +from getpass import getuser +from time import ctime, sleep +from os import getenv +from datetime import datetime +import re +import os.path +import multiprocessing + +try: + from logbook import Logger, lookup_level +except ImportError: + class Logger(object): + def __init__(self, name, level=0): + self.name = name + self.level = level + debug = info = warn = warning = notice = error = exception = \ + critical = log = lambda *a, **kw: None + + def lookup_level(_): + return 0 + +UNAME_FLAG_MEANINGS = { + 'a': 'System Infomation', + 's': 'Kernel Name', + 'n': 'Hostname', + 'r': 'Kernel Release', + 'v': 'Kernel Version', + 'm': 'Machine Hardware name', + 'p': 'Processor Type', + 'i': 'Hardware Platform', +} + +LOGOS = {'Parabola': '''{c1} +{c1} ## ### {results[0]} +{c1} ## ## ##### {results[1]} +{c1} ## ## ## ####### {results[2]} +{c1} # ## ## ## ######## {results[3]} +{c1} ### # ######### {results[4]} +{c1} ### ######### {results[5]} +{c1} ## ######## {results[6]} +{c1} ####### {results[7]} +{c1} ###### {results[8]} +{c1} ###### {results[9]} +{c1} ##### {results[10]} +{c1} ##### {results[11]} +{c1} #### {results[12]} +{c1} #### {results[13]} +{c1} ### {results[14]} +{c1} ### {results[15]} +{c1} ## {results[16]} +{c1} # {results[17]} +\x1b[0m''' +} + +CLASS_MAPPINGS = {} + +def module_register(name): + """ + Registers the class in the CLASS_MAPPING global. + """ + def decorator(cls): + CLASS_MAPPINGS[name] = cls + return cls + return decorator + +DE_DICT = collections.OrderedDict([ + ('cinnamon', 'Cinnamon'), + ('gnome-session', 'GNOME'), + ('ksmserver', 'KDE'), + ('xfce4-session', 'Xfce'), + ('lxsession', 'LXDE'), + ('', 'None'), + ]) + +WM_DICT = collections.OrderedDict([ + ('awesome', 'Awesome'), + ('beryl', 'Beryl'), + ('blackbox', 'Blackbox'), + ('dwm', 'DWM'), + ('enlightenment', 'Enlightenment'), + ('fluxbox', 'Fluxbox'), + ('fvwm', 'FVWM'), + ('i3', 'i3'), + ('icewm', 'IceWM'), + ('kwin', 'KWin'), + ('metacity', 'Metacity'), + ('musca', 'Musca'), + ('openbox', 'Openbox'), + ('pekwm', 'PekWM'), + ('ratpoison', 'ratpoison'), + ('scrotwm', 'ScrotWM'), + ('subtle', 'subtle'), + ('monsterwm', 'MonsterWM'), + ('wmaker', 'Window Maker'), + ('wmfs', 'Wmfs'), + ('wmii', 'wmii'), + ('xfwm4', 'Xfwm'), + ('emerald', 'Emerald'), + ('compiz', 'Compiz'), + (re.compile('xmonad-*'), 'xmonad'), + ('qtile', 'QTile'), + ('wingo', 'Wingo'), + ('', 'None'), + ]) + +COLORS = { + 'black': '0', + 'red': '1', + 'green': '2', + 'yellow': '3', + 'blue': '4', + 'magenta': '5', + 'cyan': '6', + 'white': '7' +} + +class ArgumentError(Exception): + def __init__(self, caller, message): + msg = "{0}: {1}".format(caller.__class__.__name__, message) + super().__init__(msg) + +# State must be serializable +State = collections.namedtuple("State", "color config logger") + +class display(object): + command_line = '' + stdindata = '' + + def __init__(self, state, args=()): + self.state = state + # Python3 unpacking is awesome + self.arg1, self.arg2, self.arg3, *_ = tuple(args) + ('', '', '') + + @staticmethod + def call_command(command): + """ + Calls a command, waits for it to exit and returns all text from stdout. + Discards all other information. + """ + proc = Popen(command.split(), stdout=PIPE) + proc.wait() + return proc.communicate()[0].decode() + + def run_command(self): + if self.command_line: + if '{arg3}' in self.command_line: + cmd = self.command_line.format(arg1=self.arg1, arg2=self.arg2, + arg3=self.arg3) + elif '{arg2}' in self.command_line: + cmd = self.command_line.format(arg1=self.arg1, arg2=self.arg2) + elif '{arg1}' in self.command_line: + cmd = self.command_line.format(arg1=self.arg1) + else: + cmd = self.command_line + + try: + self.process = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, + stderr=PIPE) + except Exception as e: + self.state.logger.error("Could not run command {0}".format(cmd)) + + def render(self): + (stdoutdata, stderrdata) = self.process.communicate(self.stdindata + or None) + + return self.format_output(stdoutdata.decode()) + + def color_me(self, output, number=None, low=30, low_color='green', + medium=60, medium_color='yellow', high_color='red'): + if number is None and output.isdigit(): + number = int(output) + elif number is None: + return output + + if number <= low: + color_= low_color + elif low < number <= medium: + color_ = medium_color + elif medium < number: + color_ = high_color + + return '{0}{1}{2}'.format(color(self.state, color_), output, + color(self.state, 'clear')) + + regex_class = re.compile("").__class__ + def process_exists(self, key): + global PROCESSES + if isinstance(key, self.regex_class): + for proc in PROCESSES._processes: + if key.search(proc): + return True + return PROCESSES(key) + + +@module_register("fs") +class fsDisplay(display): + command_line = "df -TPh {arg1}" + + conversions = { + 'binary': { + 'K': 2 ** 10, + 'M': 2 ** 20, + 'G': 2 ** 30, + 'T': 2 ** 40, + }, + 'si': { + 'K': 10 ** 3, + 'M': 10 ** 6, + 'G': 10 ** 9, + 'T': 10 ** 12, + }, + } + + def __init__(self, **kwargs): + super().__init__(**kwargs) + if not self.arg1: + msg = "Did not any arguments, require one, the fs to display" + self.state.logger.error(msg) + raise ArgumentError(self, msg) + + def format_output(self, instring): + try: + decimal_point = self.call_command( + 'locale -ck decimal_point').split('\n')[1].split('=')[1] + except Exception as e: + self.state.logger.warning('Could not determine locale decimal point,' + + 'defaulting to \'.\', failed with error {0}'.format(e)) + decimal_point = '.' + values = [line for line in instring.split('\n') if line][1].split() + used = values[3].replace(decimal_point, '.') + total = values[2].replace(decimal_point, '.') + fstype = values[1] + conversion_type = self.state.config.get('fs', 'unit', fallback="si").lower() + conversions = self.conversions[conversion_type] + + mount = '/root' if self.arg1 == '/' else self.arg1 + title = mount.split('/')[-1].title() + + low = self.state.config.getint('fs', 'low_bound', fallback=40) + medium = self.state.config.getint('fs', 'medium_bound', fallback=70) + + try: + #convert to straight float + used_ = float(used[:-1]) * conversions[used[-1].upper()] + total_ = float(total[:-1]) * conversions[total[-1].upper()] + persentage = used_ / total_ * 100 + except Exception as e: + self.state.logger.error( + "Could not colorize output, errored with {0}".format(e)) + return + else: + used = self.color_me(used, persentage, low=low, medium=medium) + + if self.state.config.getboolean("fs", "persentage", fallback=True): + part = '{used} / {total} ({persentage}%) ({fstype})'.format( + used=used, total=total, persentage=int(persentage), + fstype=fstype) + else: + part = '{used} / {total} ({fstype})'.format( + used=used, total=total, fstype=fstype) + return title, part + +@module_register("ram") +class ramDisplay(display): + command_line = "free -m" + + def format_output(self, instring): + ram = ''.join(line for line in str(instring).split('\n') if\ + line.startswith('Mem:')).split() + used = int(ram[2]) - int(ram[5]) - int(ram[6]) + total = int(ram[1]) + title = 'RAM' + try: + persentage = (used / total * 100) + except: + used += ' MB' + else: + used = self.color_me(number=persentage, output=str(used) + ' MB') + part = '{used} / {total} MB'.format(used=used, total=total) + return title, part + +@module_register("sensor") +class sensorDisplay(display): + command_line = "sensors {arg1}" + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + arg_from_conf = self.state.config.get('sensor', 'sensor', + fallback='coretemp-*') + try: + arg_from_arg = kwargs["args"][0] + except IndexError: + self.state.logger.error( + "Did not get any arguments, require one, the sensor to display.") + raise + + if arg_from_arg: + self.arg1 = arg_from_arg + else: + self.arg1 = arg_from_conf + + def format_output(self, instring): + tempinfo = instring.split('\n')[2::4] + + out = [] + for line in tempinfo: + info = [re.sub("\s\s+", "", line) for line in line.split(' ') if\ + line] + value = info[1] + intvalue = int(value[:3]) + if intvalue > 45: + temp = (color(self.state, "red") + info[1] + + color(self.state, "clear")) + elif intvalue in range(30, 45): + temp = (color(self.state, "magenta") + info[1] + + color(self.state, "clear")) + else: + temp = (color(self.state, "green") + info[1] + + color(self.state, "clear")) + out.append((info[0], temp)) + return out + +@module_register("env") +class envDisplay(display): + def __init__(self, **kwargs): + try: + self.arg1 = kwargs["args"][0] + except IndexError: + self.state.logger.error("Did not get any arguments, require one," + + " the env variable to display.") + raise + + super().__init__(**kwargs) + + def render(self): + argvalue = getenv(self.arg1.upper()) + return ('$' + self.arg1.upper(), argvalue) + +@module_register("uname") +class unameDisplay(display): + command_line = "uname {arg1}" + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + try: + flag = kwargs["args"][0] + except IndexError: + self.state.logger.error("Did not get any arguments, require one," + + " the flag to pass to uname") + raise + + arg_from_conf = self.state.config.get('uname', 'argument', fallback="") + arg_from_arg = flag + if arg_from_arg: + self.arg1 = '-' + arg_from_arg + elif arg_from_conf: + self.arg1 = '-' + arg_from_conf + else: + self.arg1 = '' + + def format_output(self, instring): + return (UNAME_FLAG_MEANINGS[self.arg1[1]], instring) + +@module_register("cpu") +class cpuDisplay(display): + command_line = "cat /proc/cpuinfo" + + def format_output(self, instring): + kv = [line.split(":") for line in instring.split("\n") if line] + infodict = {} + for k, v in kv: + infodict[k.strip()] = v.strip() + return "Processor Type", infodict["model name"] + +@module_register("uptime") +class uptimeDisplay(display): + def render(self): + with open("/proc/uptime") as upfile: + raw = upfile.read() + fuptime = int(raw.split('.')[0]) + + day = int(fuptime / 86400) + fuptime = fuptime % 86400 + hour = int(fuptime / 3600) + fuptime = fuptime % 3600 + minute = int(fuptime / 60) + uptime = '{daystring}{hours}:{mins:02d}'.format( + daystring='{days} day{s}, '.format(days=day, s=('s' if day > 1 + else '')) if day else '', + hours = hour, mins = minute + ) + return "Uptime", uptime + +@module_register("packages") +class packageDisplay(display): + command_line = "pacman -Q" + + def format_output(self, instring): + return "Packages", len(instring.rstrip('\n').split('\n')) + +@module_register("distro") +class distroCheck(display): + def render(self): + try: + _ = open("/etc/pacman.conf") + except IOError: + distro = self.call_command("uname -o") + else: + distro = "Parabola" + distro = '{0} {1}'.format(distro, self.call_command("uname -m")) + return "OS", distro + +@module_register("process") +class processCheck(display): + command_line = "ps -u " + getuser() + + render = lambda self: self + + def run_command(self): + super().run_command() + out = str(self.process.communicate()[0]) + + self._processes = set() + for line in out.split("\\n"): + words = line.split() + if len(words) <= 3: + continue + + self._processes.add(words[3]) + + def __call__(self, proc): + if proc in self._processes: + return True + return False + +@module_register("wm") +class wmDisplay(display): + def render(self): + if self.state.config.get('wm', 'manual', fallback=False): + return "WM", self.state.config.get('wm', 'manual') + wm = '' + for key in WM_DICT.keys(): + if self.process_exists(key): + wm = key + break + return "WM", WM_DICT[wm] + +@module_register("de") +class deDisplay(display): + def render(self): + if self.state.config.get('de', 'manual', fallback=False): + return "DE", self.state.config.get('de', 'manual') + de = '' + for key in DE_DICT.keys(): + if self.process_exists(key): + de = key + break + return "DE", DE_DICT[de] + +@module_register("mpd") +class mpdDisplay(display): + """ + Displays certain stat about MPD database. If mpd not installed, output + nothing. + """ + command_line = "mpc stats --host {arg1} --port {arg2}" + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + try: + self.stat = kwargs["args"][0] + except IndexError: + self.state.logger.error("Did not get any arguments, require one," + + " the stat to display.") + self.arg1 = self.state.config.get('mpd', 'host', fallback='localhost') + self.arg2 = self.state.config.getint('mpd', 'port', fallback=6600) + + def format_output(self, instring): + lines = instring.split('\n') + stats = {} + try: + stats['artists'] = lines[0].split(':')[1].strip() + stats['albums'] = lines[1].split(':')[1].strip() + stats['songs'] = lines[2].split(':')[1].strip() + #if people don't have mpc installed then return None) + except: + self.state.logger.error( + "Could not parse mpc output, is mpc installed?") + return + + return ('{statname} in MPD database'.format(statname=self.stat.title()), + stats[self.stat]) + +@module_register("system_upgrade") +class systemUpgrade(display): + + _upgrade_message = 'starting full system upgrade' + + def render(self): + try: + datestr = None + for line in reversed(list(open('/var/log/pacman.log'))): + if line.rstrip().endswith(self._upgrade_message): + datestart = line.find('[') + dateend = line.find(']') + if datestart != -1 and dateend != -1: + datestr = line[datestart + 1 : dateend] + break + except Exception as err: + print(err) + + if not datestr: + datestr = 'Unknown' + else: + currenttime = datetime.today() + updatetime = datetime.strptime(datestr, '%Y-%m-%d %H:%M') + numdays = (currenttime - updatetime).days + datestr = '{0} ({1} days ago)'.format(datestr, numdays) + + return "Last Upgrade", datestr + +#------------ Config ----------- + +class ArcheyConfigParser(configparser.SafeConfigParser): + """ + A parser for the archey config file. + """ + + defaults = {'core': {'align': 'top', + 'color': 'blue', + 'display_modules': + """\ +distro(), uname(n), uname(r), uptime(), wm(), de(), packages(), ram(),\ + cpu(), env(editor), fs(/), mpd(albums)""" + }, + } + + def read(self, file_location=None): + """ + Loads the config options stored in at file_location. If file_location + does not exist, it will attempt to load from the default config location + ($XDG_CONFIG_HOME/archey3.cfg). If that does not exist, it will write a + default config file to $XDG_CONFIG_HOME/archey3.cfg. + """ + + if file_location is None and "XDG_CONFIG_HOME" not in os.environ: + config_location = os.path.expanduser("~/.archey3.cfg") + elif file_location is None: + config_location = os.path.expandvars("$XDG_CONFIG_HOME/archey3.cfg") + else: + config_location = \ + os.path.expandvars(os.path.expanduser(file_location)) + + loaded = super(ArcheyConfigParser, self).read(config_location) + + if file_location == None and not loaded: + self.load_default_config() + self.write_config(config_location) + return [config_location] + if not loaded: + #Try with default + loaded = super(ArcheyConfigParser, self).read() + return loaded + + def load_default_config(self): + """ + Loads the config options stored at self.defaults. + """ + for section, values in self.defaults.items(): + if not self.has_section(section): + self.add_section(section) + + for option, value in values.items(): + #strip any excess spaces + value = re.sub("( +)", " ", value) + self.set(section, option, value) + + def write_config(self, location): + """ + Writes the current config to the given location. + """ + with open(location, 'w') as configfile: + self.write(configfile) + + +#------------ Functions ----------- + +def screenshot(state): + print('Screenshotting in') + screenshot_time = state.config.getint("core", "screenshotwait", fallback=5) + for x in sorted(range(1, screenshot_time + 1), reverse=True): + print('%s' % x, end='') + sys.stdout.flush() + sleep(1.0/3) + for x in range(3): + print('.', end='') + sys.stdout.flush() + sleep(1.0/3) + + print('Say Cheese!') + sys.stdout.flush() + + screenshot_command = state.config.get('core', 'screenshot_command', + fallback="import -window root .jpg") + try: + subprocess.check_call( + screenshot_command.replace('', + ctime().replace(' ','_')).split(" ")) + except subprocess.CalledProcessError as e: + state.logger.critical('Screenshot failed with return code {0}.'.format( + e.returncode)) + raise + except subprocess.FileNotFoundError: + print("Could not find import command, install imagemagick") + +def color(state, code, bold=False): + """ + Returns a character color sequence acording to the code given, and the + color theme in the state argument. + """ + if code == 2: + bold = True + first_bitty_bit = '\x1b[{0};'.format(int(not bold)) + if code in range(3): + second_bitty_bit = '3{0}m'.format(state.color) + elif code == "clear": + return '\x1b[0m' + else: + second_bitty_bit = '3{0}m'.format(COLORS[code]) + + return first_bitty_bit + second_bitty_bit + +def _mp_render_helper(container): + """ + A little helper to get round the one iterator argument with + multiprocessing.Pool.map. + """ + state = container["state"] + cls_name = container["cls_name"] + args = container["args"] + cls = CLASS_MAPPINGS[cls_name] + return render_class(state, cls, args) + +def render_class(state, cls, args): + """ + Returns the result of the run_command method for the class passed. + """ + try: + instance = cls(args=args, state=State( + logger=Logger(cls.__name__, state.logger.level), + color=state.color, + config=state.config)) + + except Exception as e: + state.logger.error( + "Could not instantiate {0}, failed with error {1}".format( + cls.__name__, e)) + return + try: + instance.run_command() + return instance.render() + except Exception as e: + state.logger.error( + "Could not render line for {0}, failed with error {1}".format( + cls.__name__, e)) + +#------------ Display object --------- + +class Archey(object): + DISPLAY_PARSING_REGEX = "(?P\w+)\((|(?P[\w, /]+))\)" + + def __init__(self, config, options): + log_level = lookup_level(options.log_level) + logger = Logger("Core", log_level) + + self.display = config.get("core", "display_modules") + colorscheme = options.color or config.get( + "core", "color", fallback="blue") + for key in COLORS.keys(): + if key == colorscheme: + colorcode = COLORS[key] + + self.state = State(colorcode, config, logger) + + global PROCESSES + PROCESSES = render_class(self.state, processCheck, ()) + + distro_out = render_class(self.state, distroCheck, ()) + + if not distro_out: + self.state.logger.critical( + "Unrecognised distribution.") + raise RuntimeException("Unrecognised distribution.") + + self.distro_name = ' '.join(distro_out[1].split()[:-1]) + + def run(self, screenshot_=False): + """ + Actually print the logo etc, and take a screenshot if required. + """ + print(self.render()) + + if screenshot_: + screenshot(self.state) + + def render(self): + results = self.prepare_results() + results = self.arrange_results(results) + + return LOGOS[self.distro_name].format(c1=color(self.state, 1), + results = results + ) + + def prepare_results(self): + """ + Renders all classes found in the display array, and then returns them + as a list. The returned list will be exactly 18 items long, with any + left over spaces being filled with empty strings. + """ + poolsize = self.state.config.getint("core", "poolsize", fallback=5) + + pool = multiprocessing.Pool(poolsize) + + arguments = [] + for cls_name, args in self.parse_display(): + arguments.append({ + 'cls_name': cls_name, + 'args': args, + 'state': self.state + }) + raw_out = pool.map(_mp_render_helper, arguments) + outputs = list(map(self.format_item, + filter(bool, raw_out))) + + + return outputs + [""] * (18 - len(outputs)) + + def arrange_results(self, results): + """ + Arranges the results as specified in the config file. + """ + arrangement = self.state.config.get("core", "align", fallback="top") + if arrangement == "top": + return results + elif arrangement == "bottom": + actuall_res = [res for res in results if res] + return [""] * (len(results) - len(actuall_res)) + actuall_res + elif arrangement == "center": + actuall_res = [res for res in results if res] + offset = [""] * int((len(results) - len(actuall_res)) / 2) + return (offset + actuall_res + + [""] * (len(results) - len(actuall_res))) + else: + return results + + def parse_display(self): + """ + Iterates over the display attribute of the Archey class, and tries to + parse them using the DISPLAY_PARSING_REGEX. + """ + for func in self.display.split(","): + func = func.strip() + + info = re.match(self.DISPLAY_PARSING_REGEX, func) + if not info: + self.state.logger.error( + "Could not parse display string {0}".format(func)) + continue + + groups = info.groupdict() + if groups["args"]: + args = [arg.strip() for arg in groups["args"].split(",")] + else: + args = () + + yield groups["func"], args + raise StopIteration + + def format_item(self, item): + title = item[0].rstrip(':') + data = str(item[1]).rstrip() + + #if we're dealing with a fraction + if len(data.split('/')) == 2: + numerator = data.split('/')[0] + numerator = (color(self.state, 1, bold=True) + numerator + + color(self.state, 'clear')) + denominator = data.split('/')[1] + data = '/'.join((numerator, denominator)) + + return "{color}{title}:{clear} {data}".format( + color=color(self.state, 1), + title=title, + data=data, + clear=color(self.state, "clear") + ) + +def main(): + parser = OptionParser( + usage='%prog', + description="""%prog is a utility to display system info and take\ + screenshots""", + version="%prog 0.3") + parser.add_option('-c', '--color', + action='store', type='choice', dest='color', + choices=('black', + 'red', + 'green', + 'yellow', + 'blue', + 'magenta', + 'cyan', + 'white'), + help="""choose a color: black, red, green, yellow, blue, magenta,\ + cyan, white [Default: blue]""") + parser.add_option('-s', '--screenshot', + action='store_true', dest='screenshot', help='Take a screenshot') + parser.add_option('--config', + action='store', dest='config', default=None, + help="Set the location of the config file to load.") + parser.add_option('--debug', + action='store', type='choice', dest='log_level', + choices=('NOTSET', + 'DEBUG', + 'INFO', + 'WARNING', + 'ERROR', + 'CRITICAL'), + default='CRITICAL', + help="The level of errors you wish to display. Choices are\ + NOTSET, DEBUG, INFO, WARNING, ERROR, and CRITICAL. CRITICAL is the default.") + (options, args) = parser.parse_args() + + config = ArcheyConfigParser() + config.read(options.config) + + archey = Archey(config=config, options=options) + archey.run(options.screenshot) + +if __name__ == "__main__": + main() diff --git a/paraboley.new b/paraboley.new new file mode 100755 index 0000000..30dc17c --- /dev/null +++ b/paraboley.new @@ -0,0 +1,261 @@ +#!/usr/bin/env python3 +# +# Parabola-eye is maintain by Aurélien DESBRIÈRES +# it is a fork inspired from: +# +# Archey [version 0.3.0] +# +# Archey is a simple system information tool written in Python. +# +# Copyright 2010 Melik Manukyan +# +# ASCII art by Brett Bohnenkamper +# Changes Jerome Launay +# Fedora support by YeOK +# +# Distributed under the terms of the GNU General Public License v3. +# See http://www.gnu.org/licenses/gpl.txt for the full license text. + +# Import libraries +import os, sys, subprocess, optparse, re, linecache +from subprocess import Popen, PIPE +from optparse import OptionParser +from getpass import getuser +from time import ctime, sleep + +#---------------Output---------------# + +output = [ + 'User', + 'Hostname', + 'Distro', + 'Kernel', + 'Uptime', + 'WindowManager', + 'DesktopEnvironment', + 'Shell', + 'Terminal', + 'Packages', + 'CPU', + 'RAM', + 'Disk' + ] + +#---------------Dictionaries---------------# + +colorDict = { + 'Parabola GNU / Linux-libre': ['\x1b[0;34m', '\x1b[1;34m'], + 'Ubuntu': ['\x1b[0;31m', '\x1b[1;31m', '\x1b[0;33m'], + 'Debian': ['\x1b[0;31m', '\x1b[1;31m'], + 'Mint': ['\x1b[0;32m', '\x1b[1;37m'], + 'Crunchbang': ['\x1b[1;37m'], + 'Fedora': ['\x1b[0;34m', '\x1b[1;37m'], + 'Sensors': ['\x1b[0;31m', '\x1b[0;32m', '\x1b[0;33m'], + 'Clear': ['\x1b[0m'] + } + +deDict = { + 'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfce4-session': 'Xfce', + 'lxsession': 'LXDE' + } + +wmDict = { + 'awesome': 'Awesome', + 'beryl': 'Beryl', + 'blackbox': 'Blackbox', + 'compiz': 'Compiz', + 'dwm': 'DWM', + 'enlightenment': 'Enlightenment', + 'fluxbox': 'Fluxbox', + 'fvwm': 'FVWM', + 'i3': 'i3', + 'icewm': 'IceWM', + 'kwin': 'KWin', + 'metacity': 'Metacity', + 'musca': 'Musca', + 'openbox': 'Openbox', + 'pekwm': 'PekWM', + 'ratpoison': 'ratpoison', + 'scrotwm': 'ScrotWM', + 'wmaker': 'Window Maker', + 'wmfs': 'Wmfs', + 'wmii': 'wmii', + 'xfwm4': 'Xfwm', + 'xmonad': 'xmonad' + } + +logosDict = {'Parabola GNU / Linux-libre': '''{color[1]} +{color[1]} ## ### {results[1]} +{color[1]} ## ## ##### {results[2]} +{color[1]} ## ## ## ####### {results[3]} +{color[1]} # ## ## ## ######## {results[4]} +{color[1]} ### ## ## ## ####### {results[5]} +{color[1]} ##### ## ## ## ####### {results[6]} +{color[1]} ## ## ## ####### {results[7]} +{color[1]} ## ####### {results[8]} +{color[1]} ###### {results[9]} +{color[0]} ###### {results[10]} +{color[0]} ##### {results[11]} +{color[0]} ##### {results[12]} +{color[0]} #### {results[13]} +{color[0]} ### {results[14]} +{color[0]} ### {results[15]} +{color[0]} ## {results[16]} +{color[0]} # {reuslts[17]} +\x1b[0m''' +} + +processes = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', + '--no-headers')), encoding='utf8').rstrip('\n').split('\n') + +#---------------Classes---------------# + +class Output: + results = [] + results.extend(['']*(13)) + + def __init__(self): + self.distro = self.__detectDistro() + + def __detectDistro(self): + if os.path.exists('/etc/pacman.conf'): + return 'Parabola GNU / Linux-libre' + else: + sys.exit(1) + + def append(self, display): + self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) + + def output(self): + print(logosDict[self.distro].format(color = colorDict[self.distro], results = self.results)) + +class User: + def __init__(self): + self.key = 'User' + self.value = os.getenv('USER') + +class Hostname: + def __init__(self): + hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].decode('Utf-8').rstrip('\n') + self.key = 'Hostname' + self.value = hostname + +class Distro: + def __init__(self): + if os.path.exists('/etc/pacman.conf'): + distro = 'Parabola GNU / Linux-libre' + self.key = 'Distro' + self.value = distro + +class Kernel: + def __init__(self): + kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].decode('Utf-8').rstrip('\n') + self.key = 'Kernel' + self.value = kernel + +class Uptime: + def __init__(self): + fuptime = int(open('/proc/uptime').read().split('.')[0]) + day = int(fuptime / 86400) + fuptime = fuptime % 86400 + hour = int(fuptime / 3600) + fuptime = fuptime % 3600 + minute = int(fuptime / 60) + uptime = '' + if day == 1: + uptime += '%d day, ' % day + if day > 1: + uptime += '%d days, ' % day + uptime += '%d:%02d' % (hour, minute) + self.key = 'Uptime' + self.value = uptime + +class WindowManager: + def __init__(self): + wm = '' + for key in wmDict.keys(): + if key in processes: + wm = wmDict[key] + break + + self.key = 'Window Manager' + self.value = wm + +class DesktopEnvironment: + def __init__(self): + de = '' + for key in deDict.keys(): + if key in processes: + wm = wmDict[key] + break + + self.key = 'Desktop Environment' + self.value = de + +class Shell: + def __init__(self): + self.key = 'Shell' + self.value = os.getenv('SHELL') + +class Terminal: + def __init__(self): + self.key = 'Terminal' + self.value = os.getenv('TERM') + +class Packages: + def __init__(self): + p1 = Popen(['pacman', '-Q'], stdout=PIPE).communicate()[0].decode("Utf-8") + packages = len(p1.rstrip('\n').split('\n')) + self.key = 'Packages' + self.value = packages + +class CPU: + def __init__(self): + file = open('/proc/cpuinfo').readlines() + cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) + output ('CPU', cpuinfo) + +class RAM: + def __init__(self): + raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].decode('Utf-8').split('\n') + ram = ''.join(filter(re.compile('M').search, raminfo)).split() + used = int(ram[2]) - int(ram[5]) - int(ram[6]) + usedpercent = ((float(used) / float(ram[1])) * 100) + if usedpercent <= 33: + ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], ram[1]) + if usedpercent > 33 and usedpercent < 67: + ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][1], used, colorDict['Clear'][0], ram[1]) + if usedpercent >= 67: + ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][0], used, colorDict['Clear'][0], ram[1]) + self.key = 'RAM' + self.value = ramdisplay + +class Disk: + def __init__(self): + p1 = Popen(['df', '-Tlh', '--total', '-t', 'ext4', '-t', 'ext3', '-t', 'ext2', '-t', 'reiserfs', '-t', 'jfs', '-t', 'ntfs', '-t', 'fat32', '-t', 'btrfs', '-t', 'fuseblk'], stdout=PIPE).communicate()[0].decode("Utf-8") + total = p1.splitlines()[-1] + used = total.split()[3] + size = total.split()[2] + usedpercent = float(total.split()[5][:-1]) + + if usedpercent <= 33: + disk = '%s%s %s/ %s' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], size) + if usedpercent > 33 and usedpercent < 67: + disk = '%s%s %s/ %s' % (colorDict['Sensors'][1], used, colorDict['Clear'][0], size) + if usedpercent >= 67: + disk = '%s%s %s/ %s' % (colorDict['Sensors'][0], used, colorDict['Clear'][0], size) + self.key = 'Disk' + self.value = disk + +## TEST ## <<< TEMPORARY +out = Output() +out.append(Shell()) +out.append(Packages()) +out.append(Disk()) +out.append(RAM()) +out.append(Distro()) +out.append(WindowManager()) +#out.append(DesktopEnvirornment()) +out.output() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..9844d10 --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +import os +from setuptools import setup + +def read(fname): + return open(os.path.join(os.path.dirname(__file__), fname)).read() + +setup( + name="Paraboley", + version="0.1", + author="Aurélien DESBRIÈRES", + author_email="aurelien@hackers.camp", + description="A simple python scrip to display an Parabola GNU / Linux-libre logo in ASCII art along with basic system information.", + license="GPL", + url="http://XL04D.github.com/paraboley", + long_description=read("README.md"), + scripts=["paraboley"] +) -- cgit v1.2.3-54-g00ecf