diff options
author | Sérgio Almeida <mephx.x@gmail.com> | 2009-07-27 18:28:46 +0100 |
---|---|---|
committer | Sérgio Almeida <mephx.x@gmail.com> | 2009-07-27 18:28:46 +0100 |
commit | 2ce51ba0fb303c4c1953559963255125805aefce (patch) | |
tree | fb4ed329765bdbd6ad87b5d4364e6b268babbcfa /uio.py | |
parent | Changed modules to plain python (diff) | |
download | uselect-2ce51ba0fb303c4c1953559963255125805aefce.tar.gz uselect-2ce51ba0fb303c4c1953559963255125805aefce.tar.bz2 uselect-2ce51ba0fb303c4c1953559963255125805aefce.zip |
Lacked -a on last commit
Diffstat (limited to 'uio.py')
-rw-r--r-- | uio.py | 79 |
1 files changed, 60 insertions, 19 deletions
@@ -8,6 +8,7 @@ import os import pwd import stat +import subprocess # Aligning space = ' ' @@ -18,7 +19,12 @@ bold = lime = red = reset = yellow = notice = '' error = warning = bullet = ok = highlight = '' verbose = False - +class Counter: + + def __init__(self): + self.count = 0 + self.level = 0 + class FileSystem: """ FileSystem Class """ def __init__(self): @@ -31,7 +37,18 @@ class FileSystem: self.environment += 'bin/' if not os.path.exists(self.environment): os.mkdir(self.environment) - + + def get_env(self): + env = [] + for param in os.environ.keys(): + env.append([param,os.environ[param]]) + return env + + def set_env(self, env): + """ Re-set a environment variable """ + # Only changes uselects environment !BROKEN! + os.environ[env.name] = env.to_string() + def read_file(self, path): """ Reads a File and returns lines[] """ file = open(path,'r') @@ -57,7 +74,8 @@ class FileSystem: return for arg in args: cmd += ' ' + arg - return os.popen(cmd).readlines() + # TODO: change to subprocess.Popen + return os.popen(cmd) def delete_file(self, path): """ Deletes file in "path" """ @@ -86,7 +104,9 @@ class FileSystem: return os.path.exists(path) def real_path(self, path): return os.path.realpath(path) - + + + class PrintSystem: """ PrintSystem Class """ @@ -129,14 +149,18 @@ class PrintSystem: print line return - def print_table(self,list, _verbose = False): - """ Prints Lists of the form list[[a,b]] """ + def print_table(self,list, _verbose = False, level = 0): + """ Prints Lists of the form list[[a,b]]. Can be nested lists.""" global verbose + if _verbose and not verbose: return for item in list: - print(' ' + item[0] + reset + '\r' + 3 * right + item[1]) - return + if isinstance(item[0], basestring): + print ' ', + print(level * ' ' + space + item[0] + reset + '\r' + 3 * right + item[1]) + else: + self.print_table(item, _verbose, level + 1) def print_exception(self, exception, iswarning = False): """ Prints Exceptions in a standart way """ @@ -146,20 +170,36 @@ class PrintSystem: type = error + ' Error! ' self.print_line('\n' + type + str(exception) + '\n') + def format_action(self, action): table = [] - if action.parameters != '': + if action.type in ['sym','path']: + table = self.format_options(action.options) + elif action.type in ['runnable','env']: for line in action.usage: table.append([line,'']) - table.append(['','']) - count = 1 - for option in action.options: - table.append([option[1] + space + \ - eval(option[0]),'']) - count += 1 - return table + + def format_options(self, options, counter = None): + table = [] + for option in options: + if isinstance(option, list) and not isinstance(option[0], int): + sub = self.format_options(option) + table.append(sub) + else: + table.append([str(option[0]) + ' - ' + option[1] + ' - ' + eval(option[2]),'']) + return table + # Screen Functions + + # For debug + def print_nested(self, _list, level = 0): + for item in _list: + if isinstance(item, list): + self.print_nested(item, level + 1) + else: + print level/2 * '*' + ' ' + str(item) + def print_ui(self, module = None, modules = None, \ action = None, args = None): if module == None: @@ -196,7 +236,6 @@ class PrintSystem: def print_module(self, module): self.print_line(bold + lime + 'Module' + space + reset \ + bold +module.name + lime + ':' + reset) - module.get_actions() self.print_line('Author:' + space + module.author + space \ + 'Version:' + space + module.version) @@ -230,16 +269,18 @@ class PrintSystem: def print_usage(self, module = None, action = None): """ General Usage Printer """ + options = '' if module != None: module_name = module.name else: module_name = '<module>' if action != None: action_name = action.name - options = action.parameters + for parameter in action.parameters: + options += parameter + space else: action_name = '<action>' - options = '<options>' + self.print_line(bold + lime + 'Usage:' + reset + ' uselect <options> ' + module_name \ + space + action_name + space + options) |