diff options
author | 2009-07-28 04:44:28 +0100 | |
---|---|---|
committer | 2009-07-28 04:44:28 +0100 | |
commit | 4c05971e84cd1056e748bab07593454326c6a6d8 (patch) | |
tree | 12ba35a9ce314283fd09642f69020d7bc2838e86 /uio.py | |
parent | Open uprofile branch (diff) | |
download | uselect-4c05971e84cd1056e748bab07593454326c6a6d8.tar.gz uselect-4c05971e84cd1056e748bab07593454326c6a6d8.tar.bz2 uselect-4c05971e84cd1056e748bab07593454326c6a6d8.zip |
uprofile structure done
improved filesystem/printsystem sharing
Diffstat (limited to 'uio.py')
-rw-r--r-- | uio.py | 104 |
1 files changed, 83 insertions, 21 deletions
@@ -10,6 +10,9 @@ import pwd import stat import subprocess + + + # Aligning space = ' ' right = '\t' @@ -108,13 +111,18 @@ class FileSystem: def real_path(self, path): return os.path.realpath(path) - - + class PrintSystem: """ PrintSystem Class """ + + def set_type(self, type): + if type == 'profile': + self.__class__ = ProfilePrintSystem - def __init__(self): + def __init__(self, profile = False): """ PrintSystem Constructor """ + if profile: + self.__class__ = ProfilePrintSystem return def verbose(self): @@ -236,36 +244,27 @@ class PrintSystem: print(line) return - def print_uprofile_ui(self, profile = None, profiles = None, args = None): - if profile == None: - self.print_profiles(profiles) - - def print_profiles(self, profiles): - self.print_line(bold + lime + 'Profiles:' + reset) - table = [] - for profile in profiles: - table.append([bold + profile.name, profile.description]) - - self.print_table(table) + def print_module(self, module): - self.print_line(bold + lime + 'Module' + space + reset \ - + bold +module.name + lime + ':' + reset) - self.print_line('Author:' + space + module.author + space \ - + 'Version:' + space + module.version) + self.print_line(highlight + space + 'Module' + space + reset \ + + bold + module.name + lime + ':' + reset) + self.print_line(space * 4 + bold + 'Author:' + reset + space + \ + module.author + space + bold + 'Version:' + reset + space \ + + module.version) def print_modules(self, modules): - self.print_line(lime + bold + 'Modules:' + reset) + self.print_line(highlight + space + 'Modules:' + reset) list = [] for module in modules: list.append([bold + module.name, bullet + space + module.description]) self.print_table(list) def print_actions(self, module): - self.print_line(highlight + 'Actions:' + reset) + self.print_line(highlight + space + 'Actions:' + reset) if len(module.actions) == 0: - print ' Module ' + module.name + \ + print space * 4 + bold + '"' + module.name + '"' + \ ' has no actions!' return list = [] @@ -308,3 +307,66 @@ class PrintSystem: # [bold + '-profile', bullet + space + 'Profile Mode'], \ [bold + '-version', bullet + space + 'Version Information']]) + +class ProfilePrintSystem(PrintSystem): + + def print_ui(self, profile = None, profiles = None, args = None, \ + action = None): + self.print_usage(profile = profile, action = action) + self.print_line('') + if profile == None: + self.print_options() + self.print_line('') + self.print_profiles(profiles) + self.print_line('') + elif profiles == None: + self.print_profile(profile) + self.print_line('') + self.print_actions(profile) + self.print_line('') + + def print_profiles(self, profiles): + self.print_line(highlight + space + 'Profiles:' + reset) + table = [] + for profile in profiles: + table.append([bold + profile.name, bullet + space + profile.description]) + self.print_table(table) + + def print_profile(self, profile): + self.print_line(highlight + space + 'Profile' + space + reset \ + + bold + profile.name + lime + ':' + reset) + self.print_line(space * 4 + bold + 'Author:' + reset + space + \ + profile.author + space + bold + 'Version:' + reset + space \ + + profile.version) + + + + def print_action(self, module, action): + self.print_table([[bold + action.description + reset, '']]) + self.print_line('') + self.print_table(self.format_action(action)) + + def print_version(self, version): + self.print_line(bold + 'Universal Profile Tool - ' \ + + lime + 'uprofile' + reset) + self.print_line(bold + 'Version ' + reset + version + '\n') + + def print_usage(self, profile = None, action = None): + """ General Usage Printer """ + options = '' + if profile != None: + profile_name = profile.name + else: + profile_name = '<profile>' + if action != None: + action_name = action.name + for parameter in action.parameters: + options += parameter + space + else: + action_name = '<action>' + + self.print_line(bold + lime + 'Usage:' + reset + ' uprofile <options> ' + profile_name \ + + space + action_name + space + options) + +filesystem = FileSystem() +printsystem = PrintSystem() |