From 4c05971e84cd1056e748bab07593454326c6a6d8 Mon Sep 17 00:00:00 2001 From: Sérgio Almeida Date: Tue, 28 Jul 2009 04:44:28 +0100 Subject: uprofile structure done improved filesystem/printsystem sharing --- uio.py | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 83 insertions(+), 21 deletions(-) (limited to 'uio.py') diff --git a/uio.py b/uio.py index 013ea3e..d99d958 100644 --- a/uio.py +++ b/uio.py @@ -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 = '' + if action != None: + action_name = action.name + for parameter in action.parameters: + options += parameter + space + else: + action_name = '' + + self.print_line(bold + lime + 'Usage:' + reset + ' uprofile ' + profile_name \ + + space + action_name + space + options) + +filesystem = FileSystem() +printsystem = PrintSystem() -- cgit v1.2.3-65-gdbad