From 7c1a45f0060f959bff4a0293a55d0edf4ea27194 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 04:17:32 -0800 Subject: first commit --- README | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 3210a599aadf97d8630d4b4a7dedeb8de279b553 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 04:19:03 -0800 Subject: first commit --- info2.py | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 info2.py diff --git a/info2.py b/info2.py new file mode 100644 index 0000000..42aab11 --- /dev/null +++ b/info2.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python + +# Import libraries. +from subprocess import Popen, PIPE + +# Define colors. +# Uncomment whatever color scheme you prefer. +clear = "\x1b[0m" # clear [Do NOT uncomment] + +# color = "\x1b[1;30m" # black +# color2 = "\x1b[0;30m" # black + +color = "\x1b[1;31m" # red +# color2 = "\x1b[0;30m" # red + +# color = "\x1b[1;32m" # green +color2 = "\x1b[0;32m" # green + +# color = "\x1b[1;33m" # yellow +# color2 = "\x1b[0;33m" # yellow + +# color = "\x1b[1;34m" # blue [Default] +# color2 = "\x1b[0;34m" # blue [Default] + +# color = "\x1b[1;35m" # magenta +# color2 = "\x1b[0;35m" # magenta + +# color = "\x1b[1;36m" # cyan +# color2 = "\x1b[0;36m" # cyan + +# color = "\x1b[1;37m" # white +# color2 = "\x1b[0;37m" # white + +# Define arrays containing values. +list = [] +blank = ['']*10 + +# Find running processes. +p1 = Popen(['ps', '-A'], stdout=PIPE) +p2 = Popen(["awk", '{print $4}'], stdin=p1.stdout, stdout=PIPE) +processes = p2.communicate()[0].split("\n") + +# Print coloured key with normal value. +def output(key, value): + output = "%s%s:%s %s" % (color, key, clear, value) + list.append(output) + +# Define operating system. +def os_display(): + os = "Arch Linux" + output('OS', os) + +# Define kernel. +def kernel_display(): + kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip("\n") + output ('Kernel', kernel) + +# Define uptime. +def uptime_display(): + p1 = Popen(['uptime'], stdout=PIPE) + p2 = Popen(['sed', '-e', 's/^.*up //', "-e", 's/, *[0-9]*.users.*//'], stdin=p1.stdout, stdout=PIPE) + uptime = p2.communicate()[0].rstrip("\n") + output ('Uptime', uptime) + p1 = p2 = None + +# Define battery. [Requires: acpi] +def battery_display(): + p1 = Popen(['acpi'], stdout=PIPE) + p2 = Popen(['sed', 's/.*, //'], stdin=p1.stdout, stdout=PIPE) + battery = p2.communicate()[0].rstrip("\n") + output ('Battery', battery) + +# Define desktop environment. +def de_display(): + dict = {'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfce-mcs-manager': 'Xfce'} + de = 'None found' + for key in dict.keys(): + if key in processes: de = dict[key] + output ('DE', de) + +# Define window manager. +def wm_display(): + dict = {'awesome': 'Awesome', + 'beryl': 'Beryl', + 'blackbox': 'Blackbox', + 'dwm': 'DWM', + 'enlightenment': 'Enlightenment', + 'fluxbox': 'Fluxbox', + 'fvwm': 'FVWM', + 'icewm': 'icewm', + 'kwin': 'kwin', + 'metacity': 'Metacity', + 'openbox': 'Openbox', + 'wmaker': 'Window Maker', + 'xfwm4': 'Xfwm', + 'xmonad': 'Xmonad'} + wm = 'None found' + for key in dict.keys(): + if key in processes: wm = dict[key] + output ('WM', wm) + +# Define packages. [number of packages installed on system] +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) + +# Define file system information. +def fs_display(): + # Display root filesystem information. [Enabled by default] + p1 = Popen(['df', '-Th'], stdout=PIPE) + p2 = Popen(['grep', "/$"], stdin=p1.stdout, stdout=PIPE) + p3 = Popen(['awk', '{print $4" / "$3}'], stdin=p2.stdout, stdout=PIPE) + root = p3.communicate()[0].rstrip("\n") + output ('Root', root) + + # Display home filesystem information. + # Uncomment if you have a seperate home filesystem. [Disabled by default] + h1 = Popen(['df', '-Th'], stdout=PIPE) + h2 = Popen(['grep', "/home$"], stdin=h1.stdout, stdout=PIPE) + h3 = Popen(['awk', '{print $4" / "$3}'], stdin=h2.stdout, stdout=PIPE) + home = h3.communicate()[0].rstrip("\n") + output ('Home', home) + + +# Values to display. +# Possible options: os, kernel, uptime, battery, de, wm, packages, fs. +display = [ 'os', 'kernel', 'battery', 'uptime', 'de', 'wm', 'packages', 'fs' ] + +# Run functions found in 'display' array. +for x in display: + funcname=x+"_display" + func=locals()[funcname] + func() + +# Fill 'list' array with with blank keys. [Do NOT remove] +list.extend(blank) + +# Result. +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 +""" % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[10], color2, list[10], color2, color2, color2, clear) + -- cgit v1.2.3 From f26e0f34efeb1fa398d02a7f966442b7e7128085 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 04:20:49 -0800 Subject: first commit --- archey.py | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ info2.py | 163 -------------------------------------------------------------- 2 files changed, 163 insertions(+), 163 deletions(-) create mode 100644 archey.py delete mode 100644 info2.py diff --git a/archey.py b/archey.py new file mode 100644 index 0000000..42aab11 --- /dev/null +++ b/archey.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python + +# Import libraries. +from subprocess import Popen, PIPE + +# Define colors. +# Uncomment whatever color scheme you prefer. +clear = "\x1b[0m" # clear [Do NOT uncomment] + +# color = "\x1b[1;30m" # black +# color2 = "\x1b[0;30m" # black + +color = "\x1b[1;31m" # red +# color2 = "\x1b[0;30m" # red + +# color = "\x1b[1;32m" # green +color2 = "\x1b[0;32m" # green + +# color = "\x1b[1;33m" # yellow +# color2 = "\x1b[0;33m" # yellow + +# color = "\x1b[1;34m" # blue [Default] +# color2 = "\x1b[0;34m" # blue [Default] + +# color = "\x1b[1;35m" # magenta +# color2 = "\x1b[0;35m" # magenta + +# color = "\x1b[1;36m" # cyan +# color2 = "\x1b[0;36m" # cyan + +# color = "\x1b[1;37m" # white +# color2 = "\x1b[0;37m" # white + +# Define arrays containing values. +list = [] +blank = ['']*10 + +# Find running processes. +p1 = Popen(['ps', '-A'], stdout=PIPE) +p2 = Popen(["awk", '{print $4}'], stdin=p1.stdout, stdout=PIPE) +processes = p2.communicate()[0].split("\n") + +# Print coloured key with normal value. +def output(key, value): + output = "%s%s:%s %s" % (color, key, clear, value) + list.append(output) + +# Define operating system. +def os_display(): + os = "Arch Linux" + output('OS', os) + +# Define kernel. +def kernel_display(): + kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip("\n") + output ('Kernel', kernel) + +# Define uptime. +def uptime_display(): + p1 = Popen(['uptime'], stdout=PIPE) + p2 = Popen(['sed', '-e', 's/^.*up //', "-e", 's/, *[0-9]*.users.*//'], stdin=p1.stdout, stdout=PIPE) + uptime = p2.communicate()[0].rstrip("\n") + output ('Uptime', uptime) + p1 = p2 = None + +# Define battery. [Requires: acpi] +def battery_display(): + p1 = Popen(['acpi'], stdout=PIPE) + p2 = Popen(['sed', 's/.*, //'], stdin=p1.stdout, stdout=PIPE) + battery = p2.communicate()[0].rstrip("\n") + output ('Battery', battery) + +# Define desktop environment. +def de_display(): + dict = {'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfce-mcs-manager': 'Xfce'} + de = 'None found' + for key in dict.keys(): + if key in processes: de = dict[key] + output ('DE', de) + +# Define window manager. +def wm_display(): + dict = {'awesome': 'Awesome', + 'beryl': 'Beryl', + 'blackbox': 'Blackbox', + 'dwm': 'DWM', + 'enlightenment': 'Enlightenment', + 'fluxbox': 'Fluxbox', + 'fvwm': 'FVWM', + 'icewm': 'icewm', + 'kwin': 'kwin', + 'metacity': 'Metacity', + 'openbox': 'Openbox', + 'wmaker': 'Window Maker', + 'xfwm4': 'Xfwm', + 'xmonad': 'Xmonad'} + wm = 'None found' + for key in dict.keys(): + if key in processes: wm = dict[key] + output ('WM', wm) + +# Define packages. [number of packages installed on system] +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) + +# Define file system information. +def fs_display(): + # Display root filesystem information. [Enabled by default] + p1 = Popen(['df', '-Th'], stdout=PIPE) + p2 = Popen(['grep', "/$"], stdin=p1.stdout, stdout=PIPE) + p3 = Popen(['awk', '{print $4" / "$3}'], stdin=p2.stdout, stdout=PIPE) + root = p3.communicate()[0].rstrip("\n") + output ('Root', root) + + # Display home filesystem information. + # Uncomment if you have a seperate home filesystem. [Disabled by default] + h1 = Popen(['df', '-Th'], stdout=PIPE) + h2 = Popen(['grep', "/home$"], stdin=h1.stdout, stdout=PIPE) + h3 = Popen(['awk', '{print $4" / "$3}'], stdin=h2.stdout, stdout=PIPE) + home = h3.communicate()[0].rstrip("\n") + output ('Home', home) + + +# Values to display. +# Possible options: os, kernel, uptime, battery, de, wm, packages, fs. +display = [ 'os', 'kernel', 'battery', 'uptime', 'de', 'wm', 'packages', 'fs' ] + +# Run functions found in 'display' array. +for x in display: + funcname=x+"_display" + func=locals()[funcname] + func() + +# Fill 'list' array with with blank keys. [Do NOT remove] +list.extend(blank) + +# Result. +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 +""" % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[10], color2, list[10], color2, color2, color2, clear) + diff --git a/info2.py b/info2.py deleted file mode 100644 index 42aab11..0000000 --- a/info2.py +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env python - -# Import libraries. -from subprocess import Popen, PIPE - -# Define colors. -# Uncomment whatever color scheme you prefer. -clear = "\x1b[0m" # clear [Do NOT uncomment] - -# color = "\x1b[1;30m" # black -# color2 = "\x1b[0;30m" # black - -color = "\x1b[1;31m" # red -# color2 = "\x1b[0;30m" # red - -# color = "\x1b[1;32m" # green -color2 = "\x1b[0;32m" # green - -# color = "\x1b[1;33m" # yellow -# color2 = "\x1b[0;33m" # yellow - -# color = "\x1b[1;34m" # blue [Default] -# color2 = "\x1b[0;34m" # blue [Default] - -# color = "\x1b[1;35m" # magenta -# color2 = "\x1b[0;35m" # magenta - -# color = "\x1b[1;36m" # cyan -# color2 = "\x1b[0;36m" # cyan - -# color = "\x1b[1;37m" # white -# color2 = "\x1b[0;37m" # white - -# Define arrays containing values. -list = [] -blank = ['']*10 - -# Find running processes. -p1 = Popen(['ps', '-A'], stdout=PIPE) -p2 = Popen(["awk", '{print $4}'], stdin=p1.stdout, stdout=PIPE) -processes = p2.communicate()[0].split("\n") - -# Print coloured key with normal value. -def output(key, value): - output = "%s%s:%s %s" % (color, key, clear, value) - list.append(output) - -# Define operating system. -def os_display(): - os = "Arch Linux" - output('OS', os) - -# Define kernel. -def kernel_display(): - kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip("\n") - output ('Kernel', kernel) - -# Define uptime. -def uptime_display(): - p1 = Popen(['uptime'], stdout=PIPE) - p2 = Popen(['sed', '-e', 's/^.*up //', "-e", 's/, *[0-9]*.users.*//'], stdin=p1.stdout, stdout=PIPE) - uptime = p2.communicate()[0].rstrip("\n") - output ('Uptime', uptime) - p1 = p2 = None - -# Define battery. [Requires: acpi] -def battery_display(): - p1 = Popen(['acpi'], stdout=PIPE) - p2 = Popen(['sed', 's/.*, //'], stdin=p1.stdout, stdout=PIPE) - battery = p2.communicate()[0].rstrip("\n") - output ('Battery', battery) - -# Define desktop environment. -def de_display(): - dict = {'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfce-mcs-manager': 'Xfce'} - de = 'None found' - for key in dict.keys(): - if key in processes: de = dict[key] - output ('DE', de) - -# Define window manager. -def wm_display(): - dict = {'awesome': 'Awesome', - 'beryl': 'Beryl', - 'blackbox': 'Blackbox', - 'dwm': 'DWM', - 'enlightenment': 'Enlightenment', - 'fluxbox': 'Fluxbox', - 'fvwm': 'FVWM', - 'icewm': 'icewm', - 'kwin': 'kwin', - 'metacity': 'Metacity', - 'openbox': 'Openbox', - 'wmaker': 'Window Maker', - 'xfwm4': 'Xfwm', - 'xmonad': 'Xmonad'} - wm = 'None found' - for key in dict.keys(): - if key in processes: wm = dict[key] - output ('WM', wm) - -# Define packages. [number of packages installed on system] -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) - -# Define file system information. -def fs_display(): - # Display root filesystem information. [Enabled by default] - p1 = Popen(['df', '-Th'], stdout=PIPE) - p2 = Popen(['grep', "/$"], stdin=p1.stdout, stdout=PIPE) - p3 = Popen(['awk', '{print $4" / "$3}'], stdin=p2.stdout, stdout=PIPE) - root = p3.communicate()[0].rstrip("\n") - output ('Root', root) - - # Display home filesystem information. - # Uncomment if you have a seperate home filesystem. [Disabled by default] - h1 = Popen(['df', '-Th'], stdout=PIPE) - h2 = Popen(['grep', "/home$"], stdin=h1.stdout, stdout=PIPE) - h3 = Popen(['awk', '{print $4" / "$3}'], stdin=h2.stdout, stdout=PIPE) - home = h3.communicate()[0].rstrip("\n") - output ('Home', home) - - -# Values to display. -# Possible options: os, kernel, uptime, battery, de, wm, packages, fs. -display = [ 'os', 'kernel', 'battery', 'uptime', 'de', 'wm', 'packages', 'fs' ] - -# Run functions found in 'display' array. -for x in display: - funcname=x+"_display" - func=locals()[funcname] - func() - -# Fill 'list' array with with blank keys. [Do NOT remove] -list.extend(blank) - -# Result. -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 -""" % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[10], color2, list[10], color2, color2, color2, clear) - -- cgit v1.2.3 From 8233927edded62feb947f88cf58f9a6e4c2c3818 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 04:35:44 -0800 Subject: second commit --- archey.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/archey.py b/archey.py index 42aab11..6a3a95f 100644 --- a/archey.py +++ b/archey.py @@ -5,16 +5,16 @@ from subprocess import Popen, PIPE # Define colors. # Uncomment whatever color scheme you prefer. -clear = "\x1b[0m" # clear [Do NOT uncomment] +clear = "\x1b[0m" # clear [Do NOT comment out] # color = "\x1b[1;30m" # black # color2 = "\x1b[0;30m" # black -color = "\x1b[1;31m" # red +# color = "\x1b[1;31m" # red # color2 = "\x1b[0;30m" # red # color = "\x1b[1;32m" # green -color2 = "\x1b[0;32m" # green +# color2 = "\x1b[0;32m" # green # color = "\x1b[1;33m" # yellow # color2 = "\x1b[0;33m" # yellow @@ -70,7 +70,7 @@ def battery_display(): battery = p2.communicate()[0].rstrip("\n") output ('Battery', battery) -# Define desktop environment. +# Define desktop environment. def de_display(): dict = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', @@ -101,34 +101,36 @@ def wm_display(): if key in processes: wm = dict[key] output ('WM', wm) -# Define packages. [number of packages installed on system] +# Define number of packages installed. 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) -# Define file system information. +# Define root partition information. def fs_display(): - # Display root filesystem information. [Enabled by default] + # Display root filesystem information. p1 = Popen(['df', '-Th'], stdout=PIPE) p2 = Popen(['grep', "/$"], stdin=p1.stdout, stdout=PIPE) p3 = Popen(['awk', '{print $4" / "$3}'], stdin=p2.stdout, stdout=PIPE) root = p3.communicate()[0].rstrip("\n") output ('Root', root) +# Define home partition information. +def home_display(): # Display home filesystem information. - # Uncomment if you have a seperate home filesystem. [Disabled by default] - h1 = Popen(['df', '-Th'], stdout=PIPE) - h2 = Popen(['grep', "/home$"], stdin=h1.stdout, stdout=PIPE) - h3 = Popen(['awk', '{print $4" / "$3}'], stdin=h2.stdout, stdout=PIPE) - home = h3.communicate()[0].rstrip("\n") + p1 = Popen(['df', '-Th'], stdout=PIPE) + p2 = Popen(['grep', "/home$"], stdin=p1.stdout, stdout=PIPE) + p3 = Popen(['awk', '{print $4" / "$3}'], stdin=p2.stdout, stdout=PIPE) + home = p3.communicate()[0].rstrip("\n") output ('Home', home) # Values to display. -# Possible options: os, kernel, uptime, battery, de, wm, packages, fs. -display = [ 'os', 'kernel', 'battery', 'uptime', 'de', 'wm', 'packages', 'fs' ] +# Possible Options [Enabled by default]: os, kernel, uptime, de, wm, packages, fs +# Possible Options [Disabled by default]: battery, home +display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs' ] # Run functions found in 'display' array. for x in display: @@ -159,5 +161,5 @@ print """%s %s ;#### ####; %s ##' '## %s #' `# %s -""" % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[10], color2, list[10], color2, color2, color2, clear) +""" % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) -- cgit v1.2.3 From 9f8eaf960a5975f01b4758785c6fb316dd6cd32a Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 04:52:50 -0800 Subject: third commit --- archey.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archey.py b/archey.py index 6a3a95f..a566efe 100644 --- a/archey.py +++ b/archey.py @@ -19,8 +19,8 @@ clear = "\x1b[0m" # clear [Do NOT comment out] # color = "\x1b[1;33m" # yellow # color2 = "\x1b[0;33m" # yellow -# color = "\x1b[1;34m" # blue [Default] -# color2 = "\x1b[0;34m" # blue [Default] +color = "\x1b[1;34m" # blue [Default] +color2 = "\x1b[0;34m" # blue [Default] # color = "\x1b[1;35m" # magenta # color2 = "\x1b[0;35m" # magenta -- cgit v1.2.3 From c00a51683921a069f38de2c1de8522205b7be8e2 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 05:33:56 -0800 Subject: Added support for system arch --- archey.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/archey.py b/archey.py index a566efe..fef4e23 100644 --- a/archey.py +++ b/archey.py @@ -39,6 +39,7 @@ blank = ['']*10 p1 = Popen(['ps', '-A'], stdout=PIPE) p2 = Popen(["awk", '{print $4}'], stdin=p1.stdout, stdout=PIPE) processes = p2.communicate()[0].split("\n") +p1 = p2 = None # Print coloured key with normal value. def output(key, value): @@ -47,7 +48,9 @@ def output(key, value): # Define operating system. def os_display(): - os = "Arch Linux" + p1 = Popen(['uname', '-m'],stdout=PIPE) + arch = p1.communicate()[0].rstrip("\n") + os = "Arch Linux %s" % arch output('OS', os) # Define kernel. -- cgit v1.2.3 From 6e825c1f48fad5d32eb97300e578d28d45e750e1 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 14:30:38 -0800 Subject: Removed README file --- README | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 README diff --git a/README b/README deleted file mode 100644 index e69de29..0000000 -- cgit v1.2.3 From 2b8f0772873389ede84dd6a645ffb5695a2e2bff Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 18:33:29 -0800 Subject: Major cleanup and replaced many pipes in favor of python --- archey.py | 105 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 50 insertions(+), 55 deletions(-) diff --git a/archey.py b/archey.py index fef4e23..bb010b1 100644 --- a/archey.py +++ b/archey.py @@ -5,72 +5,67 @@ from subprocess import Popen, PIPE # Define colors. # Uncomment whatever color scheme you prefer. -clear = "\x1b[0m" # clear [Do NOT comment out] +clear = '\x1b[0m' # clear [Do NOT comment out] -# color = "\x1b[1;30m" # black -# color2 = "\x1b[0;30m" # black +# color = '\x1b[1;30m' # black +# color2 = '\x1b[0;30m' # black -# color = "\x1b[1;31m" # red -# color2 = "\x1b[0;30m" # red +# color = '\x1b[1;31m' # red +# color2 = '\x1b[0;30m' # red -# color = "\x1b[1;32m" # green -# color2 = "\x1b[0;32m" # green +# color = '\x1b[1;32m' # green +# color2 = '\x1b[0;32m' # green -# color = "\x1b[1;33m" # yellow -# color2 = "\x1b[0;33m" # yellow +# color = '\x1b[1;33m' # yellow +# color2 = '\x1b[0;33m' # yellow -color = "\x1b[1;34m" # blue [Default] -color2 = "\x1b[0;34m" # blue [Default] +color = '\x1b[1;34m' # blue [Default] +color2 = '\x1b[0;34m' # blue [Default] -# color = "\x1b[1;35m" # magenta -# color2 = "\x1b[0;35m" # magenta +# color = '\x1b[1;35m' # magenta +# color2 = '\x1b[0;35m' # magenta -# color = "\x1b[1;36m" # cyan -# color2 = "\x1b[0;36m" # cyan +# color = '\x1b[1;36m' # cyan +# color2 = '\x1b[0;36m' # cyan -# color = "\x1b[1;37m" # white -# color2 = "\x1b[0;37m" # white +# color = '\x1b[1;37m' # white +# color2 = '\x1b[0;37m' # white # Define arrays containing values. list = [] blank = ['']*10 # Find running processes. -p1 = Popen(['ps', '-A'], stdout=PIPE) -p2 = Popen(["awk", '{print $4}'], stdin=p1.stdout, stdout=PIPE) -processes = p2.communicate()[0].split("\n") -p1 = p2 = None +p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') +processes = [process.split()[3] for process in p1 if process] +p1 = None # Print coloured key with normal value. def output(key, value): - output = "%s%s:%s %s" % (color, key, clear, value) + output = '%s%s:%s %s' % (color, key, clear, value) list.append(output) # Define operating system. def os_display(): - p1 = Popen(['uname', '-m'],stdout=PIPE) - arch = p1.communicate()[0].rstrip("\n") - os = "Arch Linux %s" % arch + arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') + os = 'Arch Linux %s' % (arch) output('OS', os) # Define kernel. def kernel_display(): - kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip("\n") + kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') output ('Kernel', kernel) # Define uptime. def uptime_display(): - p1 = Popen(['uptime'], stdout=PIPE) - p2 = Popen(['sed', '-e', 's/^.*up //', "-e", 's/, *[0-9]*.users.*//'], stdin=p1.stdout, stdout=PIPE) - uptime = p2.communicate()[0].rstrip("\n") + p1 = Popen(['uptime'], stdout=PIPE).communicate()[0].lstrip().split(' ') + uptime = ' '.join(p1[2:(p1.index(''))]).rstrip(',') output ('Uptime', uptime) - p1 = p2 = None # Define battery. [Requires: acpi] def battery_display(): - p1 = Popen(['acpi'], stdout=PIPE) - p2 = Popen(['sed', 's/.*, //'], stdin=p1.stdout, stdout=PIPE) - battery = p2.communicate()[0].rstrip("\n") + p1 = Popen(['acpi'], stdout=PIPE).communicate()[0].lstrip() + battery = p1.split(' ')[3].rstrip('\n') output ('Battery', battery) # Define desktop environment. @@ -108,36 +103,37 @@ def wm_display(): def packages_display(): p1 = Popen(['pacman', '-Q'], stdout=PIPE) p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE) - packages = p2.communicate()[0].rstrip("\n") + packages = p2.communicate()[0].rstrip('\n') output ('Packages', packages) -# Define root partition information. -def fs_display(): - # Display root filesystem information. - p1 = Popen(['df', '-Th'], stdout=PIPE) - p2 = Popen(['grep', "/$"], stdin=p1.stdout, stdout=PIPE) - p3 = Popen(['awk', '{print $4" / "$3}'], stdin=p2.stdout, stdout=PIPE) - root = p3.communicate()[0].rstrip("\n") +# Define root file system information. +def rootfs_display(): + p1 = Popen(['df', '-Th'], stdout=PIPE).communicate()[0] + drives = [line for line in p1.split('\n') if line] + for line in drives: + if line.endswith('/'): + root = line.split()[3] + break output ('Root', root) -# Define home partition information. -def home_display(): - # Display home filesystem information. - p1 = Popen(['df', '-Th'], stdout=PIPE) - p2 = Popen(['grep', "/home$"], stdin=p1.stdout, stdout=PIPE) - p3 = Popen(['awk', '{print $4" / "$3}'], stdin=p2.stdout, stdout=PIPE) - home = p3.communicate()[0].rstrip("\n") - output ('Home', home) - +# Define home file system information. +def homefs_display(): + p1 = Popen(['df', '-Th'], stdout=PIPE).communicate()[0] + drives = [line for line in p1.split('\n') if line] + for line in drives: + if line.endswith('/home'): + home = line.split()[3] + break + output ('home', home) # Values to display. -# Possible Options [Enabled by default]: os, kernel, uptime, de, wm, packages, fs -# Possible Options [Disabled by default]: battery, home -display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs' ] +# Possible Options [Enabled by default]: os, kernel, uptime, de, wm, packages, rootfs +# Possible Options [Disabled by default]: battery, homefs +display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'rootfs'] # Run functions found in 'display' array. for x in display: - funcname=x+"_display" + funcname=x+'_display' func=locals()[funcname] func() @@ -165,4 +161,3 @@ print """%s %s ##' '## %s #' `# %s """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) - -- cgit v1.2.3 From c3e80e956f378f666d784f16b651a0bfb9ebeebe Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 19:55:03 -0800 Subject: Added support for dynamic user defined filesystems. --- archey.py | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/archey.py b/archey.py index bb010b1..c62a821 100644 --- a/archey.py +++ b/archey.py @@ -33,7 +33,6 @@ color2 = '\x1b[0;34m' # blue [Default] # Define arrays containing values. list = [] -blank = ['']*10 # Find running processes. p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') @@ -106,39 +105,32 @@ def packages_display(): packages = p2.communicate()[0].rstrip('\n') output ('Packages', packages) -# Define root file system information. -def rootfs_display(): - p1 = Popen(['df', '-Th'], stdout=PIPE).communicate()[0] - drives = [line for line in p1.split('\n') if line] - for line in drives: - if line.endswith('/'): - root = line.split()[3] - break - output ('Root', root) - -# Define home file system information. -def homefs_display(): - p1 = Popen(['df', '-Th'], stdout=PIPE).communicate()[0] - drives = [line for line in p1.split('\n') if line] - for line in drives: - if line.endswith('/home'): - home = line.split()[3] - break - output ('home', home) +# Define file system information. +def fs_display(mount=''): + p1 = Popen(['df', '-Th', mount], stdout=PIPE).communicate()[0] + part = [line for line in p1.split('\n') if line][1] + part = part.split()[3] + if mount == '/': mount = '/root' + fs = mount.lstrip('/').title() + output (fs, part) # Values to display. -# Possible Options [Enabled by default]: os, kernel, uptime, de, wm, packages, rootfs -# Possible Options [Disabled by default]: battery, homefs -display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'rootfs'] +## Possible Options [Enabled by default]: 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' +## Possible Options [Disabled by default]: 'battery', 'fs:/MOUNT/POINT' +display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/', 'fs:/home' ] # Run functions found in 'display' array. for x in display: - funcname=x+'_display' + call = [arg for arg in x.split(':') if arg] + funcname=call[0] + "_display" func=locals()[funcname] - func() + if len(call) > 1: + func(arg) + else: + func() # Fill 'list' array with with blank keys. [Do NOT remove] -list.extend(blank) +list.extend(['']*(13 - len(display))) # Result. print """%s -- cgit v1.2.3 From f6ac375779cc9bfa1b5b86f4953767dbf2dc256a Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 21:30:47 -0800 Subject: Support added for screenshot --- archey.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/archey.py b/archey.py index c62a821..1759d98 100644 --- a/archey.py +++ b/archey.py @@ -34,6 +34,11 @@ color2 = '\x1b[0;34m' # blue [Default] # Define arrays containing values. list = [] +screen = 'yes' + +def screenshot(): + Popen(['scrot', '-cd5']) + # Find running processes. p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') processes = [process.split()[3] for process in p1 if process] @@ -111,7 +116,7 @@ def fs_display(mount=''): part = [line for line in p1.split('\n') if line][1] part = part.split()[3] if mount == '/': mount = '/root' - fs = mount.lstrip('/').title() + fs = mount.rpartition('/')[2].title() output (fs, part) # Values to display. @@ -153,3 +158,7 @@ print """%s %s ##' '## %s #' `# %s """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) + +if screen == 'yes': + screenshot() + exit -- cgit v1.2.3 From 05492ec7aaf53e8869db580373cdc669dec1e913 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 23:37:04 -0800 Subject: Fixed a minor bug in screenshot. --- archey.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/archey.py b/archey.py index 1759d98..dfa7ffa 100644 --- a/archey.py +++ b/archey.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # Import libraries. +import subprocess from subprocess import Popen, PIPE # Define colors. @@ -34,10 +35,11 @@ color2 = '\x1b[0;34m' # blue [Default] # Define arrays containing values. list = [] -screen = 'yes' - +# Screenshot +# Set to 'True' to enable screenshot. +screen = 'False' def screenshot(): - Popen(['scrot', '-cd5']) + subprocess.check_call(["scrot", "-cd5"]) # Find running processes. p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') @@ -159,6 +161,7 @@ print """%s %s #' `# %s """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) -if screen == 'yes': +if screen == 'True': screenshot() - exit +else: + quit -- cgit v1.2.3 From 4ead17b9a12aa31ccba5dfbb6eb2521e63eb3097 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 7 Dec 2009 23:38:54 -0800 Subject: Removed fs:/home from display --- archey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey.py b/archey.py index dfa7ffa..0302ed6 100644 --- a/archey.py +++ b/archey.py @@ -124,7 +124,7 @@ def fs_display(mount=''): # Values to display. ## Possible Options [Enabled by default]: 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' ## Possible Options [Disabled by default]: 'battery', 'fs:/MOUNT/POINT' -display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/', 'fs:/home' ] +display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' ] # Run functions found in 'display' array. for x in display: -- cgit v1.2.3 From 3eff245d2a0a322ae6198753af23813f40796a7f Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Tue, 8 Dec 2009 03:13:21 -0800 Subject: Redid uptime function in favor of native python --- archey.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/archey.py b/archey.py index 0302ed6..ef78ae2 100644 --- a/archey.py +++ b/archey.py @@ -2,6 +2,7 @@ # Import libraries. import subprocess +import datetime from subprocess import Popen, PIPE # Define colors. @@ -62,10 +63,15 @@ def kernel_display(): kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') output ('Kernel', kernel) -# Define uptime. def uptime_display(): - p1 = Popen(['uptime'], stdout=PIPE).communicate()[0].lstrip().split(' ') - uptime = ' '.join(p1[2:(p1.index(''))]).rstrip(',') + fuptime = open('/proc/uptime').read().split(' ')[0].split('.')[0] + h = int(fuptime)/3600 + m = int(fuptime)/60 + day = int(fuptime)/86400 + hour = int(h)-(24*int(day)) + minute = int(m)-(60*int(h)) + minute2 = '%s'.zfill(2) % (minute) + uptime = '%s, %s:%s' % (day, hour, minute2) output ('Uptime', uptime) # Define battery. [Requires: acpi] -- cgit v1.2.3 From a5eb26c2021989370e45e8034e5ee2dcf6b11f06 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Tue, 8 Dec 2009 04:10:17 -0800 Subject: Minor cleanup in uptime function --- archey.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/archey.py b/archey.py index ef78ae2..4dca101 100644 --- a/archey.py +++ b/archey.py @@ -65,13 +65,11 @@ def kernel_display(): def uptime_display(): fuptime = open('/proc/uptime').read().split(' ')[0].split('.')[0] - h = int(fuptime)/3600 - m = int(fuptime)/60 day = int(fuptime)/86400 - hour = int(h)-(24*int(day)) - minute = int(m)-(60*int(h)) + hour = (int(fuptime) / 3600) - (24 * (int(fuptime) / 86400)) + minute = (int(fuptime) / 60) - (60 * (int(fuptime) / 3600)) minute2 = '%s'.zfill(2) % (minute) - uptime = '%s, %s:%s' % (day, hour, minute2) + uptime = '%s days, %s:%s' % (day, hour, minute2) output ('Uptime', uptime) # Define battery. [Requires: acpi] -- cgit v1.2.3 From 9aff69fe461bcf8564423d1c4e853ab856c8b1da Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Tue, 8 Dec 2009 04:15:38 -0800 Subject: Fixed minor bug in uptime function --- archey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey.py b/archey.py index 4dca101..5d0f6fa 100644 --- a/archey.py +++ b/archey.py @@ -68,7 +68,7 @@ def uptime_display(): day = int(fuptime)/86400 hour = (int(fuptime) / 3600) - (24 * (int(fuptime) / 86400)) minute = (int(fuptime) / 60) - (60 * (int(fuptime) / 3600)) - minute2 = '%s'.zfill(2) % (minute) + minute2 = '%s'.zfill(3) % (minute) uptime = '%s days, %s:%s' % (day, hour, minute2) output ('Uptime', uptime) -- cgit v1.2.3 From 8ed7820c508f78a98ef9b08ce304b68c71737f24 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Tue, 8 Dec 2009 12:59:18 -0800 Subject: Some more work on uptime function --- archey.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/archey.py b/archey.py index 5d0f6fa..4b47d6c 100644 --- a/archey.py +++ b/archey.py @@ -64,13 +64,17 @@ def kernel_display(): output ('Kernel', kernel) def uptime_display(): - fuptime = open('/proc/uptime').read().split(' ')[0].split('.')[0] - day = int(fuptime)/86400 - hour = (int(fuptime) / 3600) - (24 * (int(fuptime) / 86400)) - minute = (int(fuptime) / 60) - (60 * (int(fuptime) / 3600)) - minute2 = '%s'.zfill(3) % (minute) - uptime = '%s days, %s:%s' % (day, hour, minute2) - output ('Uptime', uptime) + fuptime = int(open('/proc/uptime').read().split(' ')[0].split('.')[0]) + day = int(fuptime / 86400) + fuptime = fuptime % 86400 + hour = int(fuptime / 3600) + fuptime = fuptime % 3600 + minute = int(fuptime / 60) + uptime = '' + if day > 0: + uptime += '%d days, ' % day + uptime += '%d:%2d' % (hour, minute) + output('Uptime', uptime) # Define battery. [Requires: acpi] def battery_display(): -- cgit v1.2.3 From db41e798ca1e3a06d9087040ab8c7a185f74c52e Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Tue, 8 Dec 2009 16:05:24 -0800 Subject: Major cleanup --- archey.py | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/archey.py b/archey.py index 4b47d6c..af68108 100644 --- a/archey.py +++ b/archey.py @@ -2,10 +2,9 @@ # Import libraries. import subprocess -import datetime from subprocess import Popen, PIPE -# Define colors. +###### Color Scheme ####### # Uncomment whatever color scheme you prefer. clear = '\x1b[0m' # clear [Do NOT comment out] @@ -33,10 +32,15 @@ color2 = '\x1b[0;34m' # blue [Default] # color = '\x1b[1;37m' # white # color2 = '\x1b[0;37m' # white -# Define arrays containing values. +###### Values to display ####### +# Possible Options [Enabled by default]: os, kernel, uptime, de, wm, packages, fs:/ +# Possible Options [Disabled by default]: battery, fs:/MOUNT/POINT +display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' ] + +# Array containing values. list = [] -# Screenshot +###### Screenshot ####### # Set to 'True' to enable screenshot. screen = 'False' def screenshot(): @@ -52,37 +56,40 @@ def output(key, value): output = '%s%s:%s %s' % (color, key, clear, value) list.append(output) -# Define operating system. +# Operating System Function def os_display(): arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') os = 'Arch Linux %s' % (arch) output('OS', os) -# Define kernel. +# Kernel Function def kernel_display(): kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') output ('Kernel', kernel) +# Uptime Function def uptime_display(): - fuptime = int(open('/proc/uptime').read().split(' ')[0].split('.')[0]) + 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 > 0: + if day == 1: + uptime += '% day, ' % day + if day > 1: uptime += '%d days, ' % day - uptime += '%d:%2d' % (hour, minute) + uptime += '%d:%02d' % (hour, minute) output('Uptime', uptime) -# Define battery. [Requires: acpi] +# Battery Function [Requires: acpi] def battery_display(): p1 = Popen(['acpi'], stdout=PIPE).communicate()[0].lstrip() battery = p1.split(' ')[3].rstrip('\n') output ('Battery', battery) -# Define desktop environment. +# Desktop Environment Function def de_display(): dict = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', @@ -92,7 +99,7 @@ def de_display(): if key in processes: de = dict[key] output ('DE', de) -# Define window manager. +# Window Manager Function def wm_display(): dict = {'awesome': 'Awesome', 'beryl': 'Beryl', @@ -113,14 +120,14 @@ def wm_display(): if key in processes: wm = dict[key] output ('WM', wm) -# Define number of packages installed. +# 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) -# Define file system information. +# File System Function def fs_display(mount=''): p1 = Popen(['df', '-Th', mount], stdout=PIPE).communicate()[0] part = [line for line in p1.split('\n') if line][1] @@ -129,11 +136,6 @@ def fs_display(mount=''): fs = mount.rpartition('/')[2].title() output (fs, part) -# Values to display. -## Possible Options [Enabled by default]: 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' -## Possible Options [Disabled by default]: 'battery', 'fs:/MOUNT/POINT' -display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' ] - # Run functions found in 'display' array. for x in display: call = [arg for arg in x.split(':') if arg] @@ -144,10 +146,10 @@ for x in display: else: func() -# Fill 'list' array with with blank keys. [Do NOT remove] +# Fill the rest of array 'list' with blank values. [Do not remove] list.extend(['']*(13 - len(display))) -# Result. +###### Result ####### print """%s %s + %s # @@ -169,7 +171,5 @@ print """%s %s #' `# %s """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) -if screen == 'True': - screenshot() -else: - quit +# Take screenshot if it is enabled. +if screen == 'True': screenshot() -- cgit v1.2.3 From 8e9e3782618f773f105cade858d90c1bad06f051 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Wed, 9 Dec 2009 02:04:15 -0800 Subject: initial push --- archey | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 archey diff --git a/archey b/archey new file mode 100644 index 0000000..af68108 --- /dev/null +++ b/archey @@ -0,0 +1,175 @@ +#!/usr/bin/env python + +# Import libraries. +import subprocess +from subprocess import Popen, PIPE + +###### Color Scheme ####### +# Uncomment whatever color scheme you prefer. +clear = '\x1b[0m' # clear [Do NOT comment out] + +# color = '\x1b[1;30m' # black +# color2 = '\x1b[0;30m' # black + +# color = '\x1b[1;31m' # red +# color2 = '\x1b[0;30m' # red + +# color = '\x1b[1;32m' # green +# color2 = '\x1b[0;32m' # green + +# color = '\x1b[1;33m' # yellow +# color2 = '\x1b[0;33m' # yellow + +color = '\x1b[1;34m' # blue [Default] +color2 = '\x1b[0;34m' # blue [Default] + +# color = '\x1b[1;35m' # magenta +# color2 = '\x1b[0;35m' # magenta + +# color = '\x1b[1;36m' # cyan +# color2 = '\x1b[0;36m' # cyan + +# color = '\x1b[1;37m' # white +# color2 = '\x1b[0;37m' # white + +###### Values to display ####### +# Possible Options [Enabled by default]: os, kernel, uptime, de, wm, packages, fs:/ +# Possible Options [Disabled by default]: battery, fs:/MOUNT/POINT +display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' ] + +# Array containing values. +list = [] + +###### Screenshot ####### +# Set to 'True' to enable screenshot. +screen = 'False' +def screenshot(): + subprocess.check_call(["scrot", "-cd5"]) + +# Find running processes. +p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') +processes = [process.split()[3] for process in p1 if process] +p1 = None + +# Print coloured key with normal value. +def output(key, value): + output = '%s%s:%s %s' % (color, key, clear, value) + list.append(output) + +# Operating System Function +def os_display(): + 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) + +# 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 += '% 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) + +# Desktop Environment Function +def de_display(): + dict = {'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfce-mcs-manager': 'Xfce'} + de = 'None found' + for key in dict.keys(): + if key in processes: de = dict[key] + output ('DE', de) + +# Window Manager Function +def wm_display(): + dict = {'awesome': 'Awesome', + 'beryl': 'Beryl', + 'blackbox': 'Blackbox', + 'dwm': 'DWM', + 'enlightenment': 'Enlightenment', + 'fluxbox': 'Fluxbox', + 'fvwm': 'FVWM', + 'icewm': 'icewm', + 'kwin': 'kwin', + 'metacity': 'Metacity', + 'openbox': 'Openbox', + 'wmaker': 'Window Maker', + 'xfwm4': 'Xfwm', + 'xmonad': 'Xmonad'} + wm = 'None found' + for key in dict.keys(): + if key in processes: wm = dict[key] + output ('WM', wm) + +# 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) + +# File System Function +def fs_display(mount=''): + p1 = Popen(['df', '-Th', mount], stdout=PIPE).communicate()[0] + part = [line for line in p1.split('\n') if line][1] + part = part.split()[3] + if mount == '/': mount = '/root' + fs = mount.rpartition('/')[2].title() + 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() + +# Fill the rest of array 'list' with blank values. [Do not remove] +list.extend(['']*(13 - len(display))) + +###### Result ####### +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 +""" % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) + +# Take screenshot if it is enabled. +if screen == 'True': screenshot() -- cgit v1.2.3 From 2f5dca649c899769ca7cb815c5fbd600af050521 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Wed, 9 Dec 2009 02:34:17 -0800 Subject: added GNU GPL --- COPYING | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 COPYING 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 . -- cgit v1.2.3 From beb40870d7a22eca5c0eee2cfd14a2aa4beedaf5 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Thu, 10 Dec 2009 01:35:11 -0800 Subject: minor cleanup, added compiz wm --- archey | 11 ++-- archey.py | 175 -------------------------------------------------------------- 2 files changed, 7 insertions(+), 179 deletions(-) delete mode 100644 archey.py diff --git a/archey b/archey index af68108..0c56040 100644 --- a/archey +++ b/archey @@ -44,7 +44,7 @@ list = [] # Set to 'True' to enable screenshot. screen = 'False' def screenshot(): - subprocess.check_call(["scrot", "-cd5"]) + subprocess.check_call(["scrot", "-cd5"]) # Find running processes. p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') @@ -104,6 +104,7 @@ def wm_display(): dict = {'awesome': 'Awesome', 'beryl': 'Beryl', 'blackbox': 'Blackbox', + 'compiz': 'Compiz', 'dwm': 'DWM', 'enlightenment': 'Enlightenment', 'fluxbox': 'Fluxbox', @@ -168,8 +169,10 @@ print """%s %s ######' '###### %s %s ;#### ####; %s ##' '## -%s #' `# %s -""" % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) +%s #' `# """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2) # Take screenshot if it is enabled. -if screen == 'True': screenshot() +if screen == 'True': + print "%s" % (color) + screenshot() +print "%s" % (clear) diff --git a/archey.py b/archey.py deleted file mode 100644 index af68108..0000000 --- a/archey.py +++ /dev/null @@ -1,175 +0,0 @@ -#!/usr/bin/env python - -# Import libraries. -import subprocess -from subprocess import Popen, PIPE - -###### Color Scheme ####### -# Uncomment whatever color scheme you prefer. -clear = '\x1b[0m' # clear [Do NOT comment out] - -# color = '\x1b[1;30m' # black -# color2 = '\x1b[0;30m' # black - -# color = '\x1b[1;31m' # red -# color2 = '\x1b[0;30m' # red - -# color = '\x1b[1;32m' # green -# color2 = '\x1b[0;32m' # green - -# color = '\x1b[1;33m' # yellow -# color2 = '\x1b[0;33m' # yellow - -color = '\x1b[1;34m' # blue [Default] -color2 = '\x1b[0;34m' # blue [Default] - -# color = '\x1b[1;35m' # magenta -# color2 = '\x1b[0;35m' # magenta - -# color = '\x1b[1;36m' # cyan -# color2 = '\x1b[0;36m' # cyan - -# color = '\x1b[1;37m' # white -# color2 = '\x1b[0;37m' # white - -###### Values to display ####### -# Possible Options [Enabled by default]: os, kernel, uptime, de, wm, packages, fs:/ -# Possible Options [Disabled by default]: battery, fs:/MOUNT/POINT -display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' ] - -# Array containing values. -list = [] - -###### Screenshot ####### -# Set to 'True' to enable screenshot. -screen = 'False' -def screenshot(): - subprocess.check_call(["scrot", "-cd5"]) - -# Find running processes. -p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') -processes = [process.split()[3] for process in p1 if process] -p1 = None - -# Print coloured key with normal value. -def output(key, value): - output = '%s%s:%s %s' % (color, key, clear, value) - list.append(output) - -# Operating System Function -def os_display(): - 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) - -# 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 += '% 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) - -# Desktop Environment Function -def de_display(): - dict = {'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfce-mcs-manager': 'Xfce'} - de = 'None found' - for key in dict.keys(): - if key in processes: de = dict[key] - output ('DE', de) - -# Window Manager Function -def wm_display(): - dict = {'awesome': 'Awesome', - 'beryl': 'Beryl', - 'blackbox': 'Blackbox', - 'dwm': 'DWM', - 'enlightenment': 'Enlightenment', - 'fluxbox': 'Fluxbox', - 'fvwm': 'FVWM', - 'icewm': 'icewm', - 'kwin': 'kwin', - 'metacity': 'Metacity', - 'openbox': 'Openbox', - 'wmaker': 'Window Maker', - 'xfwm4': 'Xfwm', - 'xmonad': 'Xmonad'} - wm = 'None found' - for key in dict.keys(): - if key in processes: wm = dict[key] - output ('WM', wm) - -# 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) - -# File System Function -def fs_display(mount=''): - p1 = Popen(['df', '-Th', mount], stdout=PIPE).communicate()[0] - part = [line for line in p1.split('\n') if line][1] - part = part.split()[3] - if mount == '/': mount = '/root' - fs = mount.rpartition('/')[2].title() - 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() - -# Fill the rest of array 'list' with blank values. [Do not remove] -list.extend(['']*(13 - len(display))) - -###### Result ####### -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 -""" % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) - -# Take screenshot if it is enabled. -if screen == 'True': screenshot() -- cgit v1.2.3 From 572d3f7451e6b684342a10049a3ef0aaed2ec3dd Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Thu, 10 Dec 2009 01:37:13 -0800 Subject: minor clean up, added compiz wm --- archey | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 archey diff --git a/archey b/archey old mode 100644 new mode 100755 -- cgit v1.2.3 From d6ad49be46c119307f3df9be9202ac4328747307 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Thu, 10 Dec 2009 21:33:56 -0800 Subject: fixed small bug in uptime function --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 0c56040..535daba 100755 --- a/archey +++ b/archey @@ -77,7 +77,7 @@ def uptime_display(): minute = int(fuptime / 60) uptime = '' if day == 1: - uptime += '% day, ' % day + uptime += '%d day, ' % day if day > 1: uptime += '%d days, ' % day uptime += '%d:%02d' % (hour, minute) -- cgit v1.2.3 From 4e3cbd0c5ed3c9c1d109c406b238b24d10c9f1c8 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Fri, 11 Dec 2009 20:34:46 -0800 Subject: added dynamic support for color coding --- archey | 75 ++++++++++++++++++++++++------------------------------------------ 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/archey b/archey index 535daba..d182df5 100755 --- a/archey +++ b/archey @@ -1,50 +1,35 @@ #!/usr/bin/env python -# Import libraries. -import subprocess +# Import libraries +import subprocess, ConfigParser, optparse from subprocess import Popen, PIPE +from optparse import OptionParser -###### Color Scheme ####### -# Uncomment whatever color scheme you prefer. -clear = '\x1b[0m' # clear [Do NOT comment out] +# Import configuration +config = ConfigParser.RawConfigParser() +config.read('config') -# color = '\x1b[1;30m' # black -# color2 = '\x1b[0;30m' # black - -# color = '\x1b[1;31m' # red -# color2 = '\x1b[0;30m' # red - -# color = '\x1b[1;32m' # green -# color2 = '\x1b[0;32m' # green - -# color = '\x1b[1;33m' # yellow -# color2 = '\x1b[0;33m' # yellow - -color = '\x1b[1;34m' # blue [Default] -color2 = '\x1b[0;34m' # blue [Default] - -# color = '\x1b[1;35m' # magenta -# color2 = '\x1b[0;35m' # magenta - -# color = '\x1b[1;36m' # cyan -# color2 = '\x1b[0;36m' # cyan - -# color = '\x1b[1;37m' # white -# color2 = '\x1b[0;37m' # white - -###### Values to display ####### -# Possible Options [Enabled by default]: os, kernel, uptime, de, wm, packages, fs:/ -# Possible Options [Disabled by default]: battery, fs:/MOUNT/POINT -display = [ 'os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' ] - -# Array containing values. +# Array containing Values list = [] -###### Screenshot ####### -# Set to 'True' to enable screenshot. -screen = 'False' -def screenshot(): - subprocess.check_call(["scrot", "-cd5"]) +# Options +if __name__=="__main__": + parser = OptionParser("usage: %prog [-c COLOR]") + 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]") + (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 = '\x1b[0m' + +# Display +display = ['os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' ] # Find running processes. p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') @@ -147,7 +132,7 @@ for x in display: else: func() -# Fill the rest of array 'list' with blank values. [Do not remove] +# Array containing values. list.extend(['']*(13 - len(display))) ###### Result ####### @@ -169,10 +154,4 @@ print """%s %s ######' '###### %s %s ;#### ####; %s ##' '## -%s #' `# """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2) - -# Take screenshot if it is enabled. -if screen == 'True': - print "%s" % (color) - screenshot() -print "%s" % (clear) +%s #' `# %s """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) -- cgit v1.2.3 From 9f8e5b6c7c4a65c9107e5af296bc9cb5b27b2d70 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Fri, 11 Dec 2009 20:56:54 -0800 Subject: removed configparser --- archey | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/archey b/archey index d182df5..384a059 100755 --- a/archey +++ b/archey @@ -1,14 +1,10 @@ #!/usr/bin/env python # Import libraries -import subprocess, ConfigParser, optparse +import subprocess, optparse from subprocess import Popen, PIPE from optparse import OptionParser -# Import configuration -config = ConfigParser.RawConfigParser() -config.read('config') - # Array containing Values list = [] -- cgit v1.2.3 From 04658c6cff00a59c3b3ca9a0e7e6be989079704b Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Fri, 11 Dec 2009 23:23:36 -0800 Subject: added screenshot option --- archey | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/archey b/archey index 384a059..903db01 100755 --- a/archey +++ b/archey @@ -9,14 +9,16 @@ from optparse import OptionParser list = [] # Options -if __name__=="__main__": - parser = OptionParser("usage: %prog [-c COLOR]") - 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]") +if __name__=='__main__': + parser = OptionParser('usage: %prog [-c COLOR]') + 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 +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] @@ -37,6 +39,12 @@ def output(key, value): output = '%s%s:%s %s' % (color, key, clear, value) list.append(output) +# Screenshot Function +screen = '%s' % options.screenshot + +def screenshot(): + subprocess.check_call(['scrot', '-cd5']) + # Operating System Function def os_display(): arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') @@ -121,7 +129,7 @@ def fs_display(mount=''): # Run functions found in 'display' array. for x in display: call = [arg for arg in x.split(':') if arg] - funcname=call[0] + "_display" + funcname=call[0] + '_display' func=locals()[funcname] if len(call) > 1: func(arg) @@ -150,4 +158,8 @@ print """%s %s ######' '###### %s %s ;#### ####; %s ##' '## -%s #' `# %s """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) +%s #' `# +%s """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) + +if screen == 'True': + screenshot() -- cgit v1.2.3 From 0116ce8f191a26bec77a1dd39d9b4af130d76a21 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Sun, 13 Dec 2009 20:43:45 -0800 Subject: slight cleanup --- archey | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) mode change 100755 => 100644 archey diff --git a/archey b/archey old mode 100755 new mode 100644 index 903db01..d411ce0 --- a/archey +++ b/archey @@ -5,6 +5,20 @@ import subprocess, optparse from subprocess import Popen, PIPE from optparse import OptionParser +# Display +display = [ + 'os', + 'kernel', +# 'battery', + 'uptime', + 'de', + 'wm', + 'packages', +# 'fs:/boot', +# 'fs:/home', +# 'fs:/MOUNT/POINT + 'fs:/' ] + # Array containing Values list = [] @@ -26,9 +40,6 @@ color = '\x1b[1;3%sm' % colorcode color2 = '\x1b[0;3%sm' % colorcode clear = '\x1b[0m' -# Display -display = ['os', 'kernel', 'uptime', 'de', 'wm', 'packages', 'fs:/' ] - # Find running processes. p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') processes = [process.split()[3] for process in p1 if process] -- cgit v1.2.3 From 6516828325af9dfdea772c6b32e91a9565ca3d34 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Sun, 13 Dec 2009 20:56:33 -0800 Subject: added hostname function --- archey | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/archey b/archey index d411ce0..b5f8f6c 100644 --- a/archey +++ b/archey @@ -8,6 +8,7 @@ from optparse import OptionParser # Display display = [ 'os', + 'hostname', 'kernel', # 'battery', 'uptime', @@ -24,7 +25,7 @@ list = [] # Options if __name__=='__main__': - parser = OptionParser('usage: %prog [-c COLOR]') + parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the data displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 13 fields.') 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', @@ -67,6 +68,11 @@ def kernel_display(): kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') output ('Kernel', kernel) +# Kernel Function +def hostname_display(): + hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].rstrip('\n') + output ('Hostname', hostname) + # Uptime Function def uptime_display(): fuptime = int(open('/proc/uptime').read().split('.')[0]) -- cgit v1.2.3 From 0e3317220ac318ec412efd2342684be8c8816081 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Wed, 23 Dec 2009 14:06:14 -0800 Subject: slight bug fix in fs display --- archey | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/archey b/archey index b5f8f6c..676ce6b 100644 --- a/archey +++ b/archey @@ -17,7 +17,7 @@ display = [ 'packages', # 'fs:/boot', # 'fs:/home', -# 'fs:/MOUNT/POINT +# 'fs:/MOUNT/POINT', 'fs:/' ] # Array containing Values @@ -136,9 +136,9 @@ def packages_display(): # File System Function def fs_display(mount=''): - p1 = Popen(['df', '-Th', mount], stdout=PIPE).communicate()[0] + p1 = Popen(['df', '-Ph', mount], stdout=PIPE).communicate()[0] part = [line for line in p1.split('\n') if line][1] - part = part.split()[3] + part = part.split()[2] if mount == '/': mount = '/root' fs = mount.rpartition('/')[2].title() output (fs, part) -- cgit v1.2.3 From e27fe09ebcd399cc0e56dec787fd85d3342ab3fa Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Sun, 27 Dec 2009 19:15:01 -0800 Subject: Added support for Xfce 4.6 --- archey | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/archey b/archey index 676ce6b..7cdc2fb 100644 --- a/archey +++ b/archey @@ -99,7 +99,8 @@ def battery_display(): def de_display(): dict = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', - 'xfce-mcs-manager': 'Xfce'} + 'xfce-mcs-manager': 'Xfce 4', + 'xfconfd': 'Xfce 4.6'} de = 'None found' for key in dict.keys(): if key in processes: de = dict[key] @@ -113,12 +114,12 @@ def wm_display(): 'compiz': 'Compiz', 'dwm': 'DWM', 'enlightenment': 'Enlightenment', - 'fluxbox': 'Fluxbox', + 'fluxbox': 'Fluxbox', 'fvwm': 'FVWM', 'icewm': 'icewm', 'kwin': 'kwin', 'metacity': 'Metacity', - 'openbox': 'Openbox', + 'openbox': 'Openbox', 'wmaker': 'Window Maker', 'xfwm4': 'Xfwm', 'xmonad': 'Xmonad'} -- cgit v1.2.3 From 7231c462352cb14a7e1edd35e6e8f217e7e96e78 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Sun, 27 Dec 2009 19:24:07 -0800 Subject: Improved filesystem display --- archey | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/archey b/archey index 7cdc2fb..95e9f4a 100644 --- a/archey +++ b/archey @@ -138,10 +138,13 @@ def packages_display(): # File System Function def fs_display(mount=''): p1 = Popen(['df', '-Ph', mount], stdout=PIPE).communicate()[0] - part = [line for line in p1.split('\n') if line][1] - part = part.split()[2] + used = [line for line in p1.split('\n') if line][1] + used = used.split()[2] + total = [line for line in p1.split('\n') if line][1] + total = total.split()[1] if mount == '/': mount = '/root' fs = mount.rpartition('/')[2].title() + part = '%s / %s' % (used, total) output (fs, part) # Run functions found in 'display' array. -- cgit v1.2.3 From 829ce74ceca177bbbf0216c52f7cedfa767d29a3 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 28 Dec 2009 13:52:23 -0800 Subject: Added de_or_wm_display, and minor improvements in fs_display --- archey | 114 ++++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 70 insertions(+), 44 deletions(-) diff --git a/archey b/archey index 95e9f4a..973acd4 100644 --- a/archey +++ b/archey @@ -1,4 +1,13 @@ #!/usr/bin/env python +# +# archey [version 0.1-4] +# +# Maintained by Melik Manukyan +# Distributed under the terms of the GNU General Public License v3. +# See http://www.gnu.org/licenses/gpl.txt for the full license text. +# +# Program to display an Archlinux logo in ASCII art along with basic +# System information. # Import libraries import subprocess, optparse @@ -6,20 +15,22 @@ from subprocess import Popen, PIPE from optparse import OptionParser # Display +# Comment/Uncomment to Enable/Disable information. display = [ - 'os', - 'hostname', - 'kernel', -# 'battery', - 'uptime', - 'de', - 'wm', - 'packages', -# 'fs:/boot', -# 'fs:/home', -# 'fs:/MOUNT/POINT', - 'fs:/' ] - + 'os', # Display OS + 'hostname', # Display Machine Hostname + 'kernel', # Display Kernel +# 'battery', # Display Battery info [Requires 'acpi'] + 'uptime', # Display Uptime + 'de_or_wm', # Display DE or WM +# 'wm', # Display WM +# 'de', # Display DE + 'packages', # Display Number of Packages Installed +# 'fs:/boot', # Display /boot partition +# 'fs:/home', # Display /home partition +# 'fs:/MOUNT/POINT', # Display any partition, edit to your needs + 'fs:/' # Display / partition + ] # Array containing Values list = [] @@ -41,6 +52,28 @@ color = '\x1b[1;3%sm' % colorcode color2 = '\x1b[0;3%sm' % colorcode clear = '\x1b[0m' +# Define processes for identifying DEs or WMs. +de_dict = {'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfce-mcs-manager': 'Xfce 4', + 'xfconfd': 'Xfce 4.6'} +wm_dict = {'awesome': 'Awesome', + 'beryl': 'Beryl', + 'blackbox': 'Blackbox', + 'compiz': 'Compiz', + 'dwm': 'DWM', + 'enlightenment': 'Enlightenment', + 'fluxbox': 'Fluxbox', + 'fvwm': 'FVWM', + 'icewm': 'icewm', + 'kwin': 'KWin', + 'metacity': 'Metacity', + 'openbox': 'Openbox', + 'wmaker': 'Window Maker', + 'wmii': 'wmii', + 'xfwm4': 'Xfwm', + 'xmonad': 'xmonad'} + # Find running processes. p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') processes = [process.split()[3] for process in p1 if process] @@ -97,36 +130,27 @@ def battery_display(): # Desktop Environment Function def de_display(): - dict = {'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfce-mcs-manager': 'Xfce 4', - 'xfconfd': 'Xfce 4.6'} de = 'None found' - for key in dict.keys(): - if key in processes: de = dict[key] + for key in de_dict.keys(): + if key in processes: de = de_dict[key] output ('DE', de) - + # Window Manager Function def wm_display(): - dict = {'awesome': 'Awesome', - 'beryl': 'Beryl', - 'blackbox': 'Blackbox', - 'compiz': 'Compiz', - 'dwm': 'DWM', - 'enlightenment': 'Enlightenment', - 'fluxbox': 'Fluxbox', - 'fvwm': 'FVWM', - 'icewm': 'icewm', - 'kwin': 'kwin', - 'metacity': 'Metacity', - 'openbox': 'Openbox', - 'wmaker': 'Window Maker', - 'xfwm4': 'Xfwm', - 'xmonad': 'Xmonad'} - wm = 'None found' - for key in dict.keys(): - if key in processes: wm = dict[key] - output ('WM', wm) + wm = 'None found' + for key in wm_dict.keys(): + if key in processes: wm = wm_dict[key] + output ('WM', wm) + +# Desktop Environment or Window Manager Function +def de_or_wm_display(): + for key in de_dict.keys(): + if key in processes: + output ('DE', de_dict[key]) + return + for key in wm_dict.keys(): + if key in processes: + output ('WM', wm_dict[key]) # Packages Function def packages_display(): @@ -137,14 +161,16 @@ def packages_display(): # File System Function def fs_display(mount=''): - p1 = Popen(['df', '-Ph', mount], stdout=PIPE).communicate()[0] + p1 = Popen(['df', '-TPh', mount], stdout=PIPE).communicate()[0] used = [line for line in p1.split('\n') if line][1] - used = used.split()[2] + used = used.split()[3] total = [line for line in p1.split('\n') if line][1] - total = total.split()[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() - part = '%s / %s' % (used, total) + fs = mount.rpartition('/')[2].title() + " FS" + part = '%s / %s (%s)' % (used, total, type) output (fs, part) # Run functions found in 'display' array. -- cgit v1.2.3 From db664d007448216f22aeada1e9f7e312d12557fc Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 28 Dec 2009 17:49:03 -0800 Subject: added 2 more fields --- archey | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/archey b/archey index 973acd4..9f23fa4 100644 --- a/archey +++ b/archey @@ -36,7 +36,7 @@ list = [] # Options if __name__=='__main__': - parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the data displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 13 fields.') + parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the data 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', 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', @@ -57,6 +57,7 @@ de_dict = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', 'xfce-mcs-manager': 'Xfce 4', 'xfconfd': 'Xfce 4.6'} + wm_dict = {'awesome': 'Awesome', 'beryl': 'Beryl', 'blackbox': 'Blackbox', @@ -184,12 +185,12 @@ for x in display: func() # Array containing values. -list.extend(['']*(13 - len(display))) +list.extend(['']*(15 - len(display))) ###### Result ####### print """%s %s + -%s # +%s # %s %s ### %s %s ##### %s %s ###### %s @@ -203,10 +204,10 @@ print """%s %s .#######; ;#####. %s %s #########. .########` %s %s ######' '###### %s -%s ;#### ####; +%s ;#### ####; %s %s ##' '## %s #' `# -%s """ % (color, color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, color2, color, list[6], color, color2, color, list[7], color, color2, list[8], color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, color2, color2, clear) +%s """ % (color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, list[6], color, color2, color, list[7], color, color2, color, list[8], color, color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, list[13], color2, list[14], color2, color2, clear) if screen == 'True': screenshot() -- cgit v1.2.3 From ef80f926a38ee0ece863688f2a3eefe58db9345f Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Tue, 29 Dec 2009 13:01:30 -0800 Subject: minor cleanup --- archey | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/archey b/archey index 9f23fa4..80b9052 100644 --- a/archey +++ b/archey @@ -20,11 +20,11 @@ display = [ 'os', # Display OS 'hostname', # Display Machine Hostname 'kernel', # Display Kernel -# 'battery', # Display Battery info [Requires 'acpi'] + 'battery', # Display Battery info [Requires 'acpi'] 'uptime', # Display Uptime - 'de_or_wm', # Display DE or WM -# 'wm', # Display WM -# 'de', # Display DE +# 'de_or_wm', # Display DE or WM + 'wm', # Display WM + 'de', # Display DE 'packages', # Display Number of Packages Installed # 'fs:/boot', # Display /boot partition # 'fs:/home', # Display /home partition @@ -32,7 +32,7 @@ display = [ 'fs:/' # Display / partition ] # Array containing Values -list = [] +result = [] # Options if __name__=='__main__': @@ -83,7 +83,7 @@ p1 = None # Print coloured key with normal value. def output(key, value): output = '%s%s:%s %s' % (color, key, clear, value) - list.append(output) + result.append(output) # Screenshot Function screen = '%s' % options.screenshot @@ -185,7 +185,7 @@ for x in display: func() # Array containing values. -list.extend(['']*(15 - len(display))) +result.extend(['']*(15 - len(display))) ###### Result ####### print """%s @@ -207,7 +207,7 @@ print """%s %s ;#### ####; %s %s ##' '## %s #' `# -%s """ % (color, color, color, list[0], color, list[1], color, list[2], color, list[3], color, list[4], color, list[5], color, list[6], color, color2, color, list[7], color, color2, color, list[8], color, color2, list[9], color2, list[10], color2, list[11], color2, list[12], color2, list[13], color2, list[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, color2, clear) if screen == 'True': screenshot() -- cgit v1.2.3 From 6f7d728b146e4fac4c2c05e2e470718c486b3ff0 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Tue, 29 Dec 2009 19:19:57 -0800 Subject: Fixed de_or_wm function --- archey | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/archey b/archey index 80b9052..64e4284 100644 --- a/archey +++ b/archey @@ -22,9 +22,9 @@ display = [ 'kernel', # Display Kernel 'battery', # Display Battery info [Requires 'acpi'] 'uptime', # Display Uptime -# 'de_or_wm', # Display DE or WM - 'wm', # Display WM - 'de', # Display DE + 'de_or_wm', # Display DE or WM +# 'wm', # Display WM +# 'de', # Display DE 'packages', # Display Number of Packages Installed # 'fs:/boot', # Display /boot partition # 'fs:/home', # Display /home partition @@ -145,13 +145,18 @@ def wm_display(): # Desktop Environment or Window Manager Function def de_or_wm_display(): - for key in de_dict.keys(): - if key in processes: - output ('DE', de_dict[key]) - return - for key in wm_dict.keys(): - if key in processes: - output ('WM', wm_dict[key]) + gui = 'X' + if gui not in processes: + output ('GUI', 'Not Running') + if gui in processes: + for key in de_dict.keys(): + if key in processes: + output ('DE', de_dict[key]) + return + for key in wm_dict.keys(): + if key in processes: + output ('WM', wm_dict[key]) + return # Packages Function def packages_display(): -- cgit v1.2.3 From b60e01710accd6bd965953d38551fe428405db4e Mon Sep 17 00:00:00 2001 From: djmelik Date: Tue, 29 Dec 2009 23:21:25 -0700 Subject: disabled battery by default --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 64e4284..cf2530c 100644 --- a/archey +++ b/archey @@ -20,7 +20,7 @@ display = [ 'os', # Display OS 'hostname', # Display Machine Hostname 'kernel', # Display Kernel - 'battery', # Display Battery info [Requires 'acpi'] +# 'battery', # Display Battery info [Requires 'acpi'] 'uptime', # Display Uptime 'de_or_wm', # Display DE or WM # 'wm', # Display WM -- cgit v1.2.3 From e6b45415b62b478614a9629759dd70a0d4b09ae7 Mon Sep 17 00:00:00 2001 From: djmelik Date: Wed, 30 Dec 2009 02:08:42 -0700 Subject: removed de_or_wm function --- archey | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/archey b/archey index cf2530c..9e40915 100644 --- a/archey +++ b/archey @@ -22,9 +22,8 @@ display = [ 'kernel', # Display Kernel # 'battery', # Display Battery info [Requires 'acpi'] 'uptime', # Display Uptime - 'de_or_wm', # Display DE or WM -# 'wm', # Display WM -# 'de', # Display DE + 'wm', # Display WM + 'de', # Display DE 'packages', # Display Number of Packages Installed # 'fs:/boot', # Display /boot partition # 'fs:/home', # Display /home partition @@ -143,21 +142,6 @@ def wm_display(): if key in processes: wm = wm_dict[key] output ('WM', wm) -# Desktop Environment or Window Manager Function -def de_or_wm_display(): - gui = 'X' - if gui not in processes: - output ('GUI', 'Not Running') - if gui in processes: - for key in de_dict.keys(): - if key in processes: - output ('DE', de_dict[key]) - return - for key in wm_dict.keys(): - if key in processes: - output ('WM', wm_dict[key]) - return - # Packages Function def packages_display(): p1 = Popen(['pacman', '-Q'], stdout=PIPE) -- cgit v1.2.3 From 1f50fec2688039d482163862e0c1775882e6baf2 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Wed, 6 Jan 2010 16:37:16 -0800 Subject: Beta --- archey.beta | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 archey.beta diff --git a/archey.beta b/archey.beta new file mode 100644 index 0000000..23c2402 --- /dev/null +++ b/archey.beta @@ -0,0 +1,217 @@ +#!/usr/bin/env python +# +# archey [version 0.1-4] +# +# Maintained by Melik Manukyan +# Distributed under the terms of the GNU General Public License v3. +# See http://www.gnu.org/licenses/gpl.txt for the full license text. +# +# Program to display an Archlinux logo in ASCII art along with basic +# System information. + +# Import libraries +import subprocess, optparse, re +from subprocess import Popen, PIPE +from optparse import OptionParser + +# Display +# Comment/Uncomment to Enable/Disable information. +display = [ + 'os', # Display OS + 'hostname', # Display Machine Hostname + 'kernel', # Display Kernel +# 'battery', # Display Battery info [Requires 'acpi'] + 'uptime', # Display Uptime + 'wm', # Display WM + 'de', # Display DE + 'packages', # Display Number of Packages Installed + 'ram', # Display RAM usage + 'cpu', # Display CPU +# 'fs:/boot', # Display /boot partition +# 'fs:/home', # Display /home partition +# 'fs:/MOUNT/POINT', # Display any partition, edit to your needs + 'fs:/' # Display / partition + ] +# Array containing Values +result = [] + +# Options +if __name__=='__main__': + parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the data 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', + 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] +color = '\x1b[1;3%sm' % colorcode +color2 = '\x1b[0;3%sm' % colorcode +clear = '\x1b[0m' + +# Define processes for identifying DEs or WMs. +de_dict = {'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfce-mcs-manager': 'Xfce 4', + 'xfconfd': 'Xfce 4.6'} + +wm_dict = {'awesome': 'Awesome', + 'beryl': 'Beryl', + 'blackbox': 'Blackbox', + 'compiz': 'Compiz', + 'dwm': 'DWM', + 'enlightenment': 'Enlightenment', + 'fluxbox': 'Fluxbox', + 'fvwm': 'FVWM', + 'icewm': 'icewm', + 'kwin': 'KWin', + 'metacity': 'Metacity', + 'openbox': 'Openbox', + 'wmaker': 'Window Maker', + 'wmii': 'wmii', + 'xfwm4': 'Xfwm', + 'xmonad': 'xmonad'} + +# Find running processes. +p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') +processes = [process.split()[3] for process in p1 if process] +p1 = None + +# Print coloured key with normal value. +def output(key, value): + output = '%s%s:%s %s' % (color, key, clear, value) + result.append(output) + +# Screenshot Function +screen = '%s' % options.screenshot + +# 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])) + +def screenshot(): + subprocess.check_call(['scrot', '-cd5']) + +# Operating System Function +def os_display(): + 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 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 = file[4].replace('model name\t: ', '').rstrip('\n').replace('\t', ' ').replace('\t\t', ' ').replace(' ', '').replace(' ', '').replace(' ', '').replace(' ', '').replace(' ', '') + 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) + +# 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' + for key in de_dict.keys(): + if key in processes: de = de_dict[key] + output ('DE', 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) + +# 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) + +# 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) + +# 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() + +# Array containing values. +result.extend(['']*(15 - len(display))) + +###### Result ####### +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 """ % (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) + +if screen == 'True': + screenshot() -- cgit v1.2.3 From 5089612f856cd06ced2c4c4b677a1d24042537bc Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Wed, 6 Jan 2010 16:38:41 -0800 Subject: Added musca support --- archey.beta | 1 + 1 file changed, 1 insertion(+) diff --git a/archey.beta b/archey.beta index 23c2402..8a3ab45 100644 --- a/archey.beta +++ b/archey.beta @@ -71,6 +71,7 @@ wm_dict = {'awesome': 'Awesome', 'kwin': 'KWin', 'metacity': 'Metacity', 'openbox': 'Openbox', + 'musca': 'Musca', 'wmaker': 'Window Maker', 'wmii': 'wmii', 'xfwm4': 'Xfwm', -- cgit v1.2.3 From c7da02819908540623d2250aeac69838afedec7e Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Mon, 11 Jan 2010 09:59:56 -0800 Subject: Added support for CPU/RAM and various other WM's --- archey | 27 ++++++-- archey.beta | 218 ------------------------------------------------------------ 2 files changed, 22 insertions(+), 223 deletions(-) delete mode 100644 archey.beta diff --git a/archey b/archey index 9e40915..a3c20e8 100644 --- a/archey +++ b/archey @@ -10,7 +10,7 @@ # System information. # Import libraries -import subprocess, optparse +import subprocess, optparse, re from subprocess import Popen, PIPE from optparse import OptionParser @@ -25,6 +25,8 @@ display = [ 'wm', # Display WM 'de', # Display DE 'packages', # Display Number of Packages Installed + 'ram', # Display RAM usage + 'cpu', # Display CPU # 'fs:/boot', # Display /boot partition # 'fs:/home', # Display /home partition # 'fs:/MOUNT/POINT', # Display any partition, edit to your needs @@ -65,14 +67,16 @@ wm_dict = {'awesome': 'Awesome', 'enlightenment': 'Enlightenment', 'fluxbox': 'Fluxbox', 'fvwm': 'FVWM', - 'icewm': 'icewm', + 'icewm': 'IceWM', 'kwin': 'KWin', 'metacity': 'Metacity', - 'openbox': 'Openbox', - 'wmaker': 'Window Maker', + 'musca': 'Musca', + 'openbox': 'Openbox', + 'pekwm': 'PekWM', + 'wmaker': 'Window Maker', 'wmii': 'wmii', 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad'} + 'xmonad': 'Xmonad'} # Find running processes. p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') @@ -87,6 +91,13 @@ def output(key, value): # Screenshot Function screen = '%s' % options.screenshot +# 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])) + def screenshot(): subprocess.check_call(['scrot', '-cd5']) @@ -106,6 +117,12 @@ 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 = file[4].replace('model name\t: ', '').rstrip('\n').replace('\t', ' ').replace('\t\t', ' ').replace(' ', '').replace(' ', '').replace(' ', '').replace(' ', '').replace(' ', '') + output ('CPU', cpuinfo) + # Uptime Function def uptime_display(): fuptime = int(open('/proc/uptime').read().split('.')[0]) diff --git a/archey.beta b/archey.beta deleted file mode 100644 index 8a3ab45..0000000 --- a/archey.beta +++ /dev/null @@ -1,218 +0,0 @@ -#!/usr/bin/env python -# -# archey [version 0.1-4] -# -# Maintained by Melik Manukyan -# Distributed under the terms of the GNU General Public License v3. -# See http://www.gnu.org/licenses/gpl.txt for the full license text. -# -# Program to display an Archlinux logo in ASCII art along with basic -# System information. - -# Import libraries -import subprocess, optparse, re -from subprocess import Popen, PIPE -from optparse import OptionParser - -# Display -# Comment/Uncomment to Enable/Disable information. -display = [ - 'os', # Display OS - 'hostname', # Display Machine Hostname - 'kernel', # Display Kernel -# 'battery', # Display Battery info [Requires 'acpi'] - 'uptime', # Display Uptime - 'wm', # Display WM - 'de', # Display DE - 'packages', # Display Number of Packages Installed - 'ram', # Display RAM usage - 'cpu', # Display CPU -# 'fs:/boot', # Display /boot partition -# 'fs:/home', # Display /home partition -# 'fs:/MOUNT/POINT', # Display any partition, edit to your needs - 'fs:/' # Display / partition - ] -# Array containing Values -result = [] - -# Options -if __name__=='__main__': - parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot]', description='To customize the data 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', - 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] -color = '\x1b[1;3%sm' % colorcode -color2 = '\x1b[0;3%sm' % colorcode -clear = '\x1b[0m' - -# Define processes for identifying DEs or WMs. -de_dict = {'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfce-mcs-manager': 'Xfce 4', - 'xfconfd': 'Xfce 4.6'} - -wm_dict = {'awesome': 'Awesome', - 'beryl': 'Beryl', - 'blackbox': 'Blackbox', - 'compiz': 'Compiz', - 'dwm': 'DWM', - 'enlightenment': 'Enlightenment', - 'fluxbox': 'Fluxbox', - 'fvwm': 'FVWM', - 'icewm': 'icewm', - 'kwin': 'KWin', - 'metacity': 'Metacity', - 'openbox': 'Openbox', - 'musca': 'Musca', - 'wmaker': 'Window Maker', - 'wmii': 'wmii', - 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad'} - -# Find running processes. -p1 = Popen(['ps', '-A'], stdout=PIPE).communicate()[0].split('\n') -processes = [process.split()[3] for process in p1 if process] -p1 = None - -# Print coloured key with normal value. -def output(key, value): - output = '%s%s:%s %s' % (color, key, clear, value) - result.append(output) - -# Screenshot Function -screen = '%s' % options.screenshot - -# 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])) - -def screenshot(): - subprocess.check_call(['scrot', '-cd5']) - -# Operating System Function -def os_display(): - 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 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 = file[4].replace('model name\t: ', '').rstrip('\n').replace('\t', ' ').replace('\t\t', ' ').replace(' ', '').replace(' ', '').replace(' ', '').replace(' ', '').replace(' ', '') - 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) - -# 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' - for key in de_dict.keys(): - if key in processes: de = de_dict[key] - output ('DE', 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) - -# 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) - -# 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) - -# 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() - -# Array containing values. -result.extend(['']*(15 - len(display))) - -###### Result ####### -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 """ % (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) - -if screen == 'True': - screenshot() -- cgit v1.2.3 From 68663495040dca4d19d9901a2c9cedfaf6daac57 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Tue, 12 Jan 2010 13:12:43 -0800 Subject: xmonad bug fixed, and minor cleanup in CPU function --- archey | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/archey b/archey index a3c20e8..77a5c76 100644 --- a/archey +++ b/archey @@ -76,11 +76,15 @@ wm_dict = {'awesome': 'Awesome', 'wmaker': 'Window Maker', 'wmii': 'wmii', 'xfwm4': 'Xfwm', - 'xmonad': 'Xmonad'} + 'xmonad': 'xmonad'} # 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') -processes = [process.split()[3] for process in p1 if process] +processes = map(xmonadfix, [process.split()[3] for process in p1 if process]) p1 = None # Print coloured key with normal value. @@ -120,7 +124,7 @@ def hostname_display(): # CPU Function def cpu_display(): file = open('/proc/cpuinfo').readlines() - cpuinfo = file[4].replace('model name\t: ', '').rstrip('\n').replace('\t', ' ').replace('\t\t', ' ').replace(' ', '').replace(' ', '').replace(' ', '').replace(' ', '').replace(' ', '') + cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) output ('CPU', cpuinfo) # Uptime Function @@ -151,7 +155,7 @@ def de_display(): for key in de_dict.keys(): if key in processes: de = de_dict[key] output ('DE', de) - + # Window Manager Function def wm_display(): wm = 'None found' -- cgit v1.2.3 From dfa200bb2b47d5b53ee64fe8b566e60227cdebd0 Mon Sep 17 00:00:00 2001 From: Melik Manukyan Date: Fri, 15 Jan 2010 17:26:57 -0800 Subject: Added support for Reporting Shells --- archey | 66 ++++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/archey b/archey index 77a5c76..9bae108 100644 --- a/archey +++ b/archey @@ -1,43 +1,43 @@ #!/usr/bin/env python # -# archey [version 0.1-4] +# archey [version 0.1-7] # # Maintained by Melik Manukyan # Distributed under the terms of the GNU General Public License v3. # See http://www.gnu.org/licenses/gpl.txt for the full license text. # -# Program to display an Archlinux logo in ASCII art along with basic -# System information. +# Simple python script to display an Archlinux logo in ASCII art +# Along with basic system information. # Import libraries import subprocess, optparse, re from subprocess import Popen, PIPE from optparse import OptionParser -# Display -# Comment/Uncomment to Enable/Disable information. +# Display [Comment/Uncomment to Enable/Disable information.] display = [ - 'os', # Display OS + 'os', # Display Operating System 'hostname', # Display Machine Hostname - 'kernel', # Display Kernel -# 'battery', # Display Battery info [Requires 'acpi'] - 'uptime', # Display Uptime - 'wm', # Display WM - 'de', # Display DE + '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 -# 'fs:/boot', # Display /boot partition -# 'fs:/home', # Display /home partition -# 'fs:/MOUNT/POINT', # Display any partition, edit to your needs - 'fs:/' # Display / partition + '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 data displayed on archey, edit "/usr/bin/archey" directly and look for the display array. Note: Archey can only allow up to 15 fields.') + 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', 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', @@ -53,7 +53,7 @@ color = '\x1b[1;3%sm' % colorcode color2 = '\x1b[0;3%sm' % colorcode clear = '\x1b[0m' -# Define processes for identifying DEs or WMs. +# Define processes for identifying Desktop Environmentss, Window Managers, Shells. de_dict = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', 'xfce-mcs-manager': 'Xfce 4', @@ -70,19 +70,26 @@ wm_dict = {'awesome': 'Awesome', 'icewm': 'IceWM', 'kwin': 'KWin', 'metacity': 'Metacity', - 'musca': 'Musca', - 'openbox': 'Openbox', + 'musca': 'Musca', + 'openbox': 'Openbox', 'pekwm': 'PekWM', - 'wmaker': 'Window Maker', + 'wmaker': 'Window Maker', 'wmii': 'wmii', 'xfwm4': 'Xfwm', 'xmonad': 'xmonad'} +sh_dict = {'zsh': 'Z-Shell', + 'bash': 'Bash', + 'dash': 'Dash', + 'fish': 'Fish', + 'ksh': 'Korn Shell', + 'jsh': 'Job control shell', + 'tcsh': 'The C Shell'} + # 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') processes = map(xmonadfix, [process.split()[3] for process in p1 if process]) p1 = None @@ -92,8 +99,6 @@ def output(key, value): output = '%s%s:%s %s' % (color, key, clear, value) result.append(output) -# Screenshot Function -screen = '%s' % options.screenshot # RAM Function def ram_display(): @@ -102,6 +107,8 @@ def ram_display(): 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']) @@ -116,7 +123,7 @@ def kernel_display(): kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n') output ('Kernel', kernel) -# Kernel Function +# Hostname Function def hostname_display(): hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].rstrip('\n') output ('Hostname', hostname) @@ -163,6 +170,13 @@ def wm_display(): if key in processes: wm = wm_dict[key] output ('WM', 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) + # Packages Function def packages_display(): p1 = Popen(['pacman', '-Q'], stdout=PIPE) -- cgit v1.2.3 From 17fdaadd18271a4db42995b3dd2f99ad1171a175 Mon Sep 17 00:00:00 2001 From: Laurie Date: Sat, 16 Jan 2010 14:34:59 +0000 Subject: Use ps -Au username, instead of ps -A to support multi user sessions --- archey | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/archey b/archey index 9bae108..b660da3 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 = [ @@ -26,7 +27,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 @@ -70,8 +71,8 @@ wm_dict = {'awesome': 'Awesome', 'icewm': 'IceWM', 'kwin': 'KWin', 'metacity': 'Metacity', - 'musca': 'Musca', - 'openbox': 'Openbox', + 'musca': 'Musca', + 'openbox': 'Openbox', 'pekwm': 'PekWM', 'wmaker': 'Window Maker', 'wmii': 'wmii', @@ -90,7 +91,7 @@ sh_dict = {'zsh': 'Z-Shell', 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', '-Au', getuser()], stdout=PIPE).communicate()[0].split('\n') processes = map(xmonadfix, [process.split()[3] for process in p1 if process]) p1 = None -- cgit v1.2.3 From 740d59f30348ced5956f41b5d05d6d3e901796a9 Mon Sep 17 00:00:00 2001 From: Laurie Date: Sat, 16 Jan 2010 14:38:48 +0000 Subject: Sorry, that should have been ps -u username, the A overrides the u --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index b660da3..1d20afc 100644 --- a/archey +++ b/archey @@ -91,7 +91,7 @@ sh_dict = {'zsh': 'Z-Shell', def xmonadfix(str): if re.compile("xmonad").match(str): return "xmonad" return str -p1 = Popen(['ps', '-Au', getuser()], 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 -- cgit v1.2.3 From b7b62dc4ee1d14b291cb4585a6c2dbf5e1da78b2 Mon Sep 17 00:00:00 2001 From: Laurie Date: Sat, 16 Jan 2010 15:01:14 +0000 Subject: Use import for screenshot, instead of scrot. Outputs file time.ctime().jpg --- archey | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archey b/archey index 1d20afc..815aec0 100644 --- a/archey +++ b/archey @@ -14,6 +14,7 @@ import subprocess, optparse, re from subprocess import Popen, PIPE from optparse import OptionParser from getpass import getuser +from time import ctime # Display [Comment/Uncomment to Enable/Disable information.] display = [ @@ -111,7 +112,7 @@ def ram_display(): # Screenshot Function screen = '%s' % options.screenshot def screenshot(): - subprocess.check_call(['scrot', '-cd5']) + subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) # Operating System Function def os_display(): -- cgit v1.2.3 From fd80688ee0bf577292221aa7016f57b9b04699a8 Mon Sep 17 00:00:00 2001 From: Laurie Date: Sat, 16 Jan 2010 21:42:30 +0000 Subject: Added basic support for other operating systems, Ubuntu added. --- archey | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 91 insertions(+), 25 deletions(-) diff --git a/archey b/archey index 815aec0..b9be5fc 100644 --- a/archey +++ b/archey @@ -10,12 +10,15 @@ # Along with basic system information. # Import libraries -import subprocess, optparse, re +import subprocess, optparse, re, sys from subprocess import Popen, PIPE from optparse import OptionParser from getpass import getuser from time import ctime +if sys.version_info[1] < 6: + from future import with_statement + # Display [Comment/Uncomment to Enable/Disable information.] display = [ 'os', # Display Operating System @@ -88,6 +91,9 @@ sh_dict = {'zsh': 'Z-Shell', 'jsh': 'Job control shell', 'tcsh': 'The C Shell'} +os_dict = {'arch': 'Arch Linux', + 'ubuntu': 'Ubuntu'} + # Find running processes. def xmonadfix(str): if re.compile("xmonad").match(str): return "xmonad" @@ -96,6 +102,9 @@ 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 +# Architecture +arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') + # Print coloured key with normal value. def output(key, value): output = '%s%s:%s %s' % (color, key, clear, value) @@ -115,10 +124,31 @@ def screenshot(): subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) # 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 os_display(): + global os + for key in os_dict: + if eval('os_' + key)() == True: os = os_dict[key] + output('OS', os + ' ' + arch) + +# Arch finding function +def os_arch(): + try: + file = open('/etc/pacman.conf') + except IOError: + return False + else: + file.close() + return True + +# Ubuntu finding function +def os_ubuntu(): + try: + file = open('/etc/issue.conf') + except IOError: + return False + else: + file.close() + return True # Kernel Function def kernel_display(): @@ -213,27 +243,63 @@ for x in display: # Array containing values. result.extend(['']*(15 - len(display))) +colors = {'Arch Linux': (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), + 'Ubuntu': 'color3, color3, color2, color3, color2, color3, result[0], color, color2, color3, result[1], color, color2, color3, result[2], color, color2, result[3], color, color2, result[4], color, color2, result[5], color, color2, result[6], color2, color, color2, result[7], color2, color, color2, result[8], color2, color, result[9], color2, color, color3, result[10], color2, color, color3, result[11], color, color3, result[12], color, color3, result[13], color, color3, result[14], color, color3, color, color3, color, color, color3, color, color3, color, color3, color, color, color, clear'} + ###### Result ####### -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 """ % (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) +logos = {'Arch Linux': ["%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 "], + 'Ubuntu': [" ", +"%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 "]} + +logo = '' +for line in logos[os]: + logo += line + '\n' + +print logo % colors[os] if screen == 'True': screenshot() -- cgit v1.2.3 From 6bd1163f3c7dc554188112ce28de488219b19364 Mon Sep 17 00:00:00 2001 From: Laurie Date: Sun, 17 Jan 2010 00:28:35 +0000 Subject: Added verification for screenshot --- archey | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/archey b/archey index b9be5fc..6ace22f 100644 --- a/archey +++ b/archey @@ -14,7 +14,7 @@ import subprocess, optparse, re, sys from subprocess import Popen, PIPE from optparse import OptionParser from getpass import getuser -from time import ctime +from time import ctime, sleep if sys.version_info[1] < 6: from future import with_statement @@ -121,7 +121,14 @@ def ram_display(): # Screenshot Function screen = '%s' % options.screenshot def screenshot(): + print 'Screenshotting in' + list = range(1,6) + list.reverse() + for x in list: + print '%s...' % x + sleep(1) subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) + print 'Say Cheeze!' # Operating System Function def os_display(): -- cgit v1.2.3 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 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 From 5b7e1e6427980bb1af3e37f2e34961e0cb7e346e Mon Sep 17 00:00:00 2001 From: Laurie Date: Sun, 17 Jan 2010 23:12:00 +0000 Subject: Added func to find the temprature of the core. Problems: Only does one core, and I havn't tested this realy at all. --- archey | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/archey b/archey index 6ace22f..ea7aaec 100644 --- a/archey +++ b/archey @@ -26,6 +26,7 @@ display = [ 'kernel', # Display Kernel Version # 'battery', # Display Battery Usage [Requires 'acpi'] 'uptime', # Display System Uptime + 'coretemp', # Display System Core tempature 'wm', # Display Window Manager 'de', # Display Desktop Environment 'packages', # Display Number of Packages Installed @@ -128,7 +129,12 @@ def screenshot(): print '%s...' % x sleep(1) subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) - print 'Say Cheeze!' + print 'Say Cheese!' + +# Core Temp Function +def coretemp_display(): + tempinfo = Popen(['sensors', 'coretemp-*'], stdout=PIPE).communicate()[0].split('\n')[2].split(':')[1].replace(' ','').split('(')[0] + output ('Core Temp', tempinfo) # Operating System Function def os_display(): -- cgit v1.2.3 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 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 From deff2be563581ef60f3f71e2ebeffdae543f67f5 Mon Sep 17 00:00:00 2001 From: Laurie Date: Mon, 18 Jan 2010 15:56:06 +0000 Subject: Changed logos to multi line list, should improve memory usage slightly --- archey | 102 +++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/archey b/archey index ea7aaec..1685053 100644 --- a/archey +++ b/archey @@ -260,59 +260,55 @@ colors = {'Arch Linux': (color, color, color, result[0], color, result[1], color 'Ubuntu': 'color3, color3, color2, color3, color2, color3, result[0], color, color2, color3, result[1], color, color2, color3, result[2], color, color2, result[3], color, color2, result[4], color, color2, result[5], color, color2, result[6], color2, color, color2, result[7], color2, color, color2, result[8], color2, color, result[9], color2, color, color3, result[10], color2, color, color3, result[11], color, color3, result[12], color, color3, result[13], color, color3, result[14], color, color3, color, color3, color, color, color3, color, color3, color, color3, color, color, color, clear'} ###### Result ####### -logos = {'Arch Linux': ["%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 "], - 'Ubuntu': [" ", -"%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 "]} - -logo = '' -for line in logos[os]: - logo += line + '\n' - -print logo % colors[os] +logos = {'Arch Linux': ['''%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 '''], + 'Ubuntu': [''' +%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 ''']} + +print logos % colors[os] if screen == 'True': screenshot() -- cgit v1.2.3 From 1158d6ec2fe3b2e3f9da4d4e335f18fb179dccbe Mon Sep 17 00:00:00 2001 From: Laurie Date: Mon, 18 Jan 2010 16:09:58 +0000 Subject: Fixed bug on previous commit, added multi core support for core temp func. TODO: Colour temp outup acording to value --- archey | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/archey b/archey index 1685053..d348974 100644 --- a/archey +++ b/archey @@ -133,8 +133,12 @@ def screenshot(): # Core Temp Function def coretemp_display(): - tempinfo = Popen(['sensors', 'coretemp-*'], stdout=PIPE).communicate()[0].split('\n')[2].split(':')[1].replace(' ','').split('(')[0] - output ('Core Temp', tempinfo) + tempinfo = Popen(['sensors', 'coretemp-*'], stdout=PIPE).communicate()[0].split('\n')[2::4] + temps = '' + for line in tempinfo: + temps = temps + line.split(':')[1].replace(' ','').split('(')[0]+ ',' + temps = temps[:-1] + output ('Core Temp', temps) # Operating System Function def os_display(): @@ -260,7 +264,7 @@ colors = {'Arch Linux': (color, color, color, result[0], color, result[1], color 'Ubuntu': 'color3, color3, color2, color3, color2, color3, result[0], color, color2, color3, result[1], color, color2, color3, result[2], color, color2, result[3], color, color2, result[4], color, color2, result[5], color, color2, result[6], color2, color, color2, result[7], color2, color, color2, result[8], color2, color, result[9], color2, color, color3, result[10], color2, color, color3, result[11], color, color3, result[12], color, color3, result[13], color, color3, result[14], color, color3, color, color3, color, color, color3, color, color3, color, color3, color, color, color, clear'} ###### Result ####### -logos = {'Arch Linux': ['''%s +logos = {'Arch Linux': '''%s %s + %s # %s %s ### %s @@ -279,8 +283,8 @@ logos = {'Arch Linux': ['''%s %s ;#### ####; %s %s ##' '## %s #' `# -%s '''], - 'Ubuntu': [''' +%s ''', + 'Ubuntu': ''' %s ++++++ %s ++++++++ %s ++++++++++ %s++++++++ @@ -306,9 +310,9 @@ logos = {'Arch Linux': ['''%s %s ++++++++++ %s++++++++ %s ++++++++ %s ++++++ -%s ''']} +%s '''} -print logos % colors[os] +print logos[os] % colors[os] if screen == 'True': screenshot() -- cgit v1.2.3 From 9f233527a88e3a8e00d033b42f07f80e6fe6e72f Mon Sep 17 00:00:00 2001 From: Laurie Date: Mon, 18 Jan 2010 16:13:33 +0000 Subject: Added sys.stdout.flush() for screenshot countdown. Saw fix on djmelik's branch. --- archey | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archey b/archey index d348974..ace4e4d 100644 --- a/archey +++ b/archey @@ -126,7 +126,8 @@ def screenshot(): list = range(1,6) list.reverse() for x in list: - print '%s...' % x + print '%s...' % x, + sys.stdout.flush() sleep(1) subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) print 'Say Cheese!' -- cgit v1.2.3 From 6588f23c1064d58ad8699e0fb821614c7ed73586 Mon Sep 17 00:00:00 2001 From: Laurie Date: Wed, 20 Jan 2010 16:49:20 +0000 Subject: Temp output changes color with different tempratures. Also changed os detect support to use lsb method, unless specific function found --- archey | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/archey b/archey index ace4e4d..85a1c52 100644 --- a/archey +++ b/archey @@ -93,7 +93,8 @@ sh_dict = {'zsh': 'Z-Shell', 'tcsh': 'The C Shell'} os_dict = {'arch': 'Arch Linux', - 'ubuntu': 'Ubuntu'} + 'ubuntu': 'Ubuntu', + 'debian': 'Debian'} # Find running processes. def xmonadfix(str): @@ -136,8 +137,17 @@ def screenshot(): def coretemp_display(): tempinfo = Popen(['sensors', 'coretemp-*'], stdout=PIPE).communicate()[0].split('\n')[2::4] temps = '' + orange = '\x1b[1;31m' + red = '\x1b[1;33m' + blue = '\x1b[1;34m' for line in tempinfo: - temps = temps + line.split(':')[1].replace(' ','').split('(')[0]+ ',' + value = line.split(':')[1].replace(' ','').split('(')[0] + if int(value[1:3]) > 40: + temps = temps + red + line.split(':')[1].replace(' ','').split('(')[0] + clear + ',' + elif int(value[1:3]) in range(31,41): + temps = temps + orange + line.split(':')[1].replace(' ','').split('(')[0] + clear + ',' + elif int(value[1:3]) < 30: + temps = temps + blue + line.split(':')[1].replace(' ','').split('(')[0] + clear + ',' temps = temps[:-1] output ('Core Temp', temps) @@ -145,7 +155,10 @@ def coretemp_display(): def os_display(): global os for key in os_dict: - if eval('os_' + key)() == True: os = os_dict[key] + try: + if eval('os_' + key)(): os = os_dict[key] + except NameError: + if os_lsb(key): os = os_dict[key] output('OS', os + ' ' + arch) # Arch finding function @@ -158,10 +171,11 @@ def os_arch(): file.close() return True -# Ubuntu finding function -def os_ubuntu(): +# OS finding using lsb +def os_lsb(key): try: - file = open('/etc/issue.conf') + file = open('/etc/lsb-release') + if not os[key] in file.readlines()[0]: raise IOError except IOError: return False else: -- cgit v1.2.3 From a5843b1173d2ea66e41e13255812e589e6808247 Mon Sep 17 00:00:00 2001 From: Laurie Date: Mon, 25 Jan 2010 21:08:24 +0000 Subject: Added ScrotWM support --- archey | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) mode change 100644 => 100755 archey diff --git a/archey b/archey old mode 100644 new mode 100755 index 85a1c52..c5b340b --- a/archey +++ b/archey @@ -82,7 +82,8 @@ wm_dict = {'awesome': 'Awesome', 'wmaker': 'Window Maker', 'wmii': 'wmii', 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad'} + 'xmonad': 'xmonad', + 'scrotwm': 'ScrotWM'} sh_dict = {'zsh': 'Z-Shell', 'bash': 'Bash', @@ -137,8 +138,8 @@ def screenshot(): def coretemp_display(): tempinfo = Popen(['sensors', 'coretemp-*'], stdout=PIPE).communicate()[0].split('\n')[2::4] temps = '' - orange = '\x1b[1;31m' - red = '\x1b[1;33m' + orange = '\x1b[1;33m' + red = '\x1b[1;31m' blue = '\x1b[1;34m' for line in tempinfo: value = line.split(':')[1].replace(' ','').split('(')[0] -- cgit v1.2.3 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 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 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 From c8a67159ca82d249934a5445adb47f864661fb3f Mon Sep 17 00:00:00 2001 From: Laurie Date: Tue, 26 Jan 2010 07:55:09 +0000 Subject: Removed xfce4 --- archey | 1 - 1 file changed, 1 deletion(-) diff --git a/archey b/archey index c5b340b..fbbfe71 100755 --- a/archey +++ b/archey @@ -62,7 +62,6 @@ 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'} wm_dict = {'awesome': 'Awesome', -- cgit v1.2.3 From a7f776d914e10282ef0bd5644bdb20bbc18a21a5 Mon Sep 17 00:00:00 2001 From: Laurie Date: Tue, 26 Jan 2010 07:57:35 +0000 Subject: Using os.getenv for shell detection --- archey | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/archey b/archey index fbbfe71..2c6673a 100755 --- a/archey +++ b/archey @@ -15,6 +15,7 @@ from subprocess import Popen, PIPE from optparse import OptionParser from getpass import getuser from time import ctime, sleep +from os import getenv if sys.version_info[1] < 6: from future import with_statement @@ -84,14 +85,6 @@ wm_dict = {'awesome': 'Awesome', 'xmonad': 'xmonad', 'scrotwm': 'ScrotWM'} -sh_dict = {'zsh': 'Z-Shell', - 'bash': 'Bash', - 'dash': 'Dash', - 'fish': 'Fish', - 'ksh': 'Korn Shell', - 'jsh': 'Job control shell', - 'tcsh': 'The C Shell'} - os_dict = {'arch': 'Arch Linux', 'ubuntu': 'Ubuntu', 'debian': 'Debian'} @@ -235,11 +228,9 @@ def wm_display(): output ('WM', 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) +def sh_display(): + shell = os.getenv("SHELL")].split('/')[-1] + output ('Shell', shell) # Packages Function def packages_display(): -- cgit v1.2.3 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 From 45df151ac5e6950e91e929f881703be6adf1a4be Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 31 Aug 2010 19:44:48 +0100 Subject: Rewrite of archey to be Object Oriented. --- COPYING | 0 archey | 623 +++++++++++++++++++++++++++++++++++----------------------------- 2 files changed, 340 insertions(+), 283 deletions(-) mode change 100644 => 100755 COPYING diff --git a/COPYING b/COPYING old mode 100644 new mode 100755 diff --git a/archey b/archey index 2c6673a..118652f 100755 --- a/archey +++ b/archey @@ -1,8 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -# archey [version 0.1-7] +# archey [version 0.2-1] # -# Maintained by Melik Manukyan +# Copyright 2010 Melik Manukyan +# Copyright 2010 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. # @@ -17,308 +18,364 @@ from getpass import getuser from time import ctime, sleep from os import getenv -if sys.version_info[1] < 6: - from future import with_statement - # 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 - 'coretemp', # Display System Core tempature - '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 +# Protocals: +# uname:x = return output of uname -x +# sensors:x = return output of sensors x +# env:x = return value of env variable x +# fs:x = return space of partition at x +DISPLAY = [ + 'distro', # Display Operating System + 'uname:n', # Display Machine Hostname + 'uname:r', # Display Kernel Version + #'battery', # Display Battery Usage [Requires 'acpi'] + 'uptime', # Display System Uptime + 'sensors:coretemp-*', # Display System Core tempature + 'wm', # Display Window Manager + 'de', # Display Desktop Environment + 'packages', # Display Number of Packages Installed + 'ram', # Display RAM Usage + 'uname:p', # Display CPU Model + 'env:shell', # Display Current Shell + 'env:editor', # Display Editor, using EDITOR env +# 'PS1', # Display PS1 # '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 = [] + 'fs:/' # Display / Partition Usage + ] + # 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', - 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.') + 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() + +class display(object): + __slots__ = ['command_line', 'arg1', 'arg2', 'arg3', 'stdindata', 'proccess'] + + command_line = '' + arg1 = '' + arg2 = '' + arg3 = '' + stdindata = '' + + 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 + self.proccess = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE) + + def render(self): + (stdoutdata, stderrdata) = self.proccess.communicate(self.stdindata or None) + return self.format_output(stdoutdata.decode()) + + +class fsDisplay(display): + command_line = "df -TPh {arg1}" + + def __init__(self, path='/'): + self.arg1 = path + + def format_output(self, instring): + values = [line for line in instring.split('\n') if line][1].split() + used = values[3] + total = values[2] + fstype = values[1] + + mount = '/root' if self.arg1 == '/' else self.arg1 + title = mount.split('/')[-1].title() + " FS" + part = '{used} / {total} ({fstype})'.format(used=used, total=total, fstype=fstype) + return title, part + +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' + part = '{used} MB / {total} MB'.format(used=used, total=total) + return title, part + +class sensorDisplay(display): + command_line = "sensors {arg1}" + + def __init__(self, sensors="coretemp-*"): + self.arg1 = sensors + + 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("red") + info[1] + color("clear") + elif intvalue in range(30, 45): + temp = color("magenta") + info[1] + color("clear") + else: + temp = color("green") + info[1] + color("clear") + out.append((info[0], temp)) + return out + +class envDisplay(display): + def __init__(self, env='SHELL'): + self.arg1 = env + + def render(self): + argvalue = getenv(self.arg1.upper()) + return (self.arg1.title(), argvalue) + +class unameDisplay(display): + command_line = "uname {arg1}" + + def __init__(self, flag=''): + self.arg1 = '-' + flag if flag else '' + + def format_output(self, instring): + return (UNAME_FLAG_MEANINGS[self.arg1[1]], instring) + +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}'.format( + daystring='{days} day{s}, '.format(days=day, s=int(day) > 1) if day else '', + hours = hour, mins = minute + ) + return "Uptime", uptime + +class packageDisplay(display): + command_line = "pacman -Q" + + def format_output(self, instring): + return "Packages", len(instring.split('\n')) + +class distroCheck(display): + def render(self): + try: + rc = open("/etc/pacman.conf") + except IOError: + distro = render(unameDisplay("o"))[1] + else: + distro = "Arch Linux" + distro = ' '.join([distro, render(unameDisplay('m'))[1]]) + return "OS", distro + +class proccessCheck(display): + __slots__ = display.__slots__ + ['_processes'] + command_line = "ps -u {arg1}" + + render = lambda self: self + + def __init__(self): + self.arg1 = getuser() + + def run_command(self): + super().run_command() + out = str(self.proccess.communicate()[0]) + self._processes = set([line.split()[3] for line in out.split('\\n') if len(line.split()) == 4]) + + def __call__(self, proc): + if proc in self._processes: + return True + return False + +class wmDisplay(display): + def render(self): + wm = '' + for key in WM_DICT.keys(): + if processes(key): + wm = key + break + return "WM", WM_DICT[wm] + +class deDisplay(display): + def render(self): + de = '' + for key in DE_DICT.keys(): + if processes(key): + de = key + break + return "DE", DE_DICT[de] # 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' +def color(code): + if code == 1: + return '\x1b[1;3%sm' % colorcode + elif code == 2: + return '\x1b[0;3%sm' % colorcode + if code == "clear": + return '\x1b[0m' + return '\x1b[0;3%sm' % colors[code] + +FUNC_MAPPINGS = { + 'distro': distroCheck, + 'uname': unameDisplay, + 'uptime': uptimeDisplay, + 'sensors': sensorDisplay, + 'wm': wmDisplay, + 'de': deDisplay, + 'packages': packageDisplay, + 'ram': ramDisplay, + 'env': envDisplay, + 'fs': fsDisplay, +} + +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', +} + # Define processes for identifying Desktop Environmentss, Window Managers, Shells. -de_dict = {'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfconfd': 'Xfce 4.6'} - -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', - 'wmaker': 'Window Maker', - 'wmii': 'wmii', - 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad', - 'scrotwm': 'ScrotWM'} +DE_DICT = {'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfconfd': 'Xfce 4.6', + 'lxsession': 'LXDE', + '': 'None',} + +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', + 'wmaker': 'Window Maker', + 'wmii': 'wmii', + 'xfwm4': 'Xfwm', + 'xmonad': 'xmonad', + 'scrotwm': 'ScrotWM', + '': 'None',} os_dict = {'arch': 'Arch Linux', - 'ubuntu': 'Ubuntu', - 'debian': 'Debian'} + 'ubuntu': 'Ubuntu', + 'debian': 'Debian'} + + +logos = {'Arch Linux': '''{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} ######{c2}#####{c1}##; {results[8]} +{c1} ###{c2}############{c1}+ {results[9]} +{c1} #{c2}###### ####### {results[10]} +{c2} .######; ;###;`\". {results[11]} +{c2} .#######; ;#####. {results[12]} +{c2} #########. .########` {results[13]} +{c2} ######' '###### {results[14]} +{c2} ;#### ####; {results[15]} +{c2} ##' '## {results[16]} +{c2} #' `# {results[17]} +{c2} '''} -# 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 - -# Architecture -arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n') - -# Print coloured key with normal value. -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') - 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])) + if re.compile("xmonad").match(str): return "xmonad" + return str # Screenshot Function screen = '%s' % options.screenshot def screenshot(): - print 'Screenshotting 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(' ','_')+'.jpg']) - print 'Say Cheese!' - -# Core Temp Function -def coretemp_display(): - tempinfo = Popen(['sensors', 'coretemp-*'], stdout=PIPE).communicate()[0].split('\n')[2::4] - temps = '' - orange = '\x1b[1;33m' - red = '\x1b[1;31m' - blue = '\x1b[1;34m' - for line in tempinfo: - value = line.split(':')[1].replace(' ','').split('(')[0] - if int(value[1:3]) > 40: - temps = temps + red + line.split(':')[1].replace(' ','').split('(')[0] + clear + ',' - elif int(value[1:3]) in range(31,41): - temps = temps + orange + line.split(':')[1].replace(' ','').split('(')[0] + clear + ',' - elif int(value[1:3]) < 30: - temps = temps + blue + line.split(':')[1].replace(' ','').split('(')[0] + clear + ',' - temps = temps[:-1] - output ('Core Temp', temps) - -# Operating System Function -def os_display(): - global os - for key in os_dict: - try: - if eval('os_' + key)(): os = os_dict[key] - except NameError: - if os_lsb(key): os = os_dict[key] - output('OS', os + ' ' + arch) - -# Arch finding function -def os_arch(): - try: - file = open('/etc/pacman.conf') - except IOError: - return False - else: - file.close() - return True - -# OS finding using lsb -def os_lsb(key): - try: - file = open('/etc/lsb-release') - if not os[key] in file.readlines()[0]: raise IOError - except IOError: - return False - else: - file.close() - return True - -# Kernel Function -def kernel_display(): - 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) - -# 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) - -# 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' - for key in de_dict.keys(): - if key in processes: de = de_dict[key] - output ('DE', 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) - -# Shell Function -def sh_display(): - shell = os.getenv("SHELL")].split('/')[-1] - output ('Shell', shell) - -# 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) - -# 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) - -# 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() - -# Array containing values. -result.extend(['']*(15 - len(display))) - -colors = {'Arch Linux': (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), - 'Ubuntu': 'color3, color3, color2, color3, color2, color3, result[0], color, color2, color3, result[1], color, color2, color3, result[2], color, color2, result[3], color, color2, result[4], color, color2, result[5], color, color2, result[6], color2, color, color2, result[7], color2, color, color2, result[8], color2, color, result[9], color2, color, color3, result[10], color2, color, color3, result[11], color, color3, result[12], color, color3, result[13], color, color3, result[14], color, color3, color, color3, color, color, color3, color, color3, color, color3, color, color, color, clear'} - -###### Result ####### -logos = {'Arch Linux': '''%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 ''', - 'Ubuntu': ''' -%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 '''} - -print logos[os] % colors[os] - -if screen == 'True': - screenshot() + print('Screenshotting in') + list = list(range(1,6)) + list.reverse() + for x in list: + print('%s...' % x, end=' ') + sys.stdout.flush() + sleep(1) + print('Say Cheese!') + subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) + +def render(instance): + instance.run_command() + return instance.render() + +#create process list +processes = render(proccessCheck()) + +def main(): + outputs = [] + # Run functions found in 'display' array. + for func in DISPLAY: + if len(func.split(':')) > 1: + cls = FUNC_MAPPINGS[func.split(':')[0]] + args = tuple(func.split(':')[1].split(',')) + else: + cls = FUNC_MAPPINGS[func] + args = () + + out = render(cls(*args)) + if isinstance(out, list): + for o in out: + outputs.append(o) + else: + outputs.append(out) + + results = [] + for i in range(18): + if i < len(outputs): + output = outputs[i] + results.append("{color}{title}:{clear} {data}".format( + color=color(1), + title=output[0].rstrip(':'), + data=str(output[1]).rstrip(), + clear=color("clear") + )) + else: + results.append('') + + distro_name = ' '.join(render(distroCheck())[1].split()[:-1]) + print(logos[distro_name].format(c1=color(1), c2=color(2), results = results)) + + if screen == 'True': + screenshot() + +main() \ No newline at end of file -- cgit v1.2.3 From c9fba8a885cc2cd11ee14a3a3af6225dabd36e24 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 31 Aug 2010 21:08:43 +0100 Subject: Added -d command line option to allow users to customize displayed info --- archey | 357 ++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 199 insertions(+), 158 deletions(-) diff --git a/archey b/archey index 118652f..54f0e7c 100755 --- a/archey +++ b/archey @@ -19,16 +19,16 @@ from time import ctime, sleep from os import getenv # Display [Comment/Uncomment to Enable/Disable information.] -# Protocals: -# uname:x = return output of uname -x +# Protocols: +# uname:x = return output of uname -x (see UNAME_FLAG_MEANINGS for more info) # sensors:x = return output of sensors x # env:x = return value of env variable x # fs:x = return space of partition at x + DISPLAY = [ 'distro', # Display Operating System 'uname:n', # Display Machine Hostname 'uname:r', # Display Kernel Version - #'battery', # Display Battery Usage [Requires 'acpi'] 'uptime', # Display System Uptime 'sensors:coretemp-*', # Display System Core tempature 'wm', # Display Window Manager @@ -38,25 +38,101 @@ DISPLAY = [ 'uname:p', # Display CPU Model 'env:shell', # Display Current Shell 'env:editor', # Display Editor, using EDITOR env -# 'PS1', # Display PS1 # '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 ] +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 = {'Arch Linux': '''{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} ######{c2}#####{c1}##; {results[8]} +{c1} ###{c2}############{c1}+ {results[9]} +{c1} #{c2}###### ####### {results[10]} +{c2} .######; ;###;`\". {results[11]} +{c2} .#######; ;#####. {results[12]} +{c2} #########. .########` {results[13]} +{c2} ######' '###### {results[14]} +{c2} ;#### ####; {results[15]} +{c2} ##' '## {results[16]} +{c2} #' `# {results[17]} +{c2} ''' +} + +FUNC_MAPPINGS = { + 'distro': 'distroCheck', + 'uname': 'unameDisplay', + 'uptime': 'uptimeDisplay', + 'sensors': 'sensorDisplay', + 'wm': 'wmDisplay', + 'de': 'deDisplay', + 'packages': 'packageDisplay', + 'ram': 'ramDisplay', + 'env': 'envDisplay', + 'fs': 'fsDisplay', +} + + +DE_DICT = {'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfconfd': 'Xfce 4.6', + 'lxsession': 'LXDE', + '': 'None', +} + +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', + 'wmaker': 'Window Maker', + 'wmii': 'wmii', + 'xfwm4': 'Xfwm', + 'xmonad': 'xmonad', + 'scrotwm': 'ScrotWM', + '': 'None', +} -# 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', - 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() +COLORS = { + 'black': '0', + 'red': '1', + 'green': '2', + 'yellow': '3', + 'blue': '4', + 'magenta': '5', + 'cyan': '6', + 'white': '7' +} class display(object): - __slots__ = ['command_line', 'arg1', 'arg2', 'arg3', 'stdindata', 'proccess'] + __slots__ = ['command_line', 'arg1', 'arg2', 'arg3', 'stdindata', 'proccess', '_parent'] command_line = '' arg1 = '' @@ -64,6 +140,9 @@ class display(object): arg3 = '' stdindata = '' + def __init__(self, parent=None): + self._parent = parent + def run_command(self): if self.command_line: if '{arg3}' in self.command_line: @@ -84,8 +163,9 @@ class display(object): class fsDisplay(display): command_line = "df -TPh {arg1}" - def __init__(self, path='/'): + def __init__(self, path='/', parent=None): self.arg1 = path + self._parent = parent def format_output(self, instring): values = [line for line in instring.split('\n') if line][1].split() @@ -112,8 +192,9 @@ class ramDisplay(display): class sensorDisplay(display): command_line = "sensors {arg1}" - def __init__(self, sensors="coretemp-*"): + def __init__(self, sensors="coretemp-*", parent=None): self.arg1 = sensors + self._parent = parent def format_output(self, instring): tempinfo = instring.split('\n')[2::4] @@ -124,27 +205,29 @@ class sensorDisplay(display): value = info[1] intvalue = int(value[:3]) if intvalue > 45: - temp = color("red") + info[1] + color("clear") + temp = self._parent.color("red") + info[1] + self._parent.color("clear") elif intvalue in range(30, 45): - temp = color("magenta") + info[1] + color("clear") + temp = self._parent.color("magenta") + info[1] + self._parent.color("clear") else: - temp = color("green") + info[1] + color("clear") + temp = self._parent.color("green") + info[1] + self._parent.color("clear") out.append((info[0], temp)) return out class envDisplay(display): - def __init__(self, env='SHELL'): + def __init__(self, env='SHELL', parent=None): self.arg1 = env + self._parent = parent def render(self): argvalue = getenv(self.arg1.upper()) - return (self.arg1.title(), argvalue) + return ('$' + self.arg1.upper(), argvalue) class unameDisplay(display): command_line = "uname {arg1}" - def __init__(self, flag=''): + def __init__(self, flag=False, parent=None): self.arg1 = '-' + flag if flag else '' + self._parent = parent def format_output(self, instring): return (UNAME_FLAG_MEANINGS[self.arg1[1]], instring) @@ -189,8 +272,9 @@ class proccessCheck(display): render = lambda self: self - def __init__(self): + def __init__(self, parent=None): self.arg1 = getuser() + self._parent = parent def run_command(self): super().run_command() @@ -220,109 +304,6 @@ class deDisplay(display): break return "DE", DE_DICT[de] -# 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 = '\x1b[0m' - -def color(code): - if code == 1: - return '\x1b[1;3%sm' % colorcode - elif code == 2: - return '\x1b[0;3%sm' % colorcode - if code == "clear": - return '\x1b[0m' - return '\x1b[0;3%sm' % colors[code] - -FUNC_MAPPINGS = { - 'distro': distroCheck, - 'uname': unameDisplay, - 'uptime': uptimeDisplay, - 'sensors': sensorDisplay, - 'wm': wmDisplay, - 'de': deDisplay, - 'packages': packageDisplay, - 'ram': ramDisplay, - 'env': envDisplay, - 'fs': fsDisplay, -} - -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', -} - -# Define processes for identifying Desktop Environmentss, Window Managers, Shells. -DE_DICT = {'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfconfd': 'Xfce 4.6', - 'lxsession': 'LXDE', - '': 'None',} - -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', - 'wmaker': 'Window Maker', - 'wmii': 'wmii', - 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad', - 'scrotwm': 'ScrotWM', - '': 'None',} - -os_dict = {'arch': 'Arch Linux', - 'ubuntu': 'Ubuntu', - 'debian': 'Debian'} - - -logos = {'Arch Linux': '''{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} ######{c2}#####{c1}##; {results[8]} -{c1} ###{c2}############{c1}+ {results[9]} -{c1} #{c2}###### ####### {results[10]} -{c2} .######; ;###;`\". {results[11]} -{c2} .#######; ;#####. {results[12]} -{c2} #########. .########` {results[13]} -{c2} ######' '###### {results[14]} -{c2} ;#### ####; {results[15]} -{c2} ##' '## {results[16]} -{c2} #' `# {results[17]} -{c2} '''} - -def xmonadfix(str): - if re.compile("xmonad").match(str): return "xmonad" - return str - -# Screenshot Function -screen = '%s' % options.screenshot def screenshot(): print('Screenshotting in') list = list(range(1,6)) @@ -339,43 +320,103 @@ def render(instance): return instance.render() #create process list -processes = render(proccessCheck()) -def main(): - outputs = [] - # Run functions found in 'display' array. - for func in DISPLAY: - if len(func.split(':')) > 1: - cls = FUNC_MAPPINGS[func.split(':')[0]] - args = tuple(func.split(':')[1].split(',')) - else: - cls = FUNC_MAPPINGS[func] - args = () +class Archey(object): + def __init__(self, display=None, colorscheme='blue'): + self.display = display or [] + for key in COLORS.keys(): + if key == colorscheme: + self.colorcode = COLORS[key] - out = render(cls(*args)) - if isinstance(out, list): - for o in out: - outputs.append(o) - else: - outputs.append(out) + self.distro_name = ' '.join(render(distroCheck())[1].split()[:-1]) - results = [] - for i in range(18): - if i < len(outputs): - output = outputs[i] - results.append("{color}{title}:{clear} {data}".format( - color=color(1), - title=output[0].rstrip(':'), - data=str(output[1]).rstrip(), - clear=color("clear") - )) - else: - results.append('') + def render(self): + results = self.prepare_results() + + print(LOGOS[self.distro_name].format(c1=self.color(1), + c2=self.color(2), + results = results + )) + + def prepare_results(self): + outputs = [] + # Run functions found in 'display' array. + for func in self.display: + if len(func.split(':')) > 1: + cls = eval(FUNC_MAPPINGS[func.split(':')[0]]) + args = tuple(func.split(':')[1].split(',')) + else: + cls = eval(FUNC_MAPPINGS[func]) + args = () + + out = render(cls(*args, parent=self)) + if isinstance(out, list): + for o in out: + outputs.append(o) + else: + outputs.append(out) + + for i in range(18): + if i < len(outputs): + outputs[i] = self.format_item(outputs[i]) + else: + outputs.append('') + + return outputs + + def format_item(self, item): + return "{color}{title}:{clear} {data}".format( + color=self.color(1), + title=item[0].rstrip(':'), + data=str(item[1]).rstrip(), + clear=self.color("clear") + ) + + def color(self, code): + if code == 1: + return '\x1b[1;3%sm' % self.colorcode + elif code == 2: + return '\x1b[0;3%sm' % self.colorcode + if code == "clear": + return '\x1b[0m' + return '\x1b[0;3%sm' % COLORS[code] + + +def main(): + global processes + processes = render(proccessCheck()) + + parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot] [-d, --display]', + description="""Archey is a utility to take """, + 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', + action='store_true', dest='screenshot', help='Take a screenshot') + parser.add_option('-d', '--display', + action='store', dest='display', help='Define info to be displayed by archey. DISPLAY must be in the \ +format "archey_display_module:arg1,arg2,arg3.second_display_module". Availible display modules are uname, fs, env, \ +uptime, sensors, ram, de and wm. See the DISPLAY list in the archey source file for more info.') + (options, args) = parser.parse_args() + + if options.display: + global DISPLAY + DISPLAY = options.display.split('.') - distro_name = ' '.join(render(distroCheck())[1].split()[:-1]) - print(logos[distro_name].format(c1=color(1), c2=color(2), results = results)) + archey = Archey(display=DISPLAY, colorscheme=options.color) + archey.render() - if screen == 'True': + if options.screenshot: screenshot() -main() \ No newline at end of file +if __name__ == "__main__": + main() \ No newline at end of file -- cgit v1.2.3 From b4715eb43a53c7a89b69d78515cbe6f5d2dd3247 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 31 Aug 2010 21:10:42 +0100 Subject: Call the program archey3 to indicate that we're using python3, and that we've moved on from old archey --- archey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey b/archey index 54f0e7c..0c199ae 100755 --- a/archey +++ b/archey @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# archey [version 0.2-1] +# archey3 [version 0.2-1] # # Copyright 2010 Melik Manukyan # Copyright 2010 Laurie Clark-Michalek -- cgit v1.2.3 From 6f0c4d3863085fdf3740bdc67d61f163e27bed2d Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 31 Aug 2010 21:11:17 +0100 Subject: And move the file accordingly --- archey | 422 ---------------------------------------------------------------- archey3 | 422 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 422 insertions(+), 422 deletions(-) delete mode 100755 archey create mode 100755 archey3 diff --git a/archey b/archey deleted file mode 100755 index 0c199ae..0000000 --- a/archey +++ /dev/null @@ -1,422 +0,0 @@ -#!/usr/bin/env python3 -# -# archey3 [version 0.2-1] -# -# Copyright 2010 Melik Manukyan -# Copyright 2010 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 subprocess, optparse, re, sys -from subprocess import Popen, PIPE -from optparse import OptionParser -from getpass import getuser -from time import ctime, sleep -from os import getenv - -# Display [Comment/Uncomment to Enable/Disable information.] -# Protocols: -# uname:x = return output of uname -x (see UNAME_FLAG_MEANINGS for more info) -# sensors:x = return output of sensors x -# env:x = return value of env variable x -# fs:x = return space of partition at x - -DISPLAY = [ - 'distro', # Display Operating System - 'uname:n', # Display Machine Hostname - 'uname:r', # Display Kernel Version - 'uptime', # Display System Uptime - 'sensors:coretemp-*', # Display System Core tempature - 'wm', # Display Window Manager - 'de', # Display Desktop Environment - 'packages', # Display Number of Packages Installed - 'ram', # Display RAM Usage - 'uname:p', # Display CPU Model - 'env:shell', # Display Current Shell - 'env:editor', # Display Editor, using EDITOR env -# '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 - ] - -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 = {'Arch Linux': '''{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} ######{c2}#####{c1}##; {results[8]} -{c1} ###{c2}############{c1}+ {results[9]} -{c1} #{c2}###### ####### {results[10]} -{c2} .######; ;###;`\". {results[11]} -{c2} .#######; ;#####. {results[12]} -{c2} #########. .########` {results[13]} -{c2} ######' '###### {results[14]} -{c2} ;#### ####; {results[15]} -{c2} ##' '## {results[16]} -{c2} #' `# {results[17]} -{c2} ''' -} - -FUNC_MAPPINGS = { - 'distro': 'distroCheck', - 'uname': 'unameDisplay', - 'uptime': 'uptimeDisplay', - 'sensors': 'sensorDisplay', - 'wm': 'wmDisplay', - 'de': 'deDisplay', - 'packages': 'packageDisplay', - 'ram': 'ramDisplay', - 'env': 'envDisplay', - 'fs': 'fsDisplay', -} - - -DE_DICT = {'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfconfd': 'Xfce 4.6', - 'lxsession': 'LXDE', - '': 'None', -} - -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', - 'wmaker': 'Window Maker', - 'wmii': 'wmii', - 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad', - 'scrotwm': 'ScrotWM', - '': 'None', -} - -COLORS = { - 'black': '0', - 'red': '1', - 'green': '2', - 'yellow': '3', - 'blue': '4', - 'magenta': '5', - 'cyan': '6', - 'white': '7' -} - -class display(object): - __slots__ = ['command_line', 'arg1', 'arg2', 'arg3', 'stdindata', 'proccess', '_parent'] - - command_line = '' - arg1 = '' - arg2 = '' - arg3 = '' - stdindata = '' - - def __init__(self, parent=None): - self._parent = parent - - 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 - self.proccess = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE) - - def render(self): - (stdoutdata, stderrdata) = self.proccess.communicate(self.stdindata or None) - return self.format_output(stdoutdata.decode()) - - -class fsDisplay(display): - command_line = "df -TPh {arg1}" - - def __init__(self, path='/', parent=None): - self.arg1 = path - self._parent = parent - - def format_output(self, instring): - values = [line for line in instring.split('\n') if line][1].split() - used = values[3] - total = values[2] - fstype = values[1] - - mount = '/root' if self.arg1 == '/' else self.arg1 - title = mount.split('/')[-1].title() + " FS" - part = '{used} / {total} ({fstype})'.format(used=used, total=total, fstype=fstype) - return title, part - -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' - part = '{used} MB / {total} MB'.format(used=used, total=total) - return title, part - -class sensorDisplay(display): - command_line = "sensors {arg1}" - - def __init__(self, sensors="coretemp-*", parent=None): - self.arg1 = sensors - self._parent = parent - - 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 = self._parent.color("red") + info[1] + self._parent.color("clear") - elif intvalue in range(30, 45): - temp = self._parent.color("magenta") + info[1] + self._parent.color("clear") - else: - temp = self._parent.color("green") + info[1] + self._parent.color("clear") - out.append((info[0], temp)) - return out - -class envDisplay(display): - def __init__(self, env='SHELL', parent=None): - self.arg1 = env - self._parent = parent - - def render(self): - argvalue = getenv(self.arg1.upper()) - return ('$' + self.arg1.upper(), argvalue) - -class unameDisplay(display): - command_line = "uname {arg1}" - - def __init__(self, flag=False, parent=None): - self.arg1 = '-' + flag if flag else '' - self._parent = parent - - def format_output(self, instring): - return (UNAME_FLAG_MEANINGS[self.arg1[1]], instring) - -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}'.format( - daystring='{days} day{s}, '.format(days=day, s=int(day) > 1) if day else '', - hours = hour, mins = minute - ) - return "Uptime", uptime - -class packageDisplay(display): - command_line = "pacman -Q" - - def format_output(self, instring): - return "Packages", len(instring.split('\n')) - -class distroCheck(display): - def render(self): - try: - rc = open("/etc/pacman.conf") - except IOError: - distro = render(unameDisplay("o"))[1] - else: - distro = "Arch Linux" - distro = ' '.join([distro, render(unameDisplay('m'))[1]]) - return "OS", distro - -class proccessCheck(display): - __slots__ = display.__slots__ + ['_processes'] - command_line = "ps -u {arg1}" - - render = lambda self: self - - def __init__(self, parent=None): - self.arg1 = getuser() - self._parent = parent - - def run_command(self): - super().run_command() - out = str(self.proccess.communicate()[0]) - self._processes = set([line.split()[3] for line in out.split('\\n') if len(line.split()) == 4]) - - def __call__(self, proc): - if proc in self._processes: - return True - return False - -class wmDisplay(display): - def render(self): - wm = '' - for key in WM_DICT.keys(): - if processes(key): - wm = key - break - return "WM", WM_DICT[wm] - -class deDisplay(display): - def render(self): - de = '' - for key in DE_DICT.keys(): - if processes(key): - de = key - break - return "DE", DE_DICT[de] - -def screenshot(): - print('Screenshotting in') - list = list(range(1,6)) - list.reverse() - for x in list: - print('%s...' % x, end=' ') - sys.stdout.flush() - sleep(1) - print('Say Cheese!') - subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) - -def render(instance): - instance.run_command() - return instance.render() - -#create process list - -class Archey(object): - def __init__(self, display=None, colorscheme='blue'): - self.display = display or [] - for key in COLORS.keys(): - if key == colorscheme: - self.colorcode = COLORS[key] - - self.distro_name = ' '.join(render(distroCheck())[1].split()[:-1]) - - def render(self): - results = self.prepare_results() - - print(LOGOS[self.distro_name].format(c1=self.color(1), - c2=self.color(2), - results = results - )) - - def prepare_results(self): - outputs = [] - # Run functions found in 'display' array. - for func in self.display: - if len(func.split(':')) > 1: - cls = eval(FUNC_MAPPINGS[func.split(':')[0]]) - args = tuple(func.split(':')[1].split(',')) - else: - cls = eval(FUNC_MAPPINGS[func]) - args = () - - out = render(cls(*args, parent=self)) - if isinstance(out, list): - for o in out: - outputs.append(o) - else: - outputs.append(out) - - for i in range(18): - if i < len(outputs): - outputs[i] = self.format_item(outputs[i]) - else: - outputs.append('') - - return outputs - - def format_item(self, item): - return "{color}{title}:{clear} {data}".format( - color=self.color(1), - title=item[0].rstrip(':'), - data=str(item[1]).rstrip(), - clear=self.color("clear") - ) - - def color(self, code): - if code == 1: - return '\x1b[1;3%sm' % self.colorcode - elif code == 2: - return '\x1b[0;3%sm' % self.colorcode - if code == "clear": - return '\x1b[0m' - return '\x1b[0;3%sm' % COLORS[code] - - -def main(): - global processes - processes = render(proccessCheck()) - - parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot] [-d, --display]', - description="""Archey is a utility to take """, - 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', - action='store_true', dest='screenshot', help='Take a screenshot') - parser.add_option('-d', '--display', - action='store', dest='display', help='Define info to be displayed by archey. DISPLAY must be in the \ -format "archey_display_module:arg1,arg2,arg3.second_display_module". Availible display modules are uname, fs, env, \ -uptime, sensors, ram, de and wm. See the DISPLAY list in the archey source file for more info.') - (options, args) = parser.parse_args() - - if options.display: - global DISPLAY - DISPLAY = options.display.split('.') - - archey = Archey(display=DISPLAY, colorscheme=options.color) - archey.render() - - if options.screenshot: - screenshot() - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/archey3 b/archey3 new file mode 100755 index 0000000..0c199ae --- /dev/null +++ b/archey3 @@ -0,0 +1,422 @@ +#!/usr/bin/env python3 +# +# archey3 [version 0.2-1] +# +# Copyright 2010 Melik Manukyan +# Copyright 2010 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 subprocess, optparse, re, sys +from subprocess import Popen, PIPE +from optparse import OptionParser +from getpass import getuser +from time import ctime, sleep +from os import getenv + +# Display [Comment/Uncomment to Enable/Disable information.] +# Protocols: +# uname:x = return output of uname -x (see UNAME_FLAG_MEANINGS for more info) +# sensors:x = return output of sensors x +# env:x = return value of env variable x +# fs:x = return space of partition at x + +DISPLAY = [ + 'distro', # Display Operating System + 'uname:n', # Display Machine Hostname + 'uname:r', # Display Kernel Version + 'uptime', # Display System Uptime + 'sensors:coretemp-*', # Display System Core tempature + 'wm', # Display Window Manager + 'de', # Display Desktop Environment + 'packages', # Display Number of Packages Installed + 'ram', # Display RAM Usage + 'uname:p', # Display CPU Model + 'env:shell', # Display Current Shell + 'env:editor', # Display Editor, using EDITOR env +# '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 + ] + +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 = {'Arch Linux': '''{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} ######{c2}#####{c1}##; {results[8]} +{c1} ###{c2}############{c1}+ {results[9]} +{c1} #{c2}###### ####### {results[10]} +{c2} .######; ;###;`\". {results[11]} +{c2} .#######; ;#####. {results[12]} +{c2} #########. .########` {results[13]} +{c2} ######' '###### {results[14]} +{c2} ;#### ####; {results[15]} +{c2} ##' '## {results[16]} +{c2} #' `# {results[17]} +{c2} ''' +} + +FUNC_MAPPINGS = { + 'distro': 'distroCheck', + 'uname': 'unameDisplay', + 'uptime': 'uptimeDisplay', + 'sensors': 'sensorDisplay', + 'wm': 'wmDisplay', + 'de': 'deDisplay', + 'packages': 'packageDisplay', + 'ram': 'ramDisplay', + 'env': 'envDisplay', + 'fs': 'fsDisplay', +} + + +DE_DICT = {'gnome-session': 'GNOME', + 'ksmserver': 'KDE', + 'xfconfd': 'Xfce 4.6', + 'lxsession': 'LXDE', + '': 'None', +} + +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', + 'wmaker': 'Window Maker', + 'wmii': 'wmii', + 'xfwm4': 'Xfwm', + 'xmonad': 'xmonad', + 'scrotwm': 'ScrotWM', + '': 'None', +} + +COLORS = { + 'black': '0', + 'red': '1', + 'green': '2', + 'yellow': '3', + 'blue': '4', + 'magenta': '5', + 'cyan': '6', + 'white': '7' +} + +class display(object): + __slots__ = ['command_line', 'arg1', 'arg2', 'arg3', 'stdindata', 'proccess', '_parent'] + + command_line = '' + arg1 = '' + arg2 = '' + arg3 = '' + stdindata = '' + + def __init__(self, parent=None): + self._parent = parent + + 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 + self.proccess = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE) + + def render(self): + (stdoutdata, stderrdata) = self.proccess.communicate(self.stdindata or None) + return self.format_output(stdoutdata.decode()) + + +class fsDisplay(display): + command_line = "df -TPh {arg1}" + + def __init__(self, path='/', parent=None): + self.arg1 = path + self._parent = parent + + def format_output(self, instring): + values = [line for line in instring.split('\n') if line][1].split() + used = values[3] + total = values[2] + fstype = values[1] + + mount = '/root' if self.arg1 == '/' else self.arg1 + title = mount.split('/')[-1].title() + " FS" + part = '{used} / {total} ({fstype})'.format(used=used, total=total, fstype=fstype) + return title, part + +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' + part = '{used} MB / {total} MB'.format(used=used, total=total) + return title, part + +class sensorDisplay(display): + command_line = "sensors {arg1}" + + def __init__(self, sensors="coretemp-*", parent=None): + self.arg1 = sensors + self._parent = parent + + 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 = self._parent.color("red") + info[1] + self._parent.color("clear") + elif intvalue in range(30, 45): + temp = self._parent.color("magenta") + info[1] + self._parent.color("clear") + else: + temp = self._parent.color("green") + info[1] + self._parent.color("clear") + out.append((info[0], temp)) + return out + +class envDisplay(display): + def __init__(self, env='SHELL', parent=None): + self.arg1 = env + self._parent = parent + + def render(self): + argvalue = getenv(self.arg1.upper()) + return ('$' + self.arg1.upper(), argvalue) + +class unameDisplay(display): + command_line = "uname {arg1}" + + def __init__(self, flag=False, parent=None): + self.arg1 = '-' + flag if flag else '' + self._parent = parent + + def format_output(self, instring): + return (UNAME_FLAG_MEANINGS[self.arg1[1]], instring) + +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}'.format( + daystring='{days} day{s}, '.format(days=day, s=int(day) > 1) if day else '', + hours = hour, mins = minute + ) + return "Uptime", uptime + +class packageDisplay(display): + command_line = "pacman -Q" + + def format_output(self, instring): + return "Packages", len(instring.split('\n')) + +class distroCheck(display): + def render(self): + try: + rc = open("/etc/pacman.conf") + except IOError: + distro = render(unameDisplay("o"))[1] + else: + distro = "Arch Linux" + distro = ' '.join([distro, render(unameDisplay('m'))[1]]) + return "OS", distro + +class proccessCheck(display): + __slots__ = display.__slots__ + ['_processes'] + command_line = "ps -u {arg1}" + + render = lambda self: self + + def __init__(self, parent=None): + self.arg1 = getuser() + self._parent = parent + + def run_command(self): + super().run_command() + out = str(self.proccess.communicate()[0]) + self._processes = set([line.split()[3] for line in out.split('\\n') if len(line.split()) == 4]) + + def __call__(self, proc): + if proc in self._processes: + return True + return False + +class wmDisplay(display): + def render(self): + wm = '' + for key in WM_DICT.keys(): + if processes(key): + wm = key + break + return "WM", WM_DICT[wm] + +class deDisplay(display): + def render(self): + de = '' + for key in DE_DICT.keys(): + if processes(key): + de = key + break + return "DE", DE_DICT[de] + +def screenshot(): + print('Screenshotting in') + list = list(range(1,6)) + list.reverse() + for x in list: + print('%s...' % x, end=' ') + sys.stdout.flush() + sleep(1) + print('Say Cheese!') + subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) + +def render(instance): + instance.run_command() + return instance.render() + +#create process list + +class Archey(object): + def __init__(self, display=None, colorscheme='blue'): + self.display = display or [] + for key in COLORS.keys(): + if key == colorscheme: + self.colorcode = COLORS[key] + + self.distro_name = ' '.join(render(distroCheck())[1].split()[:-1]) + + def render(self): + results = self.prepare_results() + + print(LOGOS[self.distro_name].format(c1=self.color(1), + c2=self.color(2), + results = results + )) + + def prepare_results(self): + outputs = [] + # Run functions found in 'display' array. + for func in self.display: + if len(func.split(':')) > 1: + cls = eval(FUNC_MAPPINGS[func.split(':')[0]]) + args = tuple(func.split(':')[1].split(',')) + else: + cls = eval(FUNC_MAPPINGS[func]) + args = () + + out = render(cls(*args, parent=self)) + if isinstance(out, list): + for o in out: + outputs.append(o) + else: + outputs.append(out) + + for i in range(18): + if i < len(outputs): + outputs[i] = self.format_item(outputs[i]) + else: + outputs.append('') + + return outputs + + def format_item(self, item): + return "{color}{title}:{clear} {data}".format( + color=self.color(1), + title=item[0].rstrip(':'), + data=str(item[1]).rstrip(), + clear=self.color("clear") + ) + + def color(self, code): + if code == 1: + return '\x1b[1;3%sm' % self.colorcode + elif code == 2: + return '\x1b[0;3%sm' % self.colorcode + if code == "clear": + return '\x1b[0m' + return '\x1b[0;3%sm' % COLORS[code] + + +def main(): + global processes + processes = render(proccessCheck()) + + parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot] [-d, --display]', + description="""Archey is a utility to take """, + 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', + action='store_true', dest='screenshot', help='Take a screenshot') + parser.add_option('-d', '--display', + action='store', dest='display', help='Define info to be displayed by archey. DISPLAY must be in the \ +format "archey_display_module:arg1,arg2,arg3.second_display_module". Availible display modules are uname, fs, env, \ +uptime, sensors, ram, de and wm. See the DISPLAY list in the archey source file for more info.') + (options, args) = parser.parse_args() + + if options.display: + global DISPLAY + DISPLAY = options.display.split('.') + + archey = Archey(display=DISPLAY, colorscheme=options.color) + archey.render() + + if options.screenshot: + screenshot() + +if __name__ == "__main__": + main() \ No newline at end of file -- cgit v1.2.3 From 8821b7d0f443d0c11632e92b4a5ac80064a33fd1 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 31 Aug 2010 21:28:10 +0100 Subject: Fix indentation of {wm,de} dicts, and added a few more wm's --- archey3 | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/archey3 b/archey3 index 0c199ae..7b4c497 100755 --- a/archey3 +++ b/archey3 @@ -92,32 +92,36 @@ FUNC_MAPPINGS = { DE_DICT = {'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfconfd': 'Xfce 4.6', - 'lxsession': 'LXDE', - '': 'None', + 'ksmserver': 'KDE', + 'xfconfd': 'Xfce 4.6', + 'lxsession': 'LXDE', + '': 'None', } -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', - 'wmaker': 'Window Maker', - 'wmii': 'wmii', - 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad', - 'scrotwm': 'ScrotWM', - '': 'None', +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' + '': 'None', } COLORS = { -- cgit v1.2.3 From 90134a0a631cef450549241b323814211ec46a9e Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 1 Sep 2010 14:56:43 +0100 Subject: Damn thoes pesky commas: fixed syntax error (how on earth did I not notice that?? --- archey3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archey3 b/archey3 index 7b4c497..1a2653e 100755 --- a/archey3 +++ b/archey3 @@ -120,7 +120,7 @@ WM_DICT = { 'wmfs': 'Wmfs', 'wmii': 'wmii', 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad' + 'xmonad': 'xmonad', '': 'None', } @@ -423,4 +423,4 @@ uptime, sensors, ram, de and wm. See the DISPLAY list in the archey source file screenshot() if __name__ == "__main__": - main() \ No newline at end of file + main() -- cgit v1.2.3 From 92e670bae57dc7b339bd0fc815cf6f57af943386 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 1 Sep 2010 18:22:02 +0100 Subject: Added mpd display module --- archey3 | 100 ++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 27 deletions(-) diff --git a/archey3 b/archey3 index 1a2653e..b7b55f2 100755 --- a/archey3 +++ b/archey3 @@ -10,6 +10,35 @@ # Simple python script to display an Archlinux logo in ASCII art # Along with basic system information. +# Display [Comment/Uncomment to Enable/Disable information.] +# Protocols: +# uname:x = return output of `uname -x` (see UNAME_FLAG_MEANINGS for more info) +# sensors:x = return output of `sensors x` +# env:x = return value of env variable x +# fs:x = return space of partition at x +# mpd:stat,hostname,port = returns value of an mpd stat (options: artists|albums|songs) + +DISPLAY = [ + 'distro', # Display Operating System + 'uname:n', # Display Machine Hostname + 'uname:r', # Display Kernel Version + 'uptime', # Display System Uptime + 'sensors:coretemp-*', # Display System Core tempature + 'wm', # Display Window Manager + 'de', # Display Desktop Environment + 'packages', # Display Number of Packages Installed + 'ram', # Display RAM Usage + 'uname:p', # Display CPU Model + 'env:shell', # Display Current Shell + 'env:editor', # Display Editor, using EDITOR env + 'mpd:songs' +# '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 +] + + # Import libraries import subprocess, optparse, re, sys from subprocess import Popen, PIPE @@ -18,32 +47,6 @@ from getpass import getuser from time import ctime, sleep from os import getenv -# Display [Comment/Uncomment to Enable/Disable information.] -# Protocols: -# uname:x = return output of uname -x (see UNAME_FLAG_MEANINGS for more info) -# sensors:x = return output of sensors x -# env:x = return value of env variable x -# fs:x = return space of partition at x - -DISPLAY = [ - 'distro', # Display Operating System - 'uname:n', # Display Machine Hostname - 'uname:r', # Display Kernel Version - 'uptime', # Display System Uptime - 'sensors:coretemp-*', # Display System Core tempature - 'wm', # Display Window Manager - 'de', # Display Desktop Environment - 'packages', # Display Number of Packages Installed - 'ram', # Display RAM Usage - 'uname:p', # Display CPU Model - 'env:shell', # Display Current Shell - 'env:editor', # Display Editor, using EDITOR env -# '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 - ] - UNAME_FLAG_MEANINGS = { 'a': 'System Infomation', 's': 'Kernel Name', @@ -88,6 +91,7 @@ FUNC_MAPPINGS = { 'ram': 'ramDisplay', 'env': 'envDisplay', 'fs': 'fsDisplay', + 'mpd': 'mpdDisplay', } @@ -308,6 +312,48 @@ class deDisplay(display): break return "DE", DE_DICT[de] +class mpdDisplay(display): + command_line = "mpc stats" + + def __init__(self, stat='songs', hostname='localhost', port='6600', parent=None): + self.stat = stat + self.hostname = hostname + self.port = port + self._parent = parent + try: + global mpd + import mpd + self.method = 'module' + except ImportError: + self.method = 'shell' + + def run_command(self): + if self.method == 'module': + self.proccess = mpd.MPDClient() + self.proccess.connect(self.hostname, self.port) + else: + super().run_command() + + def render(self): + if self.method == 'module': + try: + return 'MPD {statname}'.format(statname=self.stat.title()), self.proccess.stats()[self.stat] + except Exception: + return 'MPD {statname}'.format(statname=self.stat.title()), 'Error encountered' + else: + super().render() + + def format_output(self, instring): + lines = instring.split('\n') + stats = {} + stats['artists'] = lines[0].split(':')[1].strip() + stats['albums'] = lines[1].split(':')[1].strip() + stats['songs'] = lines[2].split(':')[1].strip() + + return '{statname} in MPD database'.format(statname=self.stat.title()), stats[self.stat] + +#------------ Functions ----------- + def screenshot(): print('Screenshotting in') list = list(range(1,6)) @@ -323,7 +369,7 @@ def render(instance): instance.run_command() return instance.render() -#create process list +#------------ Display object --------- class Archey(object): def __init__(self, display=None, colorscheme='blue'): -- cgit v1.2.3 From 93d6cfad638fdc3a59c67a723ab584b0f3d59cc2 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 1 Sep 2010 18:40:23 +0100 Subject: Fix missing comma in DISPLAY var --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index b7b55f2..15985d2 100755 --- a/archey3 +++ b/archey3 @@ -31,7 +31,7 @@ DISPLAY = [ 'uname:p', # Display CPU Model 'env:shell', # Display Current Shell 'env:editor', # Display Editor, using EDITOR env - 'mpd:songs' + 'mpd:songs', # 'fs:/boot', # Display /boot Partition Usage # 'fs:/home', # Display /home Partition Usage # 'fs:/MOUNT/POINT', # Display * Partition, Edit To Your Needs -- cgit v1.2.3 From 4ba181875ae8b9558a4fbd9b45a794540e3d3d55 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 1 Sep 2010 19:40:49 +0100 Subject: mpdDisplay return none if python3-mpd not found, and mpc not found --- archey3 | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/archey3 b/archey3 index 15985d2..092e668 100755 --- a/archey3 +++ b/archey3 @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# archey3 [version 0.2-1] +# archey3 [version 0.2-2] # # Copyright 2010 Melik Manukyan # Copyright 2010 Laurie Clark-Michalek @@ -313,12 +313,15 @@ class deDisplay(display): return "DE", DE_DICT[de] class mpdDisplay(display): - command_line = "mpc stats" + """Displays certain stat about MPD database. If mpd not installed, output nothing.""" + command_line = "mpc stats --host {arg1} --port {arg2}" def __init__(self, stat='songs', hostname='localhost', port='6600', parent=None): self.stat = stat self.hostname = hostname self.port = port + self.arg1 = hostname + self.arg2 = port self._parent = parent try: global mpd @@ -330,25 +333,33 @@ class mpdDisplay(display): def run_command(self): if self.method == 'module': self.proccess = mpd.MPDClient() - self.proccess.connect(self.hostname, self.port) + try: + self.proccess.connect(self.hostname, self.port) + except Exception: + self.method == 'shell' + super().run_command() else: super().run_command() def render(self): if self.method == 'module': try: - return 'MPD {statname}'.format(statname=self.stat.title()), self.proccess.stats()[self.stat] + return '{statname} in MPD database'.format(statname=self.stat.title()), self.proccess.stats()[self.stat] except Exception: - return 'MPD {statname}'.format(statname=self.stat.title()), 'Error encountered' + return None else: super().render() def format_output(self, instring): lines = instring.split('\n') stats = {} - stats['artists'] = lines[0].split(':')[1].strip() - stats['albums'] = lines[1].split(':')[1].strip() - stats['songs'] = lines[2].split(':')[1].strip() + 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 (= no mpd installed) then return None) + except ValueError: + return None return '{statname} in MPD database'.format(statname=self.stat.title()), stats[self.stat] @@ -403,8 +414,10 @@ class Archey(object): if isinstance(out, list): for o in out: outputs.append(o) - else: + elif out is not None: outputs.append(out) + else: + continue for i in range(18): if i < len(outputs): -- cgit v1.2.3 From 60fbe8cc7b7f790d379314d5802bf8028d804350 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 1 Sep 2010 19:45:54 +0100 Subject: Improved screenshot countdown slighty --- archey3 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/archey3 b/archey3 index 092e668..129c88c 100755 --- a/archey3 +++ b/archey3 @@ -367,13 +367,17 @@ class mpdDisplay(display): def screenshot(): print('Screenshotting in') - list = list(range(1,6)) - list.reverse() - for x in list: - print('%s...' % x, end=' ') + for x in sorted(range(1,6), reverse=True): + print('%s' % x, end='') sys.stdout.flush() - sleep(1) + sleep(1.0/3) + for x in range(3): + print('.', end='') + sys.stdout.flush() + sleep(1.0/3) + print('Say Cheese!') + sys.stdout.flush() subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) def render(instance): -- cgit v1.2.3 From 000f5d5abb4095afa0f82f941dd631d2d7979b88 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 1 Sep 2010 20:07:23 +0100 Subject: Fixed mpdDisplay with shell method --- archey3 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/archey3 b/archey3 index 129c88c..54b45b9 100755 --- a/archey3 +++ b/archey3 @@ -346,9 +346,9 @@ class mpdDisplay(display): try: return '{statname} in MPD database'.format(statname=self.stat.title()), self.proccess.stats()[self.stat] except Exception: - return None + return False else: - super().render() + return super().render() def format_output(self, instring): lines = instring.split('\n') @@ -359,7 +359,7 @@ class mpdDisplay(display): stats['songs'] = lines[2].split(':')[1].strip() #if people don't have mpc installed (= no mpd installed) then return None) except ValueError: - return None + return False return '{statname} in MPD database'.format(statname=self.stat.title()), stats[self.stat] @@ -418,7 +418,7 @@ class Archey(object): if isinstance(out, list): for o in out: outputs.append(o) - elif out is not None: + elif out: outputs.append(out) else: continue -- cgit v1.2.3 From 92bf832c788554ea0349ef9b8c1090a152de24fc Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sat, 11 Sep 2010 21:37:00 +0100 Subject: Removed xfconfd, inserted xfce4-session --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 54b45b9..4403049 100755 --- a/archey3 +++ b/archey3 @@ -97,7 +97,7 @@ FUNC_MAPPINGS = { DE_DICT = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', - 'xfconfd': 'Xfce 4.6', + 'xfce4-session': 'Xfce 4.6', 'lxsession': 'LXDE', '': 'None', } -- cgit v1.2.3 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 From fe072db6f1c91f022311d38a142fb25db7c77732 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Thu, 23 Sep 2010 07:32:31 +0100 Subject: Fix crash when no mpd is installed --- archey3 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/archey3 b/archey3 index 4403049..b76f57b 100755 --- a/archey3 +++ b/archey3 @@ -161,7 +161,10 @@ class display(object): cmd = self.command_line.format(arg1=self.arg1) else: cmd = self.command_line - self.proccess = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE) + try: + self.proccess = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE) + except Exception as e: + pass def render(self): (stdoutdata, stderrdata) = self.proccess.communicate(self.stdindata or None) @@ -348,7 +351,10 @@ class mpdDisplay(display): except Exception: return False else: - return super().render() + if hasattr(self, "proccess"): + return super().render() + else: + return None def format_output(self, instring): lines = instring.split('\n') -- cgit v1.2.3 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 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 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 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 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 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 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 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 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 From f0d93d781869233c6ab4955bed255108b4b1f810 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 25 Oct 2010 15:55:54 +0100 Subject: Clear color at end of printing, fixes bug with bash --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index b76f57b..ccd54c8 100755 --- a/archey3 +++ b/archey3 @@ -77,7 +77,7 @@ LOGOS = {'Arch Linux': '''{c1} {c2} ;#### ####; {results[15]} {c2} ##' '## {results[16]} {c2} #' `# {results[17]} -{c2} ''' +\x1b[0m''' } FUNC_MAPPINGS = { -- cgit v1.2.3 From 515b5d0bc71e278ddedda96b441a92de47006c4d Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 25 Oct 2010 16:13:19 +0100 Subject: Added readme --- README | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..1d3e72a --- /dev/null +++ b/README @@ -0,0 +1,73 @@ +Archey 3 + +Archey 3 is a system infomation printer, designed to be used when taking screenshots of computer desktops to provide additional infomation about the operating system setup. Archey is designed to be used for Arch linux, and it acordingly prints out the Arch linux logo along side the system infomation. + +Display Variables + +Archey displays, as of 25/10/2010, the following by default: + + * Operating system + * Hostname + * Kernel Version + * Uptime + * Core temp (requires sensors) + * Window Manager + * Desktop Enviroment + * Number of packages installed + * Avalible Ram + * CPU Model + * Shell + * CLI Text Editor + * Number of songs in MPD library + * Space avalible on root filesystem + +The items that are displayed can be configured via -d|--display command line argument. Some examples are given below: + +archey3 -d 'ram.fs:/home.mpd:albums,localhost,8800.env:IP' + +would display the current ram usage, info on the /home partition, the number of mpd albums, and the IP adress env variable. + +The MPD Display function + +The MPD function takes the following arguments: + + 1. Stat name. This can be songs, artists, albums + 2. Hostname. Optional + 3. Port Number. Optional. + +The Sensor Display function + +The Sensor function takes the following argument: + + 1. Sensors. This will be given as the first argument to the sensors binary, and the output will be parsed. + +The ENV Display function + +The ENV function takes the following argument: + + 1. Variable name. The variable name will then be looked up via the genenv() function + +The uname Display function + +The uname function takes the following arguments: + + 1. Flag. This can be one of: + + * a - System Infomation + * s - Kernel Name + * n - Hostname + * r - Kernel Release + * v - Kernel Version + * m - Machine Hardwear name + * p - Processor type + * i - Hardwear platform + +The File System Display function + +The File System function takes the following arguments: + + 1. Partition path. The path to the partition to display + +The WM/DE Display function + +The WM/DE Display function takes no arguments -- cgit v1.2.3 From 32c53e86b6215d42f50a1e20d3df37924375e5b6 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 5 Nov 2010 09:59:52 +0000 Subject: Fix minor bug with uptime formatting --- archey3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archey3 b/archey3 index ccd54c8..6437a44 100755 --- a/archey3 +++ b/archey3 @@ -254,8 +254,8 @@ class uptimeDisplay(display): hour = int(fuptime / 3600) fuptime = fuptime % 3600 minute = int(fuptime / 60) - uptime = '{daystring}{hours}:{mins}'.format( - daystring='{days} day{s}, '.format(days=day, s=int(day) > 1) if day else '', + 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 -- cgit v1.2.3 From c5d85285e941c44c25e0840ecdb9ac6bea33b94c Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 7 Nov 2010 11:48:53 +0000 Subject: Added color_me method to display classes, and colored RootFS output, and RAM output --- archey3 | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 6437a44..c74b2b2 100755 --- a/archey3 +++ b/archey3 @@ -170,6 +170,20 @@ class display(object): (stdoutdata, stderrdata) = self.proccess.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(self._parent.color(color), output, self._parent.color('clear')) class fsDisplay(display): command_line = "df -TPh {arg1}" @@ -186,6 +200,14 @@ class fsDisplay(display): mount = '/root' if self.arg1 == '/' else self.arg1 title = mount.split('/')[-1].title() + " FS" + try: + used_ = ''.join(c for c in used if c.isdigit()) + total_ = ''.join(c for c in total if c.isdigit()) + persentage = 100 - (int(used_)/int(total_) * 100) + except: + pass + else: + used = self.color_me(used, persentage) part = '{used} / {total} ({fstype})'.format(used=used, total=total, fstype=fstype) return title, part @@ -197,7 +219,13 @@ class ramDisplay(display): used = int(ram[2]) - int(ram[5]) - int(ram[6]) total = int(ram[1]) title = 'RAM' - part = '{used} MB / {total} MB'.format(used=used, total=total) + try: + persentage = 100 - (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 class sensorDisplay(display): -- cgit v1.2.3 From 46411b6509ba78c4c698a6ef80aa48a4c561702a Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 7 Nov 2010 12:06:05 +0000 Subject: Corrected markdown syntax in readme --- README | 73 -------------------------------------------------------- README.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 73 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index 1d3e72a..0000000 --- a/README +++ /dev/null @@ -1,73 +0,0 @@ -Archey 3 - -Archey 3 is a system infomation printer, designed to be used when taking screenshots of computer desktops to provide additional infomation about the operating system setup. Archey is designed to be used for Arch linux, and it acordingly prints out the Arch linux logo along side the system infomation. - -Display Variables - -Archey displays, as of 25/10/2010, the following by default: - - * Operating system - * Hostname - * Kernel Version - * Uptime - * Core temp (requires sensors) - * Window Manager - * Desktop Enviroment - * Number of packages installed - * Avalible Ram - * CPU Model - * Shell - * CLI Text Editor - * Number of songs in MPD library - * Space avalible on root filesystem - -The items that are displayed can be configured via -d|--display command line argument. Some examples are given below: - -archey3 -d 'ram.fs:/home.mpd:albums,localhost,8800.env:IP' - -would display the current ram usage, info on the /home partition, the number of mpd albums, and the IP adress env variable. - -The MPD Display function - -The MPD function takes the following arguments: - - 1. Stat name. This can be songs, artists, albums - 2. Hostname. Optional - 3. Port Number. Optional. - -The Sensor Display function - -The Sensor function takes the following argument: - - 1. Sensors. This will be given as the first argument to the sensors binary, and the output will be parsed. - -The ENV Display function - -The ENV function takes the following argument: - - 1. Variable name. The variable name will then be looked up via the genenv() function - -The uname Display function - -The uname function takes the following arguments: - - 1. Flag. This can be one of: - - * a - System Infomation - * s - Kernel Name - * n - Hostname - * r - Kernel Release - * v - Kernel Version - * m - Machine Hardwear name - * p - Processor type - * i - Hardwear platform - -The File System Display function - -The File System function takes the following arguments: - - 1. Partition path. The path to the partition to display - -The WM/DE Display function - -The WM/DE Display function takes no arguments diff --git a/README.md b/README.md new file mode 100644 index 0000000..902a205 --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +Archey 3 +======== + +Archey 3 is a system infomation printer, designed to be used when taking screenshots of computer desktops to provide additional infomation about the operating system setup. Archey is designed to be used for Arch linux, and it acordingly prints out the Arch linux logo along side the system infomation. + +Display Variables +----------------- + +Archey displays, as of 25/10/2010, the following by default: + +- Operating system +- Hostname +- Kernel Version +- Uptime +- Core temp (requires sensors) +- Window Manager +- Desktop Enviroment +- Number of packages installed +- Avalible Ram +- CPU Model +- Shell +- CLI Text Editor +- Number of songs in MPD library +- Space avalible on root filesystem + +The items that are displayed can be configured via -d|--display command line argument. Some examples are given below: + +archey3 -d 'ram.fs:/home.mpd:albums,localhost,8800.env:IP' + +would display the current ram usage, info on the /home partition, the number of mpd albums, and the IP adress env variable. + +The MPD Display function +------------------------ + +The MPD function takes the following arguments: + +1. Stat name. This can be songs, artists, albums +2. Hostname. Optional +3. Port Number. Optional. + +The Sensor Display function +--------------------------- + +The Sensor function takes the following argument: + +1. Sensors. This will be given as the first argument to the sensors binary, and the output will be parsed. + +The ENV Display function +------------------------ + +The ENV function takes the following argument: + +1. Variable name. The variable name will then be looked up via the genenv() function + +The uname Display function +-------------------------- + +The uname function takes the following arguments: + +1. Flag. This can be one of: + + * a - System Infomation + * s - Kernel Name + * n - Hostname + * r - Kernel Release + * v - Kernel Version + * m - Machine Hardwear name + * p - Processor type + * i - Hardwear platform + +The File System Display function +-------------------------------- + +The File System function takes the following arguments: + +1. Partition path. The path to the partition to display + +The WM/DE Display function +-------------------------- + +The WM/DE Display function takes no arguments -- cgit v1.2.3 From b034f7a944836f15b41adeded3d9290f79d51a8f Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 7 Nov 2010 14:11:50 +0000 Subject: Fixed minor bug that was causing reverse FS coloring --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index c74b2b2..9fb48ab 100755 --- a/archey3 +++ b/archey3 @@ -203,7 +203,7 @@ class fsDisplay(display): try: used_ = ''.join(c for c in used if c.isdigit()) total_ = ''.join(c for c in total if c.isdigit()) - persentage = 100 - (int(used_)/int(total_) * 100) + persentage = (int(used_)/int(total_) * 100) except: pass else: -- cgit v1.2.3 From a453cc15a61eb458936db09fbb353c3fa4c2ee87 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 7 Nov 2010 14:13:21 +0000 Subject: Fixed minor bug that was causing reverse FS coloring --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 9fb48ab..c81d282 100755 --- a/archey3 +++ b/archey3 @@ -220,7 +220,7 @@ class ramDisplay(display): total = int(ram[1]) title = 'RAM' try: - persentage = 100 - (used / total * 100) + persentage = (used / total * 100) except: used += ' MB' else: -- cgit v1.2.3 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 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 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 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 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 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 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 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 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 From 96c455dac0a20d13fe27b649f6e34a14b87c2c2c Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 17 Nov 2010 19:44:33 +0000 Subject: Made all numerators of fraction outputs bold. Also reworked the Archey.color function. Added the bold kwarg to allow for easier control. Archey.format_item now edits output, could be an argument for allowing custom filters here. Concider for next big rewrite. --- archey3 | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/archey3 b/archey3 index c81d282..713be84 100755 --- a/archey3 +++ b/archey3 @@ -466,21 +466,35 @@ class Archey(object): return outputs 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 = self.color(1, bold=True) + numerator + self.color('clear') + denominator = data.split('/')[1] + data = '/'.join((numerator, denominator)) + return "{color}{title}:{clear} {data}".format( color=self.color(1), - title=item[0].rstrip(':'), - data=str(item[1]).rstrip(), + title=title, + data=data, clear=self.color("clear") ) - def color(self, code): - if code == 1: - return '\x1b[1;3%sm' % self.colorcode - elif code == 2: - return '\x1b[0;3%sm' % self.colorcode - if code == "clear": + def color(self, code, bold=False): + 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(self.colorcode) + elif code == "clear": return '\x1b[0m' - return '\x1b[0;3%sm' % COLORS[code] + else: + second_bitty_bit = '3{0}m'.format(COLORS[code]) + + return first_bitty_bit + second_bitty_bit def main(): -- cgit v1.2.3 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 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 From f45812e24169185e2b0589e98612f04ff8ef4fa8 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 17 Nov 2010 21:58:05 +0000 Subject: Added fix to coloring of File system output. Added conversion table to convert between size chars ('M', 'G', 'k' etc) and int. --- archey3 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/archey3 b/archey3 index 713be84..6658b20 100755 --- a/archey3 +++ b/archey3 @@ -188,6 +188,14 @@ class display(object): class fsDisplay(display): command_line = "df -TPh {arg1}" + conversions = { + 'M': 1 * 10 ** 6, + 'K': 1 * 10 ** 3, + 'G': 1 * 10 ** 9, + 'T': 1 * 10 ** 12, + 'P': 1 * 10 ** 15, + } + def __init__(self, path='/', parent=None): self.arg1 = path self._parent = parent @@ -201,9 +209,9 @@ class fsDisplay(display): mount = '/root' if self.arg1 == '/' else self.arg1 title = mount.split('/')[-1].title() + " FS" try: - used_ = ''.join(c for c in used if c.isdigit()) - total_ = ''.join(c for c in total if c.isdigit()) - persentage = (int(used_)/int(total_) * 100) + used_ = int(used[:-1]) * self.conversions[used[-1]] + total_ = int(total[:-1]) * self.conversions[total[-1]] + persentage = used_ / total_ * 100 except: pass else: -- cgit v1.2.3 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 From 2386683d94765e2d4411bd5003378563c6ad9d13 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 5 Dec 2010 11:52:19 +0000 Subject: Added another layer of error catching to hopefully fix (or at least hide) peoples recent problems --- archey3 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/archey3 b/archey3 index 6658b20..7abad8b 100755 --- a/archey3 +++ b/archey3 @@ -209,8 +209,9 @@ class fsDisplay(display): mount = '/root' if self.arg1 == '/' else self.arg1 title = mount.split('/')[-1].title() + " FS" try: - used_ = int(used[:-1]) * self.conversions[used[-1]] - total_ = int(total[:-1]) * self.conversions[total[-1]] + #convert to straight int + used_ = int(used[:-1]) * self.conversions[used[-1].upper()] + total_ = int(total[:-1]) * self.conversions[total[-1].upper()] persentage = used_ / total_ * 100 except: pass @@ -423,8 +424,11 @@ def screenshot(): subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) def render(instance): - instance.run_command() - return instance.render() + try: + instance.run_command() + return instance.render() + except: + return None #------------ Display object --------- -- cgit v1.2.3 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 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 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 From 170b495799bdb7b8d00d52f1cab1ee52b0e01512 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 20 Feb 2011 23:36:02 +0000 Subject: Output error message instead of crash if the screenshot command returns a non-zero value. --- archey3 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 7abad8b..b36280c 100755 --- a/archey3 +++ b/archey3 @@ -421,7 +421,10 @@ def screenshot(): print('Say Cheese!') sys.stdout.flush() - subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) + try: + subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) + except subprocess.CalledProcessError as e: + print('Screenshot failed with return code {0}.'.format(e.returncode)) def render(instance): try: -- cgit v1.2.3 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 From f6e1f1c9457053e20793add6d44a1a98a4d42c4d Mon Sep 17 00:00:00 2001 From: unexist Date: Tue, 29 Mar 2011 16:34:43 +0200 Subject: Added subtle to wm dict --- archey3 | 1 + 1 file changed, 1 insertion(+) diff --git a/archey3 b/archey3 index b36280c..1d055b9 100755 --- a/archey3 +++ b/archey3 @@ -120,6 +120,7 @@ WM_DICT = { 'pekwm': 'PekWM', 'ratpoison': 'ratpoison', 'scrotwm': 'ScrotWM', + 'subtle': 'subtle', 'wmaker': 'Window Maker', 'wmfs': 'Wmfs', 'wmii': 'wmii', -- cgit v1.2.3 From 27fb37ab40fded13b54f4096c0ef0e1a550ad199 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 29 Mar 2011 16:09:48 +0000 Subject: Added ArcheyConfigParser class, including a default config. --- archey3 | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 1d055b9..70ee8e3 100755 --- a/archey3 +++ b/archey3 @@ -40,7 +40,7 @@ DISPLAY = [ # Import libraries -import subprocess, optparse, re, sys +import subprocess, optparse, re, sys, configparser from subprocess import Popen, PIPE from optparse import OptionParser from getpass import getuser @@ -407,6 +407,65 @@ class mpdDisplay(display): return '{statname} in MPD database'.format(statname=self.stat.title()), stats[self.stat] +#------------ Config ----------- + +class ArcheyConfigParser(configparser.SafeConfigParser): + """ + A parser for the archey config file. + """ + + defaults = {'core': {'align': 'top', + 'color': 'blue', + 'modules': + """ + os, hostname, kernel, uptime, wm, de, pacman, ram, cpu, + env:editor, df:/, mpd:albums + """ + }, + 'mpd': {'host': 'localhost', + 'port': '8800', + 'method': 'mpc', + }, + } + + def __init__(self): + super(ArcheyConfigParser, self).__init__() + + def read(self, file_location="$XDG_CONFIG_HOME/archey3.cfg"): + """ + 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. + """ + config_location = os.path.expandvars(os.path.expanduser(file_location)) + loaded = super(ArcheyConfigParser, self).read(config_location) + if file_location == "$XDG_CONFIG_HOME/archey3.cfg": + self.load_default_config() + self.write_config(file_location) + if not loaded: + #Try with default + loaded = super(ArcheyConfigParser, self).read() + + def load_default_config(self): + """ + Loads the config options stored at self.defaults. + """ + for section, values in self.defaults.iteritems(): + for option, value in values.iteritems(): + #strip any excess spaces + while value.find(' ') != -1: + value = value.replace(' ', ' ') + self.set(section, option, value) + + def write_config(self, location): + """ + Writes the current config to the given location. + """ + with open(location, 'wb') as configfile: + self.write(configfile) + + #------------ Functions ----------- def screenshot(): -- cgit v1.2.3 From 780dc92e0cde3747d3d8d8e2663acce079a2daaa Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 29 Mar 2011 16:11:28 +0000 Subject: Changed copyright date. --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 70ee8e3..ae943a9 100755 --- a/archey3 +++ b/archey3 @@ -3,7 +3,7 @@ # archey3 [version 0.2-2] # # Copyright 2010 Melik Manukyan -# Copyright 2010 Laurie Clark-Michalek +# Copyright 2010-2011 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. # -- cgit v1.2.3 From 26c07b13e367416715be2b51126ff14b15c8d8aa Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 29 Mar 2011 16:33:25 +0000 Subject: Sorted out some overly long lines. --- archey3 | 88 +++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 29 deletions(-) diff --git a/archey3 b/archey3 index ae943a9..faccb9f 100755 --- a/archey3 +++ b/archey3 @@ -141,7 +141,8 @@ COLORS = { } class display(object): - __slots__ = ['command_line', 'arg1', 'arg2', 'arg3', 'stdindata', 'proccess', '_parent'] + __slots__ = ['command_line', 'arg1', 'arg2', 'arg3', 'stdindata', + 'proccess', '_parent', 'config'] command_line = '' arg1 = '' @@ -149,13 +150,15 @@ class display(object): arg3 = '' stdindata = '' - def __init__(self, parent=None): + def __init__(self, config, parent=None): + self.config = config self._parent = parent 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) + 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: @@ -163,15 +166,18 @@ class display(object): else: cmd = self.command_line try: - self.proccess = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE) + self.proccess = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, + stderr=PIPE) except Exception as e: pass def render(self): - (stdoutdata, stderrdata) = self.proccess.communicate(self.stdindata or None) + (stdoutdata, stderrdata) = self.proccess.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'): + 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: @@ -184,7 +190,8 @@ class display(object): elif medium < number: color = high_color - return '{0}{1}{2}'.format(self._parent.color(color), output, self._parent.color('clear')) + return '{0}{1}{2}'.format(self._parent.color(color), output, + self._parent.color('clear')) class fsDisplay(display): command_line = "df -TPh {arg1}" @@ -218,14 +225,16 @@ class fsDisplay(display): pass else: used = self.color_me(used, persentage) - part = '{used} / {total} ({fstype})'.format(used=used, total=total, fstype=fstype) + part = '{used} / {total} ({fstype})'.format(used=used, total=total, + fstype=fstype) return title, part 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() + 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' @@ -250,15 +259,19 @@ class sensorDisplay(display): out = [] for line in tempinfo: - info = [re.sub("\s\s+", "", line) for line in line.split(' ') if line] + info = [re.sub("\s\s+", "", line) for line in line.split(' ') if\ + line] value = info[1] intvalue = int(value[:3]) if intvalue > 45: - temp = self._parent.color("red") + info[1] + self._parent.color("clear") + temp = (self._parent.color("red") + info[1] + + self._parent.color("clear")) elif intvalue in range(30, 45): - temp = self._parent.color("magenta") + info[1] + self._parent.color("clear") + temp = (self._parent.color("magenta") + info[1] + + self._parent.color("clear")) else: - temp = self._parent.color("green") + info[1] + self._parent.color("clear") + temp = (self._parent.color("green") + info[1] + + self._parent.color("clear")) out.append((info[0], temp)) return out @@ -293,7 +306,8 @@ class uptimeDisplay(display): 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 '', + daystring='{days} day{s}, '.format(days=day, s=('s' if day > 1 + else '')) if day else '', hours = hour, mins = minute ) return "Uptime", uptime @@ -328,7 +342,8 @@ class proccessCheck(display): def run_command(self): super().run_command() out = str(self.proccess.communicate()[0]) - self._processes = set([line.split()[3] for line in out.split('\\n') if len(line.split()) == 4]) + self._processes = set([line.split()[3] for line in out.split('\\n') if\ + len(line.split()) == 4]) def __call__(self, proc): if proc in self._processes: @@ -354,10 +369,14 @@ class deDisplay(display): return "DE", DE_DICT[de] class mpdDisplay(display): - """Displays certain stat about MPD database. If mpd not installed, output nothing.""" + """ + Displays certain stat about MPD database. If mpd not installed, output + nothing. + """ command_line = "mpc stats --host {arg1} --port {arg2}" - def __init__(self, stat='songs', hostname='localhost', port='6600', parent=None): + def __init__(self, stat='songs', hostname='localhost', port='6600', + parent=None): self.stat = stat self.hostname = hostname self.port = port @@ -385,7 +404,8 @@ class mpdDisplay(display): def render(self): if self.method == 'module': try: - return '{statname} in MPD database'.format(statname=self.stat.title()), self.proccess.stats()[self.stat] + return '{statname} in MPD database'.format( + statname=self.stat.title()), self.proccess.stats()[self.stat] except Exception: return False else: @@ -401,11 +421,12 @@ class mpdDisplay(display): 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 (= no mpd installed) then return None) + #if people don't have mpc installed then return None) except ValueError: return False - return '{statname} in MPD database'.format(statname=self.stat.title()), stats[self.stat] + return ('{statname} in MPD database'.format(statname=self.stat.title()), + stats[self.stat]) #------------ Config ----------- @@ -482,9 +503,11 @@ def screenshot(): print('Say Cheese!') sys.stdout.flush() try: - subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) + subprocess.check_call(['import', '-window', 'root', + ctime().replace(' ','_')+'.jpg']) except subprocess.CalledProcessError as e: - print('Screenshot failed with return code {0}.'.format(e.returncode)) + print('Screenshot failed with return code {0}.'.format( + e.returncode)) def render(instance): try: @@ -547,7 +570,8 @@ class Archey(object): #if we're dealing with a fraction if len(data.split('/')) == 2: numerator = data.split('/')[0] - numerator = self.color(1, bold=True) + numerator + self.color('clear') + numerator = (self.color(1, bold=True) + numerator + + self.color('clear')) denominator = data.split('/')[1] data = '/'.join((numerator, denominator)) @@ -576,8 +600,9 @@ def main(): global processes processes = render(proccessCheck()) - parser = OptionParser(usage='%prog [-c COLOR] [-s, --screenshot] [-d, --display]', - description="""Archey is a utility to take """, + parser = OptionParser( + usage='%prog [-c COLOR] [-s, --screenshot] [-d, --display]', + description="""Archey is a utility to take """, version="%prog 0.2-1") parser.add_option('-c', action='store', default='blue', type='choice', dest='color', @@ -589,13 +614,18 @@ def main(): 'magenta', 'cyan', 'white'), - help='choose a color: black, red, green, yellow, blue, magenta, cyan, white [Default: blue]') + 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('-d', '--display', - action='store', dest='display', help='Define info to be displayed by archey. DISPLAY must be in the \ -format "archey_display_module:arg1,arg2,arg3.second_display_module". Availible display modules are uname, fs, env, \ -uptime, sensors, ram, de and wm. See the DISPLAY list in the archey source file for more info.') + action='store', dest='display', + help="""Define info to be displayed by archey. DISPLAY + must be in the format "archey_display_module:arg1,arg2,arg + 3.second_display_module". Availible display modules are un + ame, fs, env, uptime, sensors, ram, de and wm. + See the DISPLAY list in the archey source file for more + info.""") (options, args) = parser.parse_args() if options.display: -- cgit v1.2.3 From cedfec40f4818e90cdc0a418bc15acfd48028428 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 29 Mar 2011 16:45:27 +0000 Subject: Make sure every display class takes config as an argument. --- archey3 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/archey3 b/archey3 index faccb9f..5def9b9 100755 --- a/archey3 +++ b/archey3 @@ -276,8 +276,9 @@ class sensorDisplay(display): return out class envDisplay(display): - def __init__(self, env='SHELL', parent=None): + def __init__(self, config, env='SHELL', parent=None): self.arg1 = env + self.config = config self._parent = parent def render(self): @@ -287,8 +288,9 @@ class envDisplay(display): class unameDisplay(display): command_line = "uname {arg1}" - def __init__(self, flag=False, parent=None): + def __init__(self, config, flag=False, parent=None): self.arg1 = '-' + flag if flag else '' + self.config = config self._parent = parent def format_output(self, instring): @@ -335,8 +337,9 @@ class proccessCheck(display): render = lambda self: self - def __init__(self, parent=None): + def __init__(self, config, parent=None): self.arg1 = getuser() + self.config = config self._parent = parent def run_command(self): @@ -375,13 +378,14 @@ class mpdDisplay(display): """ command_line = "mpc stats --host {arg1} --port {arg2}" - def __init__(self, stat='songs', hostname='localhost', port='6600', + def __init__(self, config, stat='songs', hostname='localhost', port='6600', parent=None): self.stat = stat self.hostname = hostname self.port = port self.arg1 = hostname self.arg2 = port + self.config = config self._parent = parent try: global mpd -- cgit v1.2.3 From ee306ae6702a7bbfe1f2d152216fe671e2930979 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 29 Mar 2011 17:41:45 +0000 Subject: Modified various classes to use new config options. --- archey3 | 69 +++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/archey3 b/archey3 index 5def9b9..0daa97e 100755 --- a/archey3 +++ b/archey3 @@ -197,15 +197,23 @@ class fsDisplay(display): command_line = "df -TPh {arg1}" conversions = { - 'M': 1 * 10 ** 6, - 'K': 1 * 10 ** 3, - 'G': 1 * 10 ** 9, - 'T': 1 * 10 ** 12, - 'P': 1 * 10 ** 15, + 'binary': { + 'KB': 2 ** 10, + 'MB': 2 ** 20, + 'GB': 2 ** 30, + 'TB': 2 ** 40, + }, + 'si': { + 'KB': 10 ** 3, + 'MB': 10 ** 6, + 'GB': 10 ** 9, + 'TB': 10 ** 12, + }, } - def __init__(self, path='/', parent=None): + def __init__(self, config, path='/', parent=None): self.arg1 = path + self.config = config self._parent = parent def format_output(self, instring): @@ -213,13 +221,15 @@ class fsDisplay(display): used = values[3] total = values[2] fstype = values[1] + conversion_type = self.config.get('fs', 'unit').lower() + conversions = self.conversions[conversion_type] mount = '/root' if self.arg1 == '/' else self.arg1 title = mount.split('/')[-1].title() + " FS" try: #convert to straight int - used_ = int(used[:-1]) * self.conversions[used[-1].upper()] - total_ = int(total[:-1]) * self.conversions[total[-1].upper()] + used_ = int(used[:-1]) * conversions[used[-1].upper()] + total_ = int(total[:-1]) * conversions[total[-1].upper()] persentage = used_ / total_ * 100 except: pass @@ -250,9 +260,15 @@ class ramDisplay(display): class sensorDisplay(display): command_line = "sensors {arg1}" - def __init__(self, sensors="coretemp-*", parent=None): - self.arg1 = sensors + def __init__(self, config, sensors='', parent=None): + self.config = config self._parent = parent + arg_from_conf = config.get('sensor', 'sensor', 'coretemp-*') + arg_from_arg = sensors + 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] @@ -289,9 +305,16 @@ class unameDisplay(display): command_line = "uname {arg1}" def __init__(self, config, flag=False, parent=None): - self.arg1 = '-' + flag if flag else '' self.config = config self._parent = parent + arg_from_conf = config.get('uname', 'argument', '') + 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) @@ -378,35 +401,29 @@ class mpdDisplay(display): """ command_line = "mpc stats --host {arg1} --port {arg2}" - def __init__(self, config, stat='songs', hostname='localhost', port='6600', - parent=None): + def __init__(self, config, stat='songs', parent=None): self.stat = stat - self.hostname = hostname - self.port = port + self.hostname = config.get('mpd', 'host', 'localhost') + self.port = int(config.get('mpd', 'port', 8800)) self.arg1 = hostname self.arg2 = port + self.method = config.get('mpd', 'method', 'mpc') self.config = config self._parent = parent - try: - global mpd - import mpd - self.method = 'module' - except ImportError: - self.method = 'shell' def run_command(self): - if self.method == 'module': + if self.method == 'python3mpd': self.proccess = mpd.MPDClient() try: self.proccess.connect(self.hostname, self.port) except Exception: - self.method == 'shell' + self.method == 'mpc' super().run_command() else: super().run_command() def render(self): - if self.method == 'module': + if self.method == 'python3mpd': try: return '{statname} in MPD database'.format( statname=self.stat.title()), self.proccess.stats()[self.stat] @@ -447,10 +464,6 @@ class ArcheyConfigParser(configparser.SafeConfigParser): env:editor, df:/, mpd:albums """ }, - 'mpd': {'host': 'localhost', - 'port': '8800', - 'method': 'mpc', - }, } def __init__(self): -- cgit v1.2.3 From 1e133e983503e26f9eeeef10ab53eb26f5486d82 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 29 Mar 2011 17:49:35 +0000 Subject: Added manual option for DE and WM display classes to allow users to specify products not in the standard DE_DICT/WM_DICT --- archey3 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/archey3 b/archey3 index 0daa97e..a3348bf 100755 --- a/archey3 +++ b/archey3 @@ -378,6 +378,8 @@ class proccessCheck(display): class wmDisplay(display): def render(self): + if not self.config.get('wm', 'manual', False): + return "WM", self.config.get('de', 'manual') wm = '' for key in WM_DICT.keys(): if processes(key): @@ -387,6 +389,8 @@ class wmDisplay(display): class deDisplay(display): def render(self): + if not self.config.get('de', 'manual', False): + return "DE", self.config.get('de', 'manual') de = '' for key in DE_DICT.keys(): if processes(key): -- cgit v1.2.3 From b8d0bdc814a1c7ff2e5ab3080fbe36d70756c569 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 6 Jun 2011 20:31:07 +0000 Subject: Added working config file, along with logging via logbook --- archey3 | 374 +++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 202 insertions(+), 172 deletions(-) diff --git a/archey3 b/archey3 index a3348bf..d11a836 100755 --- a/archey3 +++ b/archey3 @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # # archey3 [version 0.2-2] # @@ -18,27 +18,6 @@ # fs:x = return space of partition at x # mpd:stat,hostname,port = returns value of an mpd stat (options: artists|albums|songs) -DISPLAY = [ - 'distro', # Display Operating System - 'uname:n', # Display Machine Hostname - 'uname:r', # Display Kernel Version - 'uptime', # Display System Uptime - 'sensors:coretemp-*', # Display System Core tempature - 'wm', # Display Window Manager - 'de', # Display Desktop Environment - 'packages', # Display Number of Packages Installed - 'ram', # Display RAM Usage - 'uname:p', # Display CPU Model - 'env:shell', # Display Current Shell - 'env:editor', # Display Editor, using EDITOR env - 'mpd:songs', -# '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 -] - - # Import libraries import subprocess, optparse, re, sys, configparser from subprocess import Popen, PIPE @@ -46,6 +25,9 @@ from optparse import OptionParser from getpass import getuser from time import ctime, sleep from os import getenv +import re +import os.path +from logbook import Logger UNAME_FLAG_MEANINGS = { 'a': 'System Infomation', @@ -80,7 +62,7 @@ LOGOS = {'Arch Linux': '''{c1} \x1b[0m''' } -FUNC_MAPPINGS = { +CLASS_MAPPINGS = { 'distro': 'distroCheck', 'uname': 'unameDisplay', 'uptime': 'uptimeDisplay', @@ -141,19 +123,27 @@ COLORS = { } class display(object): - __slots__ = ['command_line', 'arg1', 'arg2', 'arg3', 'stdindata', - 'proccess', '_parent', 'config'] - command_line = '' arg1 = '' arg2 = '' arg3 = '' stdindata = '' - def __init__(self, config, parent=None): + def __init__(self, args, config, logger, parent=None): self.config = config + self.logger = logger self._parent = parent + @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: @@ -166,14 +156,15 @@ class display(object): else: cmd = self.command_line try: - self.proccess = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, + self.process = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE) except Exception as e: pass def render(self): - (stdoutdata, stderrdata) = self.proccess.communicate(self.stdindata + (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', @@ -192,16 +183,21 @@ class display(object): return '{0}{1}{2}'.format(self._parent.color(color), output, self._parent.color('clear')) + + def process_exists(self, key): + global PROCESSES + return PROCESSES(key) + class fsDisplay(display): command_line = "df -TPh {arg1}" conversions = { 'binary': { - 'KB': 2 ** 10, - 'MB': 2 ** 20, - 'GB': 2 ** 30, - 'TB': 2 ** 40, + 'KiB': 2 ** 10, + 'MiB': 2 ** 20, + 'GiB': 2 ** 30, + 'TiB': 2 ** 40, }, 'si': { 'KB': 10 ** 3, @@ -211,17 +207,21 @@ class fsDisplay(display): }, } - def __init__(self, config, path='/', parent=None): - self.arg1 = path - self.config = config - self._parent = parent + def __init__(self, **kwargs): + super().__init__(**kwargs) + try: + self.arg1 = kwargs["args"][0] + except IndexError: + self.logger.error( + "Did not any arguments, require one, the fs to display") + raise def format_output(self, instring): values = [line for line in instring.split('\n') if line][1].split() used = values[3] total = values[2] fstype = values[1] - conversion_type = self.config.get('fs', 'unit').lower() + conversion_type = self.config.get('fs', 'unit', fallback="si").lower() conversions = self.conversions[conversion_type] mount = '/root' if self.arg1 == '/' else self.arg1 @@ -260,11 +260,18 @@ class ramDisplay(display): class sensorDisplay(display): command_line = "sensors {arg1}" - def __init__(self, config, sensors='', parent=None): - self.config = config - self._parent = parent - arg_from_conf = config.get('sensor', 'sensor', 'coretemp-*') - arg_from_arg = sensors + def __init__(self, **kwargs): + super().__init__(**kwargs) + + arg_from_conf = self.config.get('sensor', 'sensor', + fallback='coretemp-*') + try: + arg_from_arg = kwargs["args"][0] + except IndexError: + self.logger.error( + "Did not get any arguments, require one, the sensor to display.") + raise + if arg_from_arg: self.arg1 = arg_from_arg else: @@ -292,10 +299,15 @@ class sensorDisplay(display): return out class envDisplay(display): - def __init__(self, config, env='SHELL', parent=None): - self.arg1 = env - self.config = config - self._parent = parent + def __init__(self, **kwargs): + try: + self.arg1 = kwargs["args"][0] + except IndexError: + self.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()) @@ -304,10 +316,17 @@ class envDisplay(display): class unameDisplay(display): command_line = "uname {arg1}" - def __init__(self, config, flag=False, parent=None): - self.config = config - self._parent = parent - arg_from_conf = config.get('uname', 'argument', '') + def __init__(self, **kwargs): + super().__init__(**kwargs) + + try: + flag = kwargs["args"][0] + except IndexError: + self.logger.error("Did not get any arguments, require one," + + " the flag to pass to uname") + raise + + arg_from_conf = self.config.get('uname', 'argument', fallback="") arg_from_arg = flag if arg_from_arg: self.arg1 = '-' + arg_from_arg @@ -346,28 +365,26 @@ class packageDisplay(display): class distroCheck(display): def render(self): try: - rc = open("/etc/pacman.conf") + _ = open("/etc/pacman.conf") except IOError: - distro = render(unameDisplay("o"))[1] + distro = self.call_command("uname -o") else: distro = "Arch Linux" - distro = ' '.join([distro, render(unameDisplay('m'))[1]]) + distro = '{0} {1}'.format(distro, self.call_command("uname -m")) return "OS", distro -class proccessCheck(display): - __slots__ = display.__slots__ + ['_processes'] +class processCheck(display): command_line = "ps -u {arg1}" render = lambda self: self - def __init__(self, config, parent=None): + def __init__(self, **kwargs): self.arg1 = getuser() - self.config = config - self._parent = parent + super().__init__(**kwargs) def run_command(self): super().run_command() - out = str(self.proccess.communicate()[0]) + out = str(self.process.communicate()[0]) self._processes = set([line.split()[3] for line in out.split('\\n') if\ len(line.split()) == 4]) @@ -378,22 +395,22 @@ class proccessCheck(display): class wmDisplay(display): def render(self): - if not self.config.get('wm', 'manual', False): - return "WM", self.config.get('de', 'manual') + if self.config.get('wm', 'manual', fallback=False): + return "WM", self.config.get('wm', 'manual') wm = '' for key in WM_DICT.keys(): - if processes(key): + if self.process_exists(key): wm = key break return "WM", WM_DICT[wm] class deDisplay(display): def render(self): - if not self.config.get('de', 'manual', False): + if self.config.get('de', 'manual', fallback=False): return "DE", self.config.get('de', 'manual') de = '' for key in DE_DICT.keys(): - if processes(key): + if self.process_exists(key): de = key break return "DE", DE_DICT[de] @@ -405,39 +422,16 @@ class mpdDisplay(display): """ command_line = "mpc stats --host {arg1} --port {arg2}" - def __init__(self, config, stat='songs', parent=None): - self.stat = stat - self.hostname = config.get('mpd', 'host', 'localhost') - self.port = int(config.get('mpd', 'port', 8800)) - self.arg1 = hostname - self.arg2 = port - self.method = config.get('mpd', 'method', 'mpc') - self.config = config - self._parent = parent - - def run_command(self): - if self.method == 'python3mpd': - self.proccess = mpd.MPDClient() - try: - self.proccess.connect(self.hostname, self.port) - except Exception: - self.method == 'mpc' - super().run_command() - else: - super().run_command() - - def render(self): - if self.method == 'python3mpd': - try: - return '{statname} in MPD database'.format( - statname=self.stat.title()), self.proccess.stats()[self.stat] - except Exception: - return False - else: - if hasattr(self, "proccess"): - return super().render() - else: - return None + def __init__(self, **kwargs): + super().__init__(**kwargs) + + try: + self.stat = kwargs["args"][0] + except IndexError: + self.logger.error("Did not get any arguments, require one," + + " the stat to display.") + self.arg1 = self.config.get('mpd', 'host', fallback='localhost') + self.arg2 = self.config.getint('mpd', 'port', fallback=8800) def format_output(self, instring): lines = instring.split('\n') @@ -447,7 +441,7 @@ class mpdDisplay(display): 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 ValueError: + except: return False return ('{statname} in MPD database'.format(statname=self.stat.title()), @@ -462,49 +456,52 @@ class ArcheyConfigParser(configparser.SafeConfigParser): defaults = {'core': {'align': 'top', 'color': 'blue', - 'modules': - """ - os, hostname, kernel, uptime, wm, de, pacman, ram, cpu, - env:editor, df:/, mpd:albums - """ + 'display_modules': + """\ +distro(), uname(n), distro(r), uptime(), wm(), de(), packages(), ram(),\ + uname(p), env(editor), df(/), mpd(albums)""" }, } - def __init__(self): - super(ArcheyConfigParser, self).__init__() - - def read(self, file_location="$XDG_CONFIG_HOME/archey3.cfg"): + 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. """ - config_location = os.path.expandvars(os.path.expanduser(file_location)) + + config_location = os.path.expandvars(os.path.expanduser( + file_location or "$XDG_CONFIG_HOME/archey3.cfg")) + loaded = super(ArcheyConfigParser, self).read(config_location) - if file_location == "$XDG_CONFIG_HOME/archey3.cfg": + + if file_location == None and not loaded: self.load_default_config() - self.write_config(file_location) + self.write_config(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.iteritems(): - for option, value in values.iteritems(): + 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 - while value.find(' ') != -1: - value = value.replace(' ', ' ') + 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, 'wb') as configfile: + with open(location, 'w') as configfile: self.write(configfile) @@ -530,59 +527,78 @@ def screenshot(): print('Screenshot failed with return code {0}.'.format( e.returncode)) -def render(instance): - try: - instance.run_command() - return instance.render() - except: - return None - #------------ Display object --------- class Archey(object): - def __init__(self, display=None, colorscheme='blue'): - self.display = display or [] + DISPLAY_PARSING_REGEX = "(?P\w+)\((|(?P[\w, /]+))\)" + + def __init__(self, config, options): + self.config = config + self.log_level = int(options.log_level) + self.logger = Logger("Core", self.log_level) + + self.display = config.get("core", "display_modules") + colorscheme = options.color or config.get("core", "color") for key in COLORS.keys(): if key == colorscheme: self.colorcode = COLORS[key] - self.distro_name = ' '.join(render(distroCheck())[1].split()[:-1]) + global PROCESSES + PROCESSES = self.render_class(processCheck, ()) + + self.distro_name = ' '.join( + self.render_class(distroCheck, ())[1].split()[:-1]) def render(self): results = self.prepare_results() - print(LOGOS[self.distro_name].format(c1=self.color(1), - c2=self.color(2), - results = results - )) + return LOGOS[self.distro_name].format(c1=self.color(1), + c2=self.color(2), + 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. + """ outputs = [] # Run functions found in 'display' array. - for func in self.display: - if len(func.split(':')) > 1: - cls = eval(FUNC_MAPPINGS[func.split(':')[0]]) - args = tuple(func.split(':')[1].split(',')) - else: - cls = eval(FUNC_MAPPINGS[func]) - args = () + for func_name, args in self.parse_display(): + cls = eval(CLASS_MAPPINGS[func_name]) - out = render(cls(*args, parent=self)) - if isinstance(out, list): - for o in out: - outputs.append(o) - elif out: - outputs.append(out) - else: - continue + line = self.render_class(cls, args) + if hasattr(line, "__iter__") and len(line) != 2: + outputs.extend(line) + elif line: + outputs.append(line) - for i in range(18): - if i < len(outputs): - outputs[i] = self.format_item(outputs[i]) + outputs = [self.format_item(line) for line in outputs] + return outputs + [""] * (18 - len(outputs)) + + 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.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: - outputs.append('') - - return outputs + args = () + + yield groups["func"], args + raise StopIteration def format_item(self, item): title = item[0].rstrip(':') @@ -615,17 +631,35 @@ class Archey(object): second_bitty_bit = '3{0}m'.format(COLORS[code]) return first_bitty_bit + second_bitty_bit - + + def render_class(self, cls, args): + """ + Returns the result of the run_command method for the class passed. + """ + logger = Logger(cls.__name__, self.log_level) + try: + instance = cls(args=args, config=self.config, logger=logger, + parent=self) + except Exception as e: + self.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: + self.logger.error( + "Could not render line for {0}, failed with error {1}".format( + cls.__name__, e)) def main(): - global processes - processes = render(proccessCheck()) - parser = OptionParser( - usage='%prog [-c COLOR] [-s, --screenshot] [-d, --display]', - description="""Archey is a utility to take """, - version="%prog 0.2-1") - parser.add_option('-c', + 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', default='blue', type='choice', dest='color', choices=('black', 'red', @@ -639,22 +673,18 @@ def main(): cyan, white [Default: blue]""") parser.add_option('-s', '--screenshot', action='store_true', dest='screenshot', help='Take a screenshot') - parser.add_option('-d', '--display', - action='store', dest='display', - help="""Define info to be displayed by archey. DISPLAY - must be in the format "archey_display_module:arg1,arg2,arg - 3.second_display_module". Availible display modules are un - ame, fs, env, uptime, sensors, ram, de and wm. - See the DISPLAY list in the archey source file for more - info.""") + 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', dest='log_level', default=1) (options, args) = parser.parse_args() - if options.display: - global DISPLAY - DISPLAY = options.display.split('.') + config = ArcheyConfigParser() + config.read(options.config) - archey = Archey(display=DISPLAY, colorscheme=options.color) - archey.render() + archey = Archey(config=config, options=options) + print(archey.render()) if options.screenshot: screenshot() -- cgit v1.2.3 From aceca2905ed8ed7e72e15998b2f76a20ae8dfb94 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 6 Jun 2011 21:15:17 +0000 Subject: Fixed coloring in fsDisplay, added persentage option. Fixed xmonad detection --- archey3 | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/archey3 b/archey3 index d11a836..78cfcbc 100755 --- a/archey3 +++ b/archey3 @@ -107,7 +107,7 @@ WM_DICT = { 'wmfs': 'Wmfs', 'wmii': 'wmii', 'xfwm4': 'Xfwm', - 'xmonad': 'xmonad', + re.compile('xmonad-*'): 'xmonad', '': 'None', } @@ -184,8 +184,13 @@ class display(object): return '{0}{1}{2}'.format(self._parent.color(color), output, self._parent.color('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) @@ -194,16 +199,16 @@ class fsDisplay(display): conversions = { 'binary': { - 'KiB': 2 ** 10, - 'MiB': 2 ** 20, - 'GiB': 2 ** 30, - 'TiB': 2 ** 40, + 'K': 2 ** 10, + 'M': 2 ** 20, + 'G': 2 ** 30, + 'T': 2 ** 40, }, 'si': { - 'KB': 10 ** 3, - 'MB': 10 ** 6, - 'GB': 10 ** 9, - 'TB': 10 ** 12, + 'K': 10 ** 3, + 'M': 10 ** 6, + 'G': 10 ** 9, + 'T': 10 ** 12, }, } @@ -225,18 +230,25 @@ class fsDisplay(display): conversions = self.conversions[conversion_type] mount = '/root' if self.arg1 == '/' else self.arg1 - title = mount.split('/')[-1].title() + " FS" + title = mount.split('/')[-1].title() try: #convert to straight int used_ = int(used[:-1]) * conversions[used[-1].upper()] total_ = int(total[:-1]) * conversions[total[-1].upper()] persentage = used_ / total_ * 100 - except: - pass + except Exception as e: + self.logger.error( + "Could not colorize output, errored with {0}".format(e)) else: used = self.color_me(used, persentage) - part = '{used} / {total} ({fstype})'.format(used=used, total=total, - fstype=fstype) + + if self.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 class ramDisplay(display): -- cgit v1.2.3 From 7df468dc12a8178aa6235463526573fdbfd6152e Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 6 Jun 2011 21:21:39 +0000 Subject: Corrected incorrect default mpd port --- archey3 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 78cfcbc..186e334 100755 --- a/archey3 +++ b/archey3 @@ -155,6 +155,7 @@ class display(object): 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) @@ -443,7 +444,7 @@ class mpdDisplay(display): self.logger.error("Did not get any arguments, require one," + " the stat to display.") self.arg1 = self.config.get('mpd', 'host', fallback='localhost') - self.arg2 = self.config.getint('mpd', 'port', fallback=8800) + self.arg2 = self.config.getint('mpd', 'port', fallback=6600) def format_output(self, instring): lines = instring.split('\n') -- cgit v1.2.3 From c57f9d99c3805a218e0508275b7a746a2cbc8024 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 6 Jun 2011 14:50:38 -0700 Subject: github generated gh-pages branch --- index.html | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..59c1f09 --- /dev/null +++ b/index.html @@ -0,0 +1,79 @@ + + + + + + bluepeppers/archey3 @ GitHub + + + + + + Fork me on GitHub + +
+ +
+ + + + +
+ +

Archey3 + by bluepeppers

+ +
+ Simple python script to print the Archlinux logo with basic system information. +
+ +

Archey3 is a customisable system information printer aimed at people wishing to take screenshots of their desktops.

Dependencies

+

logbook, python, imagemagick (for screenshotting only)

+

Authors

+

Laurie Clark-Michalek (bluepeppers@archlinux.us)
Melik Manukyan (melik@archlinux.us)
unexist (unexist@dorfelite.net)

+

Contact

+

Laurie Clark-Michalek (bluepeppers@archlinux.us)

+ + +

Download

+

+ You can download this project in either + zip or + tar formats. +

+

You can also clone the project with Git + by running: +

$ git clone git://github.com/bluepeppers/archey3
+

+ + + +
+ + + + -- cgit v1.2.3 From 7becd2d8b7e1a1b9a4fb860b27c5ae25137fcc7a Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 6 Jun 2011 22:25:57 +0000 Subject: Added image of default config, along with changing up the default github page a bit. --- images/default_config.jpg | Bin 0 -> 39702 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 images/default_config.jpg diff --git a/images/default_config.jpg b/images/default_config.jpg new file mode 100644 index 0000000..7a46ee4 Binary files /dev/null and b/images/default_config.jpg differ -- cgit v1.2.3 From 7d4e05c4565094deeb6b35cbde4ebc90bac29e74 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 6 Jun 2011 22:30:14 +0000 Subject: Fixed gh-pages mixup --- index.html | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/index.html b/index.html index 59c1f09..e211acf 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - bluepeppers/archey3 @ GitHub + Archey3 - - - - Fork me on GitHub - -

Archey3 - by BluePeppers

- -
- Simple python script to print the Archlinux logo with basic system information. -
- -

Archey3 is a customisable system information printer aimed at people wishing to take screenshots of their desktops.

- - - -

Install

-

The recommened way of installing Archey3 is via the archlinux user repository. Using an AUR helper such as yaourt, install it with one command. However, if you do not have one installed, you can get it by running: -

-$ wget https://aur.archlinux.org/packages/archey3/archey3.tar.gz
-$ tar xfvz archey3.tar.gz
-$ cd archey3
-$ makepkg
-$ pacman -U archey3-*.pkg.tar.xz
- -You can then run Archey3 via -
$ archey
-or -
$ archey3
- -The above methods installs Archey3 from it's master git repo. If you wish to clone that repo to work on it, either fork it on github, or clone it by running: -
$ git clone git://github.com/bluepeppers/archey3
-

- -

Authors

-

Laurie Clark-Michalek (bluepeppers@archlinux.us)
Melik Manukyan (melik@archlinux.us)
unexist (unexist@dorfelite.net)
- - - - - - -- cgit v1.2.3 From 725f8d602a2b7c7d3941a772daa1ea2b11c21c15 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 6 Jun 2011 23:46:21 +0000 Subject: Removed obsoleat information from readme and header comments in archey3 --- README.md | 79 +-------------------------------------------------------------- archey3 | 8 ------- 2 files changed, 1 insertion(+), 86 deletions(-) diff --git a/README.md b/README.md index 902a205..24fe97a 100644 --- a/README.md +++ b/README.md @@ -1,81 +1,4 @@ Archey 3 ======== -Archey 3 is a system infomation printer, designed to be used when taking screenshots of computer desktops to provide additional infomation about the operating system setup. Archey is designed to be used for Arch linux, and it acordingly prints out the Arch linux logo along side the system infomation. - -Display Variables ------------------ - -Archey displays, as of 25/10/2010, the following by default: - -- Operating system -- Hostname -- Kernel Version -- Uptime -- Core temp (requires sensors) -- Window Manager -- Desktop Enviroment -- Number of packages installed -- Avalible Ram -- CPU Model -- Shell -- CLI Text Editor -- Number of songs in MPD library -- Space avalible on root filesystem - -The items that are displayed can be configured via -d|--display command line argument. Some examples are given below: - -archey3 -d 'ram.fs:/home.mpd:albums,localhost,8800.env:IP' - -would display the current ram usage, info on the /home partition, the number of mpd albums, and the IP adress env variable. - -The MPD Display function ------------------------- - -The MPD function takes the following arguments: - -1. Stat name. This can be songs, artists, albums -2. Hostname. Optional -3. Port Number. Optional. - -The Sensor Display function ---------------------------- - -The Sensor function takes the following argument: - -1. Sensors. This will be given as the first argument to the sensors binary, and the output will be parsed. - -The ENV Display function ------------------------- - -The ENV function takes the following argument: - -1. Variable name. The variable name will then be looked up via the genenv() function - -The uname Display function --------------------------- - -The uname function takes the following arguments: - -1. Flag. This can be one of: - - * a - System Infomation - * s - Kernel Name - * n - Hostname - * r - Kernel Release - * v - Kernel Version - * m - Machine Hardwear name - * p - Processor type - * i - Hardwear platform - -The File System Display function --------------------------------- - -The File System function takes the following arguments: - -1. Partition path. The path to the partition to display - -The WM/DE Display function --------------------------- - -The WM/DE Display function takes no arguments +Archey 3 is a system infomation printer, designed to be used when taking screenshots of computer desktops to provide additional infomation about the operating system setup. Archey is designed to be used for Arch linux, and it acordingly prints out the Arch linux logo along side the system infomation. \ No newline at end of file diff --git a/archey3 b/archey3 index 706a89e..cdbfbce 100755 --- a/archey3 +++ b/archey3 @@ -10,14 +10,6 @@ # Simple python script to display an Archlinux logo in ASCII art # Along with basic system information. -# Display [Comment/Uncomment to Enable/Disable information.] -# Protocols: -# uname:x = return output of `uname -x` (see UNAME_FLAG_MEANINGS for more info) -# sensors:x = return output of `sensors x` -# env:x = return value of env variable x -# fs:x = return space of partition at x -# mpd:stat,hostname,port = returns value of an mpd stat (options: artists|albums|songs) - # Import libraries import subprocess, optparse, re, sys, configparser from subprocess import Popen, PIPE -- cgit v1.2.3 From 2570aaa122cd564b3df24f65b03a6b02e093ce16 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 7 Jun 2011 00:50:32 +0000 Subject: Made logbook an optional dependency --- archey3 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/archey3 b/archey3 index cdbfbce..9887379 100755 --- a/archey3 +++ b/archey3 @@ -19,7 +19,16 @@ from time import ctime, sleep from os import getenv import re import os.path -from logbook import Logger + +try: + from logbook import Logger +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 UNAME_FLAG_MEANINGS = { 'a': 'System Infomation', -- cgit v1.2.3 From a7ccb2e66dc09d74f92f6f35844f014ff61320fb Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Thu, 9 Jun 2011 11:22:42 +0000 Subject: Corrected order of results when using bottom alignment --- archey3 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 9887379..5c69c4f 100755 --- a/archey3 +++ b/archey3 @@ -602,7 +602,8 @@ class Archey(object): if arrangement == "top": return results elif arrangement == "bottom": - return results[::-1] + 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) -- cgit v1.2.3 From 47501302d9c1055dbf8440bf2bbb2d4e81b5d7a4 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Thu, 9 Jun 2011 12:59:52 +0000 Subject: Added some logging to a couple of silent errors --- archey3 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/archey3 b/archey3 index 5c69c4f..800f12a 100755 --- a/archey3 +++ b/archey3 @@ -161,7 +161,7 @@ class display(object): self.process = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE) except Exception as e: - pass + self.logger.error("Could not run command {0}".format(cmd)) def render(self): (stdoutdata, stderrdata) = self.process.communicate(self.stdindata @@ -456,7 +456,8 @@ class mpdDisplay(display): stats['songs'] = lines[2].split(':')[1].strip() #if people don't have mpc installed then return None) except: - return False + self.logger.error("Could not parse mpc output, is mpc installed?") + return return ('{statname} in MPD database'.format(statname=self.stat.title()), stats[self.stat]) -- cgit v1.2.3 From a33c879fdb2015756a448f695abbe5502e5a312e Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sat, 11 Jun 2011 12:38:29 +0100 Subject: Fixed error with conversion from decimal string to int. --- archey3 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/archey3 b/archey3 index 800f12a..801cd11 100755 --- a/archey3 +++ b/archey3 @@ -234,13 +234,14 @@ class fsDisplay(display): mount = '/root' if self.arg1 == '/' else self.arg1 title = mount.split('/')[-1].title() try: - #convert to straight int - used_ = int(used[:-1]) * conversions[used[-1].upper()] - total_ = int(total[:-1]) * conversions[total[-1].upper()] + #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.logger.error( "Could not colorize output, errored with {0}".format(e)) + return else: used = self.color_me(used, persentage) -- cgit v1.2.3 From aff7528c635c73d888c6609fb6acf4a60444ff3b Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sat, 11 Jun 2011 12:51:04 +0100 Subject: Changed usage of the --debug option. --- archey3 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/archey3 b/archey3 index 801cd11..03a8ccb 100755 --- a/archey3 +++ b/archey3 @@ -21,7 +21,7 @@ import re import os.path try: - from logbook import Logger + from logbook import Logger, lookup_level except ImportError: class Logger(object): def __init__(self, name, level=0): @@ -29,6 +29,9 @@ except ImportError: 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', @@ -551,7 +554,7 @@ class Archey(object): def __init__(self, config, options): self.config = config - self.log_level = int(options.log_level) + self.log_level = lookup_level(options.log_level) self.logger = Logger("Core", self.log_level) self.display = config.get("core", "display_modules") @@ -714,7 +717,16 @@ def main(): action='store', dest='config', default=None, help="Set the location of the config file to load.") parser.add_option('--debug', - action='store', dest='log_level', default=1) + 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() -- cgit v1.2.3 From b8a72dc1c5e91dbb42efe95be9841a6582d2e867 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 12 Jun 2011 13:21:41 +0100 Subject: Made the bounds of the fs coloring config options; low_bound and medium_bound in the fs section --- archey3 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 03a8ccb..7a144ed 100755 --- a/archey3 +++ b/archey3 @@ -236,6 +236,10 @@ class fsDisplay(display): mount = '/root' if self.arg1 == '/' else self.arg1 title = mount.split('/')[-1].title() + + low = self.config.getint('fs', 'low_bound', fallback=40) + medium = self.config.getint('fs', 'medium_bound', fallback=70) + try: #convert to straight float used_ = float(used[:-1]) * conversions[used[-1].upper()] @@ -246,7 +250,7 @@ class fsDisplay(display): "Could not colorize output, errored with {0}".format(e)) return else: - used = self.color_me(used, persentage) + used = self.color_me(used, persentage, low=low, medium=medium) if self.config.getboolean("fs", "persentage", fallback=True): part = '{used} / {total} ({persentage}%) ({fstype})'.format( -- cgit v1.2.3 From 8ed5def21c30df5e98c22b34d863862bbc4be21b Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 12 Jun 2011 17:06:29 +0100 Subject: Fixed locale issue with decimal point. --- archey3 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/archey3 b/archey3 index 7a144ed..9fb6b58 100755 --- a/archey3 +++ b/archey3 @@ -227,9 +227,16 @@ class fsDisplay(display): raise 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.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] - total = values[2] + used = values[3].replace(decimal_point, '.') + total = values[2].replace(decimal_point, '.') fstype = values[1] conversion_type = self.config.get('fs', 'unit', fallback="si").lower() conversions = self.conversions[conversion_type] -- cgit v1.2.3 From 9844b633ed4947ac784c8aef30b4cec7090de326 Mon Sep 17 00:00:00 2001 From: dcelasun Date: Mon, 8 Aug 2011 12:43:34 +0300 Subject: Updated for Xfce 4.8 --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 archey3 diff --git a/archey3 b/archey3 old mode 100755 new mode 100644 index 9fb6b58..d04759a --- a/archey3 +++ b/archey3 @@ -83,7 +83,7 @@ CLASS_MAPPINGS = { DE_DICT = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', - 'xfce4-session': 'Xfce 4.6', + 'xfce4-session': 'Xfce 4.8', 'lxsession': 'LXDE', '': 'None', } -- cgit v1.2.3 From 41c0dfe5f8e6cb57bd82cc9229238911da4e1bb4 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 17 Aug 2011 22:33:35 +0100 Subject: Utilised the multiprocessing module to try and speed things up a bit. Added new config node, core.poolsize, to determine how large the process pool is, default=5. --- archey3 | 258 ++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 144 insertions(+), 114 deletions(-) diff --git a/archey3 b/archey3 index 9fb6b58..b0d7d2a 100755 --- a/archey3 +++ b/archey3 @@ -11,6 +11,7 @@ # Along with basic system information. # Import libraries +import collections import subprocess, optparse, re, sys, configparser from subprocess import Popen, PIPE from optparse import OptionParser @@ -19,6 +20,7 @@ from time import ctime, sleep from os import getenv import re import os.path +import multiprocessing try: from logbook import Logger, lookup_level @@ -78,6 +80,7 @@ CLASS_MAPPINGS = { 'env': 'envDisplay', 'fs': 'fsDisplay', 'mpd': 'mpdDisplay', + '_pc': 'processCheck' # Do _not_ use, internal only } @@ -126,17 +129,17 @@ COLORS = { 'white': '7' } +# State must be serializable +State = collections.namedtuple("State", "color config logger") + class display(object): command_line = '' - arg1 = '' - arg2 = '' - arg3 = '' stdindata = '' - def __init__(self, args, config, logger, parent=None): - self.config = config - self.logger = logger - self._parent = parent + 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): @@ -164,7 +167,7 @@ class display(object): self.process = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE) except Exception as e: - self.logger.error("Could not run command {0}".format(cmd)) + self.state.logger.error("Could not run command {0}".format(cmd)) def render(self): (stdoutdata, stderrdata) = self.process.communicate(self.stdindata @@ -180,14 +183,14 @@ class display(object): return output if number <= low: - color = low_color + color_= low_color elif low < number <= medium: - color = medium_color + color_ = medium_color elif medium < number: - color = high_color + color_ = high_color - return '{0}{1}{2}'.format(self._parent.color(color), output, - self._parent.color('clear')) + return '{0}{1}{2}'.format(color(self.state, color_), output, + color(self.state, 'clear')) regex_class = re.compile("").__class__ def process_exists(self, key): @@ -219,33 +222,31 @@ class fsDisplay(display): def __init__(self, **kwargs): super().__init__(**kwargs) - try: - self.arg1 = kwargs["args"][0] - except IndexError: - self.logger.error( - "Did not any arguments, require one, the fs to display") - raise + 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.logger.warning('Could not determine locale decimal point,' + + 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.config.get('fs', 'unit', fallback="si").lower() + 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.config.getint('fs', 'low_bound', fallback=40) - medium = self.config.getint('fs', 'medium_bound', fallback=70) + 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 @@ -253,13 +254,13 @@ class fsDisplay(display): total_ = float(total[:-1]) * conversions[total[-1].upper()] persentage = used_ / total_ * 100 except Exception as e: - self.logger.error( + 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.config.getboolean("fs", "persentage", fallback=True): + if self.state.config.getboolean("fs", "persentage", fallback=True): part = '{used} / {total} ({persentage}%) ({fstype})'.format( used=used, total=total, persentage=int(persentage), fstype=fstype) @@ -292,12 +293,12 @@ class sensorDisplay(display): def __init__(self, **kwargs): super().__init__(**kwargs) - arg_from_conf = self.config.get('sensor', 'sensor', + arg_from_conf = self.state.config.get('sensor', 'sensor', fallback='coretemp-*') try: arg_from_arg = kwargs["args"][0] except IndexError: - self.logger.error( + self.state.logger.error( "Did not get any arguments, require one, the sensor to display.") raise @@ -332,7 +333,7 @@ class envDisplay(display): try: self.arg1 = kwargs["args"][0] except IndexError: - self.logger.error("Did not get any arguments, require one," + + self.state.logger.error("Did not get any arguments, require one," + " the env variable to display.") raise @@ -351,11 +352,11 @@ class unameDisplay(display): try: flag = kwargs["args"][0] except IndexError: - self.logger.error("Did not get any arguments, require one," + + self.state.logger.error("Did not get any arguments, require one," + " the flag to pass to uname") raise - arg_from_conf = self.config.get('uname', 'argument', fallback="") + arg_from_conf = self.state.config.get('uname', 'argument', fallback="") arg_from_arg = flag if arg_from_arg: self.arg1 = '-' + arg_from_arg @@ -424,8 +425,8 @@ class processCheck(display): class wmDisplay(display): def render(self): - if self.config.get('wm', 'manual', fallback=False): - return "WM", self.config.get('wm', 'manual') + 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): @@ -435,8 +436,8 @@ class wmDisplay(display): class deDisplay(display): def render(self): - if self.config.get('de', 'manual', fallback=False): - return "DE", self.config.get('de', 'manual') + 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): @@ -457,10 +458,10 @@ class mpdDisplay(display): try: self.stat = kwargs["args"][0] except IndexError: - self.logger.error("Did not get any arguments, require one," + + self.state.logger.error("Did not get any arguments, require one," + " the stat to display.") - self.arg1 = self.config.get('mpd', 'host', fallback='localhost') - self.arg2 = self.config.getint('mpd', 'port', fallback=6600) + 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') @@ -471,7 +472,8 @@ class mpdDisplay(display): stats['songs'] = lines[2].split(':')[1].strip() #if people don't have mpc installed then return None) except: - self.logger.error("Could not parse mpc output, is mpc installed?") + self.state.logger.error( + "Could not parse mpc output, is mpc installed?") return return ('{statname} in MPD database'.format(statname=self.stat.title()), @@ -539,54 +541,112 @@ distro(), uname(n), uname(r), uptime(), wm(), de(), packages(), ram(),\ #------------ Functions ----------- def screenshot(): - print('Screenshotting in') - for x in sorted(range(1,6), 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!') + print('Screenshotting in') + for x in sorted(range(1,6), reverse=True): + print('%s' % x, end='') sys.stdout.flush() - try: - subprocess.check_call(['import', '-window', 'root', - ctime().replace(' ','_')+'.jpg']) - except subprocess.CalledProcessError as e: - print('Screenshot failed with return code {0}.'.format( + sleep(1.0/3) + for x in range(3): + print('.', end='') + sys.stdout.flush() + sleep(1.0/3) + + print('Say Cheese!') + sys.stdout.flush() + try: + subprocess.check_call(['import', '-window', 'root', + ctime().replace(' ','_')+'.jpg']) + except subprocess.CalledProcessError as e: + print('Screenshot failed with return code {0}.'.format( e.returncode)) +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 = globals()[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): - self.config = config - self.log_level = lookup_level(options.log_level) - self.logger = Logger("Core", self.log_level) + 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: - self.colorcode = COLORS[key] + colorcode = COLORS[key] + + self.state = State(colorcode, config, logger) global PROCESSES - PROCESSES = self.render_class(processCheck, ()) + PROCESSES = render_class(self.state, processCheck, ()) - self.distro_name = ' '.join( - self.render_class(distroCheck, ())[1].split()[:-1]) + 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 render(self): results = self.prepare_results() results = self.arrange_results(results) - return LOGOS[self.distro_name].format(c1=self.color(1), - c2=self.color(2), + return LOGOS[self.distro_name].format(c1=color(self.state, 1), + c2=color(self.state, 2), results = results ) @@ -596,25 +656,29 @@ class Archey(object): as a list. The returned list will be exactly 18 items long, with any left over spaces being filled with empty strings. """ - outputs = [] - # Run functions found in 'display' array. - for func_name, args in self.parse_display(): - cls = eval(CLASS_MAPPINGS[func_name]) - - line = self.render_class(cls, args) - if hasattr(line, "__iter__") and len(line) != 2: - outputs.extend(line) - elif line: - outputs.append(line) + 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))) + - outputs = [self.format_item(line) for line in outputs] return outputs + [""] * (18 - len(outputs)) def arrange_results(self, results): """ Arranges the results as specified in the config file. """ - arrangement = self.config.get("core", "align", fallback="top") + arrangement = self.state.config.get("core", "align", fallback="top") if arrangement == "top": return results elif arrangement == "bottom": @@ -638,7 +702,7 @@ class Archey(object): info = re.match(self.DISPLAY_PARSING_REGEX, func) if not info: - self.logger.error( + self.state.logger.error( "Could not parse display string {0}".format(func)) continue @@ -658,51 +722,17 @@ class Archey(object): #if we're dealing with a fraction if len(data.split('/')) == 2: numerator = data.split('/')[0] - numerator = (self.color(1, bold=True) + numerator + - self.color('clear')) + 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=self.color(1), + color=color(self.state, 1), title=title, data=data, - clear=self.color("clear") + clear=color(self.state, "clear") ) - - def color(self, code, bold=False): - 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(self.colorcode) - elif code == "clear": - return '\x1b[0m' - else: - second_bitty_bit = '3{0}m'.format(COLORS[code]) - - return first_bitty_bit + second_bitty_bit - - def render_class(self, cls, args): - """ - Returns the result of the run_command method for the class passed. - """ - logger = Logger(cls.__name__, self.log_level) - try: - instance = cls(args=args, config=self.config, logger=logger, - parent=self) - except Exception as e: - self.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: - self.logger.error( - "Could not render line for {0}, failed with error {1}".format( - cls.__name__, e)) def main(): parser = OptionParser( -- cgit v1.2.3 From eec554ef698fe148fcd46cd55da59b50557fce7b Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 17 Aug 2011 23:06:22 +0100 Subject: Added missing ArgumentError class. --- archey3 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/archey3 b/archey3 index b0d7d2a..78e5fb6 100755 --- a/archey3 +++ b/archey3 @@ -129,6 +129,11 @@ COLORS = { '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") -- cgit v1.2.3 From 71a6e06efa4db1c15cd6742cfe3e4bdaf6452761 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 17 Aug 2011 23:17:27 +0100 Subject: Let users choose the time before taking screenshot with the core.screenshotwait node. --- archey3 | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/archey3 b/archey3 index 78e5fb6..b047e36 100755 --- a/archey3 +++ b/archey3 @@ -545,9 +545,10 @@ distro(), uname(n), uname(r), uptime(), wm(), de(), packages(), ram(),\ #------------ Functions ----------- -def screenshot(): +def screenshot(state): print('Screenshotting in') - for x in sorted(range(1,6), reverse=True): + 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) @@ -562,8 +563,9 @@ def screenshot(): subprocess.check_call(['import', '-window', 'root', ctime().replace(' ','_')+'.jpg']) except subprocess.CalledProcessError as e: - print('Screenshot failed with return code {0}.'.format( + state.logger.critical('Screenshot failed with return code {0}.'.format( e.returncode)) + raise def color(state, code, bold=False): """ @@ -646,6 +648,15 @@ class Archey(object): 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) @@ -779,10 +790,7 @@ def main(): config.read(options.config) archey = Archey(config=config, options=options) - print(archey.render()) - - if options.screenshot: - screenshot() + archey.run(options.screenshot) if __name__ == "__main__": main() -- cgit v1.2.3 From 7b9596ab962df7491b387ccbd7590c6b1f19e4f6 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 17 Aug 2011 23:19:45 +0100 Subject: Bumped version number. --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index b047e36..9222833 100755 --- a/archey3 +++ b/archey3 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# archey3 [version 0.3] +# archey3 [version 0.4] # # Copyright 2010 Melik Manukyan # Copyright 2010-2011 Laurie Clark-Michalek -- cgit v1.2.3 From 448a92accfa525a61efd6c69dfe2c10cc202023f Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 17 Aug 2011 23:48:22 +0100 Subject: Fixed error with old coloring code in sensors module. --- archey3 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/archey3 b/archey3 index 9222833..d183d90 100755 --- a/archey3 +++ b/archey3 @@ -322,14 +322,14 @@ class sensorDisplay(display): value = info[1] intvalue = int(value[:3]) if intvalue > 45: - temp = (self._parent.color("red") + info[1] + - self._parent.color("clear")) + temp = (color(self.state, "red") + info[1] + + color(self.state, "clear")) elif intvalue in range(30, 45): - temp = (self._parent.color("magenta") + info[1] + - self._parent.color("clear")) + temp = (color(self.state, "magenta") + info[1] + + color(self.state, "clear")) else: - temp = (self._parent.color("green") + info[1] + - self._parent.color("clear")) + temp = (color(self.state, "green") + info[1] + + color(self.state, "clear")) out.append((info[0], temp)) return out -- cgit v1.2.3 From 0f28874277ad54483637bdee52267da4d5ff5c62 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Wed, 17 Aug 2011 23:59:16 +0100 Subject: Removed unused class mapping. --- archey3 | 1 - 1 file changed, 1 deletion(-) diff --git a/archey3 b/archey3 index d183d90..0ddb622 100755 --- a/archey3 +++ b/archey3 @@ -80,7 +80,6 @@ CLASS_MAPPINGS = { 'env': 'envDisplay', 'fs': 'fsDisplay', 'mpd': 'mpdDisplay', - '_pc': 'processCheck' # Do _not_ use, internal only } -- cgit v1.2.3 From 49782c7484cdfff6c546c36cc6f0c718a552f1d7 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Thu, 18 Aug 2011 00:03:40 +0100 Subject: Bumped version number in setup.py. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 349288a..b1986b5 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ def read(fname): setup( name="Archey3", - version="0.3", + version="0.4", author="Laurie Clark-Michalek", author_email="bluepeppers@archlinux.us", description="A simple python scrip to display an Archlinux logo in ASCII art along with basic system information.", -- cgit v1.2.3 From c456eaae5942ff31f491ec5e06cbe6494629fc93 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Thu, 18 Aug 2011 12:00:10 +0100 Subject: Replaced static dictionary with class decorator. --- archey3 | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/archey3 b/archey3 index 846ac07..45f00dd 100644 --- a/archey3 +++ b/archey3 @@ -68,20 +68,16 @@ LOGOS = {'Arch Linux': '''{c1} \x1b[0m''' } -CLASS_MAPPINGS = { - 'distro': 'distroCheck', - 'uname': 'unameDisplay', - 'uptime': 'uptimeDisplay', - 'sensors': 'sensorDisplay', - 'wm': 'wmDisplay', - 'de': 'deDisplay', - 'packages': 'packageDisplay', - 'ram': 'ramDisplay', - 'env': 'envDisplay', - 'fs': 'fsDisplay', - 'mpd': 'mpdDisplay', -} +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 = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', @@ -206,6 +202,7 @@ class display(object): return PROCESSES(key) +@module_register("fs") class fsDisplay(display): command_line = "df -TPh {arg1}" @@ -273,6 +270,7 @@ class fsDisplay(display): used=used, total=total, fstype=fstype) return title, part +@register_module("ram") class ramDisplay(display): command_line = "free -m" @@ -291,6 +289,7 @@ class ramDisplay(display): part = '{used} / {total} MB'.format(used=used, total=total) return title, part +@register_module("sensor") class sensorDisplay(display): command_line = "sensors {arg1}" @@ -332,6 +331,7 @@ class sensorDisplay(display): out.append((info[0], temp)) return out +@register_module("env") class envDisplay(display): def __init__(self, **kwargs): try: @@ -347,6 +347,7 @@ class envDisplay(display): argvalue = getenv(self.arg1.upper()) return ('$' + self.arg1.upper(), argvalue) +@register_module("uname") class unameDisplay(display): command_line = "uname {arg1}" @@ -372,6 +373,7 @@ class unameDisplay(display): def format_output(self, instring): return (UNAME_FLAG_MEANINGS[self.arg1[1]], instring) +@register_module("uptime") class uptimeDisplay(display): def render(self): with open("/proc/uptime") as upfile: @@ -390,12 +392,14 @@ class uptimeDisplay(display): ) return "Uptime", uptime +@register_module("package") class packageDisplay(display): command_line = "pacman -Q" def format_output(self, instring): return "Packages", len(instring.split('\n')) +@register_module("distro") class distroCheck(display): def render(self): try: @@ -407,6 +411,7 @@ class distroCheck(display): distro = '{0} {1}'.format(distro, self.call_command("uname -m")) return "OS", distro +@register_module("process") class processCheck(display): command_line = "ps -u {arg1}" @@ -427,6 +432,7 @@ class processCheck(display): return True return False +@register_module("wm") class wmDisplay(display): def render(self): if self.state.config.get('wm', 'manual', fallback=False): @@ -438,6 +444,7 @@ class wmDisplay(display): break return "WM", WM_DICT[wm] +@register_module("de") class deDisplay(display): def render(self): if self.state.config.get('de', 'manual', fallback=False): @@ -449,6 +456,7 @@ class deDisplay(display): break return "DE", DE_DICT[de] +@register_module("mpd") class mpdDisplay(display): """ Displays certain stat about MPD database. If mpd not installed, output @@ -591,7 +599,7 @@ def _mp_render_helper(container): state = container["state"] cls_name = container["cls_name"] args = container["args"] - cls = globals()[CLASS_MAPPINGS[cls_name]] + cls = CLASS_MAPPINGS[cls_name] return render_class(state, cls, args) def render_class(state, cls, args): -- cgit v1.2.3 From 8f81febccbb6058b67052618788920206ecf016b Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 4 Sep 2011 16:26:30 +0100 Subject: Added core.screenshot_command config option, and fixed some incorrectly named decorators. --- archey3 | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/archey3 b/archey3 index 45f00dd..287ab79 100644 --- a/archey3 +++ b/archey3 @@ -270,7 +270,7 @@ class fsDisplay(display): used=used, total=total, fstype=fstype) return title, part -@register_module("ram") +@module_register("ram") class ramDisplay(display): command_line = "free -m" @@ -289,7 +289,7 @@ class ramDisplay(display): part = '{used} / {total} MB'.format(used=used, total=total) return title, part -@register_module("sensor") +@module_register("sensor") class sensorDisplay(display): command_line = "sensors {arg1}" @@ -331,7 +331,7 @@ class sensorDisplay(display): out.append((info[0], temp)) return out -@register_module("env") +@module_register("env") class envDisplay(display): def __init__(self, **kwargs): try: @@ -347,7 +347,7 @@ class envDisplay(display): argvalue = getenv(self.arg1.upper()) return ('$' + self.arg1.upper(), argvalue) -@register_module("uname") +@module_register("uname") class unameDisplay(display): command_line = "uname {arg1}" @@ -373,7 +373,7 @@ class unameDisplay(display): def format_output(self, instring): return (UNAME_FLAG_MEANINGS[self.arg1[1]], instring) -@register_module("uptime") +@module_register("uptime") class uptimeDisplay(display): def render(self): with open("/proc/uptime") as upfile: @@ -392,14 +392,14 @@ class uptimeDisplay(display): ) return "Uptime", uptime -@register_module("package") +@module_register("package") class packageDisplay(display): command_line = "pacman -Q" def format_output(self, instring): return "Packages", len(instring.split('\n')) -@register_module("distro") +@module_register("distro") class distroCheck(display): def render(self): try: @@ -411,7 +411,7 @@ class distroCheck(display): distro = '{0} {1}'.format(distro, self.call_command("uname -m")) return "OS", distro -@register_module("process") +@module_register("process") class processCheck(display): command_line = "ps -u {arg1}" @@ -432,7 +432,7 @@ class processCheck(display): return True return False -@register_module("wm") +@module_register("wm") class wmDisplay(display): def render(self): if self.state.config.get('wm', 'manual', fallback=False): @@ -444,7 +444,7 @@ class wmDisplay(display): break return "WM", WM_DICT[wm] -@register_module("de") +@module_register("de") class deDisplay(display): def render(self): if self.state.config.get('de', 'manual', fallback=False): @@ -456,7 +456,7 @@ class deDisplay(display): break return "DE", DE_DICT[de] -@register_module("mpd") +@module_register("mpd") class mpdDisplay(display): """ Displays certain stat about MPD database. If mpd not installed, output @@ -566,9 +566,15 @@ def screenshot(state): print('Say Cheese!') sys.stdout.flush() + + screenshot_command = state.config.get('core', 'screenshot_command', + fallback="import -window root .jpg") + print(screenshot_command) + sys.stdout.flush() try: - subprocess.check_call(['import', '-window', 'root', - ctime().replace(' ','_')+'.jpg']) + 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)) -- cgit v1.2.3 From b5a47cf8a2df43523b3ceac52d5fe6937a77aa8c Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 4 Sep 2011 16:30:38 +0100 Subject: Corrected typo in package module registration --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 287ab79..2f7e47c 100644 --- a/archey3 +++ b/archey3 @@ -392,7 +392,7 @@ class uptimeDisplay(display): ) return "Uptime", uptime -@module_register("package") +@module_register("packages") class packageDisplay(display): command_line = "pacman -Q" -- cgit v1.2.3 From 12a55ee6e3451223a40af7bcef7242478e485b21 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 4 Sep 2011 16:31:11 +0100 Subject: Removed print statement --- archey3 | 2 -- 1 file changed, 2 deletions(-) diff --git a/archey3 b/archey3 index 2f7e47c..d5b8af5 100644 --- a/archey3 +++ b/archey3 @@ -569,8 +569,6 @@ def screenshot(state): screenshot_command = state.config.get('core', 'screenshot_command', fallback="import -window root .jpg") - print(screenshot_command) - sys.stdout.flush() try: subprocess.check_call( screenshot_command.replace('', -- cgit v1.2.3 From 6919be81b4d6579b77873c7040919d6d1f0696ad Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 4 Sep 2011 16:35:04 +0100 Subject: Added PKGBUILD to master, and made imagemagick a optdepend. --- PKGBUILD | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 PKGBUILD diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..cb8de05 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,44 @@ +# Maintainer: Laurie Clark-Michalek + +pkgname=archey3 +pkgver=20110612 +pkgrel=1 +pkgdesc="Python script to display system infomation alongside Arch Linux logo" +arch=('any') +url="http://bluepeppers.github.com/archey3" +license=('GPL') +depends=('python' 'imagemagick') +makedepends=('git' 'python-distribute') +optdepends=( + 'python3-mpd-git: python mpd libary for mpd protocol (optional, mpc can be used instead)' + 'python-logbook-git: for logging' + 'imagemagick: for default screenshot command' +) +conflicts=('archey') +provides=('archey') +md5sums=() + +_gitroot="git://github.com/bluepeppers/archey3.git" +_gitname="archey3" + +build() { + cd ${srcdir} + msg "Connecting to GIT server...." + + if [ -d archey3 ] ; then + cd archey3 && git pull origin + msg "The local files are updated." + else + git clone ${_gitroot} + fi + + msg "GIT checkout done or server timeout" + msg "Starting make..." + + cd ${srcdir}/${_gitname} + + python setup.py install --root=${pkgdir} + # Comment line below to install side by side with standard archey + ln -s /usr/bin/archey3 ${pkgdir}/usr/bin/archey || return 1 + install -D -m644 COPYING ${pkgdir}/usr/share/licenses/archey/COPYING +} -- cgit v1.2.3 From 30f77165c1712bee8b267a7189229d4d52a83a22 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 4 Sep 2011 16:38:13 +0100 Subject: Bumped version in pkgbuild and fixed typo. --- PKGBUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index cb8de05..e2d8bcd 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,9 +1,9 @@ # Maintainer: Laurie Clark-Michalek pkgname=archey3 -pkgver=20110612 +pkgver=20110904 pkgrel=1 -pkgdesc="Python script to display system infomation alongside Arch Linux logo" +pkgdesc="Python script to display system infomation alongside the Arch Linux logo" arch=('any') url="http://bluepeppers.github.com/archey3" license=('GPL') -- cgit v1.2.3 From 54793724154b75cd0b56c6a0114a4a89422d8393 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sun, 4 Sep 2011 16:40:45 +0100 Subject: Remove imagemagick from actual depends --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index e2d8bcd..cf5db2f 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -7,7 +7,7 @@ pkgdesc="Python script to display system infomation alongside the Arch Linux log arch=('any') url="http://bluepeppers.github.com/archey3" license=('GPL') -depends=('python' 'imagemagick') +depends=('python') makedepends=('git' 'python-distribute') optdepends=( 'python3-mpd-git: python mpd libary for mpd protocol (optional, mpc can be used instead)' -- cgit v1.2.3 From 4fdbe594a591a584f25cc6007de336a441db1e37 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sat, 17 Sep 2011 21:16:20 +0100 Subject: Added support for the Emerald window manager --- archey3 | 1 + 1 file changed, 1 insertion(+) diff --git a/archey3 b/archey3 index d5b8af5..c1c1550 100644 --- a/archey3 +++ b/archey3 @@ -109,6 +109,7 @@ WM_DICT = { 'wmfs': 'Wmfs', 'wmii': 'wmii', 'xfwm4': 'Xfwm', + 'emerald': 'Emerald', re.compile('xmonad-*'): 'xmonad', '': 'None', } -- cgit v1.2.3 From 6f0ee7e05bd1b1531ff567a72499f4c7c7d2b9b3 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sat, 17 Sep 2011 21:28:58 +0100 Subject: Fixed processes detection. --- archey3 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/archey3 b/archey3 index c1c1550..666a9eb 100644 --- a/archey3 +++ b/archey3 @@ -110,7 +110,7 @@ WM_DICT = { 'wmii': 'wmii', 'xfwm4': 'Xfwm', 'emerald': 'Emerald', - re.compile('xmonad-*'): 'xmonad', + 'xmonad': 'xmonad', '': 'None', } @@ -425,8 +425,18 @@ class processCheck(display): def run_command(self): super().run_command() out = str(self.process.communicate()[0]) - self._processes = set([line.split()[3] for line in out.split('\\n') if\ - len(line.split()) == 4]) + + self._processes = set() + for line in out.split("\\n"): + words = line.split() + if len(words) <= 10: + continue + + # Ignore the wrapper command + if words[10] == 'ck-launch-session': + words[10] = words[11] + + self._processes.add(words[10]) def __call__(self, proc): if proc in self._processes: -- cgit v1.2.3 From 824678651b0d447f76992754a58714e61c7ee5bc Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sat, 17 Sep 2011 22:19:37 +0100 Subject: Fixed actual problem with process check module --- archey3 | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/archey3 b/archey3 index 666a9eb..4acb7c4 100644 --- a/archey3 +++ b/archey3 @@ -414,29 +414,24 @@ class distroCheck(display): @module_register("process") class processCheck(display): - command_line = "ps -u {arg1}" + command_line = "ps -u " + getuser() render = lambda self: self - def __init__(self, **kwargs): - self.arg1 = getuser() - super().__init__(**kwargs) - def run_command(self): super().run_command() out = str(self.process.communicate()[0]) self._processes = set() + import pdb; pdb.set_trace() for line in out.split("\\n"): + print(line) words = line.split() - if len(words) <= 10: + if len(words) <= 3: continue - # Ignore the wrapper command - if words[10] == 'ck-launch-session': - words[10] = words[11] - - self._processes.add(words[10]) + self._processes.add(words[3]) + print(self._processes) def __call__(self, proc): if proc in self._processes: -- cgit v1.2.3 From c1611744f9023511497ba8b3300d173e36d93b8e Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sat, 17 Sep 2011 22:21:50 +0100 Subject: Reversed problem with xmonad --- archey3 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/archey3 b/archey3 index 4acb7c4..d9cf468 100644 --- a/archey3 +++ b/archey3 @@ -110,7 +110,7 @@ WM_DICT = { 'wmii': 'wmii', 'xfwm4': 'Xfwm', 'emerald': 'Emerald', - 'xmonad': 'xmonad', + re.compile('xmonad-*'): 'xmonad', '': 'None', } @@ -423,15 +423,12 @@ class processCheck(display): out = str(self.process.communicate()[0]) self._processes = set() - import pdb; pdb.set_trace() for line in out.split("\\n"): - print(line) words = line.split() if len(words) <= 3: continue self._processes.add(words[3]) - print(self._processes) def __call__(self, proc): if proc in self._processes: -- cgit v1.2.3 From a27064dd281554b5d4caaf56238aa13f697e964e Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sat, 17 Sep 2011 23:31:15 +0100 Subject: Moved Compiz priority down --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index d9cf468..9dbdebc 100644 --- a/archey3 +++ b/archey3 @@ -90,7 +90,6 @@ WM_DICT = { 'awesome': 'Awesome', 'beryl': 'Beryl', 'blackbox': 'Blackbox', - 'compiz': 'Compiz', 'dwm': 'DWM', 'enlightenment': 'Enlightenment', 'fluxbox': 'Fluxbox', @@ -110,6 +109,7 @@ WM_DICT = { 'wmii': 'wmii', 'xfwm4': 'Xfwm', 'emerald': 'Emerald', + 'compiz': 'Compiz', re.compile('xmonad-*'): 'xmonad', '': 'None', } -- cgit v1.2.3 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 From d48293ff49d9b8d8d8a105f418f511f20ac7715b Mon Sep 17 00:00:00 2001 From: graysky Date: Thu, 17 May 2012 19:28:03 -0400 Subject: updated for xfce4 v4.10 --- PKGBUILD | 2 +- archey3 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index cf5db2f..67dca13 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Laurie Clark-Michalek pkgname=archey3 -pkgver=20110904 +pkgver=20120517 pkgrel=1 pkgdesc="Python script to display system infomation alongside the Arch Linux logo" arch=('any') diff --git a/archey3 b/archey3 index 9dbdebc..4684880 100644 --- a/archey3 +++ b/archey3 @@ -81,7 +81,7 @@ def module_register(name): DE_DICT = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', - 'xfce4-session': 'Xfce 4.8', + 'xfce4-session': 'Xfce 4.10', 'lxsession': 'LXDE', '': 'None', } -- cgit v1.2.3 From 4201af9d8597dd4151d9d4335103ae972030a299 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 10 Aug 2012 09:04:09 +0100 Subject: Added cpu module as uname -p no longer works. Fixes #8 --- archey3 | 177 ++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 94 insertions(+), 83 deletions(-) diff --git a/archey3 b/archey3 index 4684880..226c08d 100644 --- a/archey3 +++ b/archey3 @@ -3,11 +3,11 @@ # archey3 [version 0.4] # # Copyright 2010 Melik Manukyan -# Copyright 2010-2011 Laurie Clark-Michalek +# 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 +# Simple python script to display an Archlinux logo in ASCII art # Along with basic system information. # Import libraries @@ -31,7 +31,7 @@ except ImportError: self.level = level debug = info = warn = warning = notice = error = exception = \ critical = log = lambda *a, **kw: None - + def lookup_level(_): return 0 @@ -63,7 +63,7 @@ LOGOS = {'Arch Linux': '''{c1} {c2} #########. .########` {results[13]} {c2} ######' '###### {results[14]} {c2} ;#### ####; {results[15]} -{c2} ##' '## {results[16]} +{c2} ##' '## {results[16]} {c2} #' `# {results[17]} \x1b[0m''' } @@ -85,7 +85,7 @@ DE_DICT = {'gnome-session': 'GNOME', 'lxsession': 'LXDE', '': 'None', } - + WM_DICT = { 'awesome': 'Awesome', 'beryl': 'Beryl', @@ -136,12 +136,12 @@ 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): """ @@ -151,7 +151,7 @@ class display(object): 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: @@ -163,36 +163,36 @@ class display(object): 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 @@ -206,7 +206,7 @@ class display(object): @module_register("fs") class fsDisplay(display): command_line = "df -TPh {arg1}" - + conversions = { 'binary': { 'K': 2 ** 10, @@ -221,14 +221,14 @@ class fsDisplay(display): '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( @@ -243,13 +243,13 @@ class fsDisplay(display): 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 + + 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()] @@ -261,7 +261,7 @@ class fsDisplay(display): 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), @@ -274,7 +274,7 @@ class fsDisplay(display): @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() @@ -289,11 +289,11 @@ class ramDisplay(display): 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) @@ -305,15 +305,15 @@ class sensorDisplay(display): 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\ @@ -341,9 +341,9 @@ class envDisplay(display): 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) @@ -351,17 +351,17 @@ class envDisplay(display): @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: @@ -370,17 +370,28 @@ class unameDisplay(display): 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) @@ -396,7 +407,7 @@ class uptimeDisplay(display): @module_register("packages") class packageDisplay(display): command_line = "pacman -Q" - + def format_output(self, instring): return "Packages", len(instring.split('\n')) @@ -415,26 +426,26 @@ class distroCheck(display): @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): @@ -466,10 +477,10 @@ class mpdDisplay(display): nothing. """ command_line = "mpc stats --host {arg1} --port {arg2}" - + def __init__(self, **kwargs): super().__init__(**kwargs) - + try: self.stat = kwargs["args"][0] except IndexError: @@ -477,7 +488,7 @@ class mpdDisplay(display): " 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 = {} @@ -490,7 +501,7 @@ class mpdDisplay(display): 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]) @@ -506,10 +517,10 @@ class ArcheyConfigParser(configparser.SafeConfigParser): 'display_modules': """\ distro(), uname(n), uname(r), uptime(), wm(), de(), packages(), ram(),\ - uname(p), env(editor), fs(/), mpd(albums)""" + cpu(), env(editor), fs(/), mpd(albums)""" }, } - + def read(self, file_location=None): """ Loads the config options stored in at file_location. If file_location @@ -517,12 +528,12 @@ distro(), uname(n), uname(r), uptime(), wm(), de(), packages(), ram(),\ ($XDG_CONFIG_HOME/archey3.cfg). If that does not exist, it will write a default config file to $XDG_CONFIG_HOME/archey3.cfg. """ - + config_location = os.path.expandvars(os.path.expanduser( file_location or "$XDG_CONFIG_HOME/archey3.cfg")) - + loaded = super(ArcheyConfigParser, self).read(config_location) - + if file_location == None and not loaded: self.load_default_config() self.write_config(config_location) @@ -539,7 +550,7 @@ distro(), uname(n), uname(r), uptime(), wm(), de(), packages(), ram(),\ 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) @@ -551,7 +562,7 @@ distro(), uname(n), uname(r), uptime(), wm(), de(), packages(), ram(),\ """ with open(location, 'w') as configfile: self.write(configfile) - + #------------ Functions ----------- @@ -566,11 +577,11 @@ def screenshot(state): print('.', end='') sys.stdout.flush() sleep(1.0/3) - + print('Say Cheese!') sys.stdout.flush() - - screenshot_command = state.config.get('core', 'screenshot_command', + + screenshot_command = state.config.get('core', 'screenshot_command', fallback="import -window root .jpg") try: subprocess.check_call( @@ -618,7 +629,7 @@ def render_class(state, cls, args): 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( @@ -636,50 +647,50 @@ def render_class(state, cls, args): 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), c2=color(self.state, 2), results = results ) - + def prepare_results(self): """ Renders all classes found in the display array, and then returns them @@ -687,9 +698,9 @@ class Archey(object): 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({ @@ -700,10 +711,10 @@ class Archey(object): 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. @@ -721,7 +732,7 @@ class Archey(object): [""] * (len(results) - len(actuall_res))) else: return results - + def parse_display(self): """ Iterates over the display attribute of the Archey class, and tries to @@ -729,26 +740,26 @@ class Archey(object): """ 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] @@ -756,7 +767,7 @@ class Archey(object): 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, @@ -799,10 +810,10 @@ def main(): 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) -- cgit v1.2.3 From 61d48e0d6533ca6c394a1c569309026790b21021 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 10 Aug 2012 09:05:07 +0100 Subject: Removed version number from xfce output --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 226c08d..a3681d3 100644 --- a/archey3 +++ b/archey3 @@ -81,7 +81,7 @@ def module_register(name): DE_DICT = {'gnome-session': 'GNOME', 'ksmserver': 'KDE', - 'xfce4-session': 'Xfce 4.10', + 'xfce4-session': 'Xfce', 'lxsession': 'LXDE', '': 'None', } -- cgit v1.2.3 From 5b78b86ce9b9508b926e612181ceccd8ad1965a1 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 7 Sep 2012 03:39:54 +0100 Subject: Made the archey3 file executable --- archey3 | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 archey3 diff --git a/archey3 b/archey3 old mode 100644 new mode 100755 -- cgit v1.2.3 From d8030d41eb690f8fa6ec4223c218462f50ada2a7 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 7 Sep 2012 22:54:57 +0100 Subject: Moved to ordered dicts to allow DE & WMs to have priority and added cinnamon support --- archey3 | 70 +++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/archey3 b/archey3 index a3681d3..38bced6 100755 --- a/archey3 +++ b/archey3 @@ -79,40 +79,42 @@ def module_register(name): return cls return decorator -DE_DICT = {'gnome-session': 'GNOME', - 'ksmserver': 'KDE', - 'xfce4-session': 'Xfce', - 'lxsession': 'LXDE', - '': 'None', -} - -WM_DICT = { - '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', - 'wmaker': 'Window Maker', - 'wmfs': 'Wmfs', - 'wmii': 'wmii', - 'xfwm4': 'Xfwm', - 'emerald': 'Emerald', - 'compiz': 'Compiz', - re.compile('xmonad-*'): 'xmonad', - '': 'None', -} +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'), + ('wmaker', 'Window Maker'), + ('wmfs', 'Wmfs'), + ('wmii', 'wmii'), + ('xfwm4', 'Xfwm'), + ('emerald', 'Emerald'), + ('compiz', 'Compiz'), + (re.compile('xmonad-*'), 'xmonad'), + ('', 'None'), + ]) COLORS = { 'black': '0', -- cgit v1.2.3 From b6f93f0975071ad91f4511062923673a5267ea7c Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Sat, 8 Sep 2012 04:20:34 +0100 Subject: Added qtile support --- archey3 | 1 + 1 file changed, 1 insertion(+) diff --git a/archey3 b/archey3 index 38bced6..784c0d3 100755 --- a/archey3 +++ b/archey3 @@ -113,6 +113,7 @@ WM_DICT = collections.OrderedDict([ ('emerald', 'Emerald'), ('compiz', 'Compiz'), (re.compile('xmonad-*'), 'xmonad'), + ('qtile', 'QTile'), ('', 'None'), ]) -- cgit v1.2.3 From 25d7e3baf1271a74bbd58ea9ab45a59b83e3bf83 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Mon, 10 Sep 2012 16:34:08 +0100 Subject: Remove executable bit on COPYING --- COPYING | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 COPYING diff --git a/COPYING b/COPYING old mode 100755 new mode 100644 -- cgit v1.2.3 From 4aa50d3f14c35f955755aeef14eda398905ba067 Mon Sep 17 00:00:00 2001 From: Neil Perry Date: Sat, 20 Oct 2012 22:52:37 +0200 Subject: Add MonsterWM WM. --- archey3 | 1 + 1 file changed, 1 insertion(+) diff --git a/archey3 b/archey3 index 784c0d3..a6c17b5 100755 --- a/archey3 +++ b/archey3 @@ -106,6 +106,7 @@ WM_DICT = collections.OrderedDict([ ('ratpoison', 'ratpoison'), ('scrotwm', 'ScrotWM'), ('subtle', 'subtle'), + ('monsterwm', 'MonsterWM'), ('wmaker', 'Window Maker'), ('wmfs', 'Wmfs'), ('wmii', 'wmii'), -- cgit v1.2.3 From db0dd9c630bce6ba460499e51a2a581fa2f4260b Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 25 Dec 2012 16:43:22 +0000 Subject: Fixed problem for people without XDG_CONFIG_HOME --- archey3 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/archey3 b/archey3 index 784c0d3..b04a815 100755 --- a/archey3 +++ b/archey3 @@ -532,8 +532,13 @@ distro(), uname(n), uname(r), uptime(), wm(), de(), packages(), ram(),\ default config file to $XDG_CONFIG_HOME/archey3.cfg. """ - config_location = os.path.expandvars(os.path.expanduser( - file_location or "$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) -- cgit v1.2.3 From 712599851ef4d51e8b97e62488edca6ebda52ad7 Mon Sep 17 00:00:00 2001 From: Mike Frampton Date: Thu, 9 May 2013 23:26:30 +1200 Subject: Added an extra output. Can now print the time since the last full system upgrade. --- archey3 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/archey3 b/archey3 index 3fe7436..536fb66 100755 --- a/archey3 +++ b/archey3 @@ -18,6 +18,7 @@ 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 @@ -509,6 +510,34 @@ class mpdDisplay(display): 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): -- cgit v1.2.3 From d61166a0e31bc9160c95c5ea79d001e6f7f4315a Mon Sep 17 00:00:00 2001 From: graysky Date: Sun, 9 Jun 2013 11:52:13 -0400 Subject: updated PKGBUILD for pacman 4.x --- PKGBUILD | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 67dca13..fa39e56 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,44 +1,33 @@ # Maintainer: Laurie Clark-Michalek +# Contributer: graysky pkgname=archey3 -pkgver=20120517 +pkgver=0.4.29.gb4cc4bb pkgrel=1 -pkgdesc="Python script to display system infomation alongside the Arch Linux logo" +pkgdesc="Python script to display system infomation alongside the Arch Linux logo." arch=('any') url="http://bluepeppers.github.com/archey3" license=('GPL') depends=('python') makedepends=('git' 'python-distribute') optdepends=( - 'python3-mpd-git: python mpd libary for mpd protocol (optional, mpc can be used instead)' - 'python-logbook-git: for logging' - 'imagemagick: for default screenshot command' +'python3-mpd-git: python mpd libary for mpd protocol (optional, mpc can be used instead)' +'python-logbook-git: for logging' +'imagemagick: for default screenshot command' ) conflicts=('archey') provides=('archey') -md5sums=() +source="git://github.com/bluepeppers/archey3.git" +md5sums=('SKIP') -_gitroot="git://github.com/bluepeppers/archey3.git" -_gitname="archey3" - -build() { - cd ${srcdir} - msg "Connecting to GIT server...." - - if [ -d archey3 ] ; then - cd archey3 && git pull origin - msg "The local files are updated." - else - git clone ${_gitroot} - fi - - msg "GIT checkout done or server timeout" - msg "Starting make..." - - cd ${srcdir}/${_gitname} +pkgver() { + cd ${pkgname} + git describe --always | sed 's|-|.|g' +} +package() { + cd ${pkgname} python setup.py install --root=${pkgdir} - # Comment line below to install side by side with standard archey - ln -s /usr/bin/archey3 ${pkgdir}/usr/bin/archey || return 1 - install -D -m644 COPYING ${pkgdir}/usr/share/licenses/archey/COPYING + ln -s /usr/bin/archey3 ${pkgdir}/usr/bin/archey + install -D -m644 COPYING ${pkgdir}/usr/share/licenses/archey/COPYING } -- cgit v1.2.3 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 From ce8a6a27414f0519b464d3855b75684afec603a8 Mon Sep 17 00:00:00 2001 From: Adam Jimerson Date: Tue, 16 Jul 2013 14:41:57 -0400 Subject: Add Wingo to WM collection Added Wingo to the WM_DICT collection. --- archey3 | 1 + 1 file changed, 1 insertion(+) diff --git a/archey3 b/archey3 index 536fb66..608d715 100755 --- a/archey3 +++ b/archey3 @@ -116,6 +116,7 @@ WM_DICT = collections.OrderedDict([ ('compiz', 'Compiz'), (re.compile('xmonad-*'), 'xmonad'), ('qtile', 'QTile'), + ('wingo', 'Wingo'), ('', 'None'), ]) -- cgit v1.2.3 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 From 712cd0827d7ebd56b24474e1d11d867d028786a2 Mon Sep 17 00:00:00 2001 From: feivel Date: Fri, 13 Sep 2013 23:44:09 -0400 Subject: Fix overreported installed package count. --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 608d715..734cc56 100755 --- a/archey3 +++ b/archey3 @@ -415,7 +415,7 @@ class packageDisplay(display): command_line = "pacman -Q" def format_output(self, instring): - return "Packages", len(instring.split('\n')) + return "Packages", len(instring.rstrip('\n').split('\n')) @module_register("distro") class distroCheck(display): -- cgit v1.2.3 From d44b1c55b9b26851b8b40442326bef5ca11810f0 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 1 Nov 2013 16:11:49 +0000 Subject: Bumped version to 0.5 --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 734cc56..88b32c3 100755 --- a/archey3 +++ b/archey3 @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# archey3 [version 0.4] +# archey3 [version 0.5] # # Copyright 2010 Melik Manukyan # Copyright 2010-2012 Laurie Clark-Michalek -- cgit v1.2.3 From c1d1fedccc843ada034d7bcbfe89d00cfc58fea3 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Fri, 1 Nov 2013 16:13:13 +0000 Subject: Updated PKGBUILD --- PKGBUILD | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index fa39e56..2ac5d14 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -2,7 +2,7 @@ # Contributer: graysky pkgname=archey3 -pkgver=0.4.29.gb4cc4bb +pkgver=0.5 pkgrel=1 pkgdesc="Python script to display system infomation alongside the Arch Linux logo." arch=('any') @@ -11,7 +11,7 @@ license=('GPL') depends=('python') makedepends=('git' 'python-distribute') optdepends=( -'python3-mpd-git: python mpd libary for mpd protocol (optional, mpc can be used instead)' +'python-mpd-git: python libary for mpd interaction', 'python-logbook-git: for logging' 'imagemagick: for default screenshot command' ) @@ -26,8 +26,7 @@ pkgver() { } package() { - cd ${pkgname} + cd "$srcdir/$pkgname" python setup.py install --root=${pkgdir} - ln -s /usr/bin/archey3 ${pkgdir}/usr/bin/archey install -D -m644 COPYING ${pkgdir}/usr/share/licenses/archey/COPYING -} +} -- cgit v1.2.3 From 3c8265265791a2a58bbd90c444f9929094f0da33 Mon Sep 17 00:00:00 2001 From: Laurie Clark-Michalek Date: Tue, 4 Feb 2014 12:43:01 +0000 Subject: Added explicit error message about lack of imagemagick (Fixes #17) --- archey3 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archey3 b/archey3 index 88b32c3..773c523 100755 --- a/archey3 +++ b/archey3 @@ -630,6 +630,8 @@ def screenshot(state): 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): """ -- cgit v1.2.3 From 4d12a076409c02e8d26a9f828eaaa59871688800 Mon Sep 17 00:00:00 2001 From: shmibs Date: Wed, 26 Feb 2014 12:24:28 -0700 Subject: added DE and WM elements --- archey3 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archey3 b/archey3 index 773c523..b56d45a 100755 --- a/archey3 +++ b/archey3 @@ -84,6 +84,7 @@ DE_DICT = collections.OrderedDict([ ('cinnamon', 'Cinnamon'), ('gnome-session', 'GNOME'), ('ksmserver', 'KDE'), + ('mate-session', 'MATE'), ('xfce4-session', 'Xfce'), ('lxsession', 'LXDE'), ('', 'None'), @@ -97,6 +98,7 @@ WM_DICT = collections.OrderedDict([ ('enlightenment', 'Enlightenment'), ('fluxbox', 'Fluxbox'), ('fvwm', 'FVWM'), + ('herbstluftwm', 'herbstluftwm'), ('i3', 'i3'), ('icewm', 'IceWM'), ('kwin', 'KWin'), -- cgit v1.2.3 From 214fe1e83561df9daf2b249b7602794322282f0a Mon Sep 17 00:00:00 2001 From: ribmo Date: Fri, 20 Jun 2014 14:46:25 +0000 Subject: Added bspwm to WM collection --- archey3 | 1 + 1 file changed, 1 insertion(+) diff --git a/archey3 b/archey3 index 773c523..c76e3ef 100755 --- a/archey3 +++ b/archey3 @@ -93,6 +93,7 @@ WM_DICT = collections.OrderedDict([ ('awesome', 'Awesome'), ('beryl', 'Beryl'), ('blackbox', 'Blackbox'), + ('bspwm', 'bspwm'), ('dwm', 'DWM'), ('enlightenment', 'Enlightenment'), ('fluxbox', 'Fluxbox'), -- cgit v1.2.3 From 59cdfe286d4dea461e221c012151112c87d251e6 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Fri, 5 Sep 2014 17:32:00 +0200 Subject: changed format_output(...) to remove unnecessary quotation marks --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index c76e3ef..e0f681a 100755 --- a/archey3 +++ b/archey3 @@ -239,7 +239,7 @@ class fsDisplay(display): def format_output(self, instring): try: decimal_point = self.call_command( - 'locale -ck decimal_point').split('\n')[1].split('=')[1] + 'locale -ck decimal_point').split('\n')[1].split('=')[1].strip('\"') except Exception as e: self.state.logger.warning('Could not determine locale decimal point,' + 'defaulting to \'.\', failed with error {0}'.format(e)) -- cgit v1.2.3 From 01f07a83b5345ae8d70cd67a8d7ba57aacce88a1 Mon Sep 17 00:00:00 2001 From: rski Date: Sat, 15 Nov 2014 19:35:52 +0000 Subject: fix issue #24 --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 8998cf1..39c093a 100755 --- a/archey3 +++ b/archey3 @@ -287,7 +287,7 @@ class ramDisplay(display): 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]) + used = int(ram[2]) total = int(ram[1]) title = 'RAM' try: -- cgit v1.2.3 From 3dc762675473465e54f7b4f2e3a5512d31c505ec Mon Sep 17 00:00:00 2001 From: rski Date: Fri, 1 May 2015 21:37:33 +0100 Subject: fix issue #27: can now detect kwin_x11 and kwin_wayland --- archey3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archey3 b/archey3 index 39c093a..d4b387e 100755 --- a/archey3 +++ b/archey3 @@ -102,7 +102,7 @@ WM_DICT = collections.OrderedDict([ ('herbstluftwm', 'herbstluftwm'), ('i3', 'i3'), ('icewm', 'IceWM'), - ('kwin', 'KWin'), + (re.compile('kwin(_x11|_wayland)?'), 'KWin'), ('metacity', 'Metacity'), ('musca', 'Musca'), ('openbox', 'Openbox'), -- cgit v1.2.3