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
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
-rw-r--r--.uprofile/folder.json (renamed from .uprofile/uprofile.json)24
-rw-r--r--uio.py31
-rw-r--r--umodule.py2
-rwxr-xr-xuprofile.py60
4 files changed, 86 insertions, 31 deletions
diff --git a/.uprofile/uprofile.json b/.uprofile/folder.json
index 1f0d75a..012649c 100644
--- a/.uprofile/uprofile.json
+++ b/.uprofile/folder.json
@@ -2,18 +2,18 @@
"description": "This profile is used to test uprofile's capabilities.",
"author": "mephx",
"version": "0.1",
- "modules": [
- "python",
- "gcc"
- ],
- "actions": {
- "python": [
- "bin 0",
- "test 1 1"
- ],
- "gcc": [
- "bin 0"
- ]
+ "modules": {
+ "python": {
+ "actions": [
+ "bin 1",
+ "test 1 1"
+ ]
+ },
+ "gcc": {
+ "actions": [
+ "bin 0"
+ ]
+ }
}
}}
diff --git a/uio.py b/uio.py
index 610ebca..c669a11 100644
--- a/uio.py
+++ b/uio.py
@@ -236,7 +236,7 @@ class PrintSystem:
self.print_usage(module, action)
self.print_line('')
# Action
- self.print_action(module, action)
+ self.print_action(action)
self.print_line('')
else:
# This means Action Done
@@ -300,26 +300,35 @@ class PrintSystem:
+ space + action_name + space + options)
def print_options(self):
+
self.print_line(highlight + space + 'Options:' + reset)
self.print_table([ \
[bold + '-v', bullet + space + 'Verbose Mode'], \
[bold + '-nc', bullet + space + 'No Colors'], \
- # [bold + '-profile', bullet + space + 'Profile Mode'], \
+ [bold + '-help', bullet + space + 'See this screen'], \
+ [bold + '-list', bullet + space + 'List Profiles'], \
[bold + '-version', bullet + space + 'Version Information']])
+ self.print_line('')
+ self.print_line(highlight + space + 'Usage Examples:' + reset)
+ self.print_table([ \
+ [bold + 'uprofile', bullet + space + 'Activates Folder Profile. Fallback to user profile.'], \
+ [bold + 'uprofile <profile>', bullet + space + 'See Details on <profile>']])
class ProfilePrintSystem(PrintSystem):
def print_ui(self, profile = None, profiles = None, args = None, \
- action = None):
-
+ action = None, help = False, list = False):
if profile == None:
- self.print_usage(profile = profile, action = action)
- self.print_line('')
- self.print_options()
- self.print_line('')
- self.print_profiles(profiles)
- self.print_line('')
+ if help or list:
+ self.print_usage(profile = profile, action = action)
+ self.print_line('')
+ if help:
+ self.print_options()
+ self.print_line('')
+ if list:
+ self.print_profiles(profiles)
+ self.print_line('')
elif profiles == None and action == None:
self.print_usage(profile = profile, action = action)
self.print_line('')
@@ -329,7 +338,7 @@ class ProfilePrintSystem(PrintSystem):
self.print_line('')
else:
for line in action.output:
- print line
+ print line
def print_profiles(self, profiles):
self.print_line(highlight + space + 'Profiles:' + reset)
diff --git a/umodule.py b/umodule.py
index c8ba4d6..ae4f818 100644
--- a/umodule.py
+++ b/umodule.py
@@ -302,7 +302,7 @@ class Var():
class ProfileAction(Action):
def do_action(self, args):
- if args[0] == 'set':
+ if args[0] == 'activate':
self.output.append('Folder Profile Set!')
elif args[0] == 'default':
self.output.append('Default Profile Set!')
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)