summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurie Clark-Michalek <bluepeppers@archlinux.us>2010-08-31 21:08:43 +0100
committerLaurie Clark-Michalek <bluepeppers@archlinux.us>2010-08-31 21:08:43 +0100
commitc9fba8a885cc2cd11ee14a3a3af6225dabd36e24 (patch)
tree94824b50b88630f4adad6e223f908b4b067eb380
parent45df151ac5e6950e91e929f881703be6adf1a4be (diff)
Added -d command line option to allow users to customize displayed info
-rwxr-xr-xarchey357
1 files 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