diff options
author | Sérgio Almeida <mephx.x@gmail.com> | 2009-08-01 20:08:11 +0100 |
---|---|---|
committer | Sérgio Almeida <mephx.x@gmail.com> | 2009-08-01 20:08:11 +0100 |
commit | 008fd405ed2a0fca275e54c7ce818ff4e9fe2560 (patch) | |
tree | bf592c25f0f94c12397a36fc7ad5d77b42913021 | |
parent | uprofile now uses PWD instead of HOME for profile storage (diff) | |
download | uselect-008fd405ed2a0fca275e54c7ce818ff4e9fe2560.tar.gz uselect-008fd405ed2a0fca275e54c7ce818ff4e9fe2560.tar.bz2 uselect-008fd405ed2a0fca275e54c7ce818ff4e9fe2560.zip |
tweaked uprofile's behaviour, minor bug fixing
-rw-r--r-- | .uprofile/folder.json | 2 | ||||
-rwxr-xr-x | uprofile.py | 65 |
2 files changed, 39 insertions, 28 deletions
diff --git a/.uprofile/folder.json b/.uprofile/folder.json index 983a536..fcddf9b 100644 --- a/.uprofile/folder.json +++ b/.uprofile/folder.json @@ -1,5 +1,5 @@ {"profile": { - "description": "This profile is used to test uprofile's capabilities.", + "description": "Sample Profile.", "author": "mephx", "version": "0.1", "modules": { 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: |