summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSérgio Almeida <mephx.x@gmail.com>2009-07-28 19:42:42 +0100
committerSérgio Almeida <mephx.x@gmail.com>2009-07-28 19:42:42 +0100
commit0041f8ab0991adc8524ea0c79a207543833e6cf7 (patch)
tree30b1fe2d814f1e53ca561d890d194f5c885172e9 /uprofile.py
parentAdded json profiles partial parsing (diff)
downloaduselect-0041f8ab0991adc8524ea0c79a207543833e6cf7.tar.gz
uselect-0041f8ab0991adc8524ea0c79a207543833e6cf7.tar.bz2
uselect-0041f8ab0991adc8524ea0c79a207543833e6cf7.zip
uprofile with no arguments now defaults do folder
profiles are now action and module aware added help and list options
Diffstat (limited to 'uprofile.py')
-rwxr-xr-xuprofile.py60
1 files changed, 53 insertions, 7 deletions
diff --git a/uprofile.py b/uprofile.py
index 5c6e68b..3c1ca98 100755
--- a/uprofile.py
+++ b/uprofile.py
@@ -26,26 +26,50 @@ class Profile(Module):
self.actions = []
self.parameters = []
self.output = []
-
+ self.modules = []
str = ''
for line in filesystem.read_file('.uprofile/' + path):
str += line
-
+
profile = json.loads(str)
+ print 'profile = json.loads(str)'
+
+ print profile
self.profile = profile
self.name = path[:-5]
+
self.author = profile['profile']['author']
self.version = profile['profile']['version']
self.description = profile['profile']['description']
- self.actions.append(Action(name = 'set', \
+ for module in profile['profile']['modules']:
+ actions = []
+ for action in profile['profile']['modules'][module]['actions']:
+ actions.append(action)
+ module = self.get_module(module)
+ self.modules.append([module, actions])
+
+ #for module in self.modules:
+ # print module[0]
+ # print module[0].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
+ modname = name
+ modpath = 'modules.'+ modname
+ __import__(modpath)
+ module = eval(modpath + '.module')
+ return module
+
class UniversalProfileTool:
@@ -70,7 +94,11 @@ class UniversalProfileTool:
profile = None
profiles = None
action = None
+ help = False
+ list = False
+
printsystem.use_colors(True)
+
for arg in args:
if arg == '-v':
verbose = True
@@ -79,12 +107,29 @@ class UniversalProfileTool:
elif arg == '-nc':
printsystem.use_colors(False)
args = args[1:]
+ elif arg == '-help':
+ help = True
+ args = args[1:]
+ elif arg == '-list':
+ list = True
+ args = args[1:]
+
- if len(args) < 1:
+ if list or help:
self.get_profiles()
profiles = self.profiles
+ elif len(args) < 1:
+ profile = self.get_profile('folder')
+ action = profile.get_action('activate')
+ action.build()
+ action.do_action(['activate'])
elif len(args) == 1:
- profile = self.get_profile(args[0])
+ try:
+ profile = self.get_profile(args[0])
+ except Exception, exception:
+ 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])
@@ -95,7 +140,7 @@ class UniversalProfileTool:
else:
args = args[2:]
- return [profile, profiles, args, action]
+ return [profile, profiles, args, action, help, list]
def main():
@@ -104,7 +149,8 @@ def main():
list = uprofile.parse_argv(sys.argv[1:])
printsystem.print_ui(profile = list[0], \
- profiles = list[1], action = list[3], args = list[2])
+ profiles = list[1], action = list[3], \
+ args = list[2], help = list[4], list = list[5])
except UserWarning, warning:
printsystem.print_exception(warning, True)