diff options
Diffstat (limited to 'uprofile.py')
-rwxr-xr-x | uprofile.py | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/uprofile.py b/uprofile.py index 129bd02..3084e66 100755 --- a/uprofile.py +++ b/uprofile.py @@ -23,28 +23,39 @@ filesystem.set_type('profile') class Profile(Module): - def __init__(self, path): + def __init__(self, name): + self.name = name self.actions = [] self.parameters = [] self.output = [] self.modules = [] - str = '' - for line in filesystem.read_file('.uprofile/' + path): + self.actions.append(Action(name = 'activate', \ + description = 'Set this profile for this folder.', \ + type = 'profile')) + self.actions.append(Action(name = 'default', \ + description = 'Set this profile the default profile.', \ + type = 'profile')) + + def write_profile(self): + print self.profile + return + + def read_profile(self): + str = '' + + for line in filesystem.read_file('.uprofile/' + self.name + '.json'): str += line profile = json.loads(str) self.profile = profile - self.name = path[:-5] - self.author = profile['profile']['author'] self.version = profile['profile']['version'] self.description = profile['profile']['description'] modules = profile['profile']['modules'] - for module in modules: actions = [] for action in modules[module]['actions']: @@ -53,14 +64,6 @@ class Profile(Module): module = self.get_module(module) self.modules.append([module, actions]) - - self.actions.append(Action(name = 'activate', \ - description = 'Set this profile for this folder.', \ - type = 'profile')) - self.actions.append(Action(name = 'default', \ - description = 'Set this profile the default profile.', \ - type = 'profile')) - def get_module(self, name): import modules @@ -78,16 +81,15 @@ class UniversalProfileTool: self.profiles = [] return - def get_profile(self, name): - profile = Profile(name + '.json') - return profile - def get_profiles(self): """ Returns the list of available uprofiles """ if filesystem.path_exists('.uprofile'): for profile in filesystem.list_dir('.uprofile/'): - if re.match('.*.json$', profile): - self.profiles.append(Profile(profile)) + match = re.match('(.+).json$', profile) + if match: + _profile = Profile(match.group(1)) + _profile.read_profile() + self.profiles.append(_profile) def parse_argv(self, args): global verbose, version @@ -120,7 +122,8 @@ class UniversalProfileTool: profiles = self.profiles elif len(args) < 1: try: - profile = self.get_profile('folder') + profile = Profile('folder') + profile.read_profile() action = profile.get_action('activate') action.build() action.do_action(['activate'], profile.modules) @@ -130,16 +133,24 @@ class UniversalProfileTool: list = True elif len(args) == 1: try: - profile = self.get_profile(args[0]) - except Exception, exception: + profile = Profile(args[0]) + profile.read_profile() + except IOError: printsystem.print_exception(Exception(\ 'No such option/profile "' + args[0] + \ '"\n "uprofile -help" for help')) elif len(args) == 2: - profile = self.get_profile(args[0]) - action = profile.get_action(args[1]) - action.build() - action.do_action(args[1:]) + try: + profile = Profile(args[0]) + profile.read_profile() + action = profile.get_action(args[1]) + action.build() + action.do_action(args[1:], profile.modules) + except IOError: + printsystem.print_exception(Exception(\ + 'No such option/profile "' + args[0] + \ + '"\n "uprofile -help" for help')) + if len(args) == 2: args = None else: |