diff options
author | Laurie Clark-Michalek <bluepeppers@archlinux.us> | 2010-11-19 19:42:34 +0000 |
---|---|---|
committer | Laurie Clark-Michalek <bluepeppers@archlinux.us> | 2010-11-19 19:42:34 +0000 |
commit | 81aa06f90db4c3560b082a0c5d3c0f9b36e23704 (patch) | |
tree | c4db05e0137c8cd5d602d595286ab522dc2b7f61 | |
parent | 2509e25926e289ad97febc0e724a9eb4d9006fbe (diff) |
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.
-rw-r--r-- | archey.new | 47 |
1 files changed, 33 insertions, 14 deletions
@@ -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() |