summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSérgio Almeida <mephx.x@gmail.com>2009-07-28 15:01:40 +0100
committerSérgio Almeida <mephx.x@gmail.com>2009-07-28 15:01:40 +0100
commite0afc09ae893e09da19a6da4ec455c64eb2540e9 (patch)
tree52d336218c19ed1586aafd60d90fa37974fa8c81
parentProfileAction structure and Argv parsing done (diff)
downloaduselect-e0afc09ae893e09da19a6da4ec455c64eb2540e9.tar.gz
uselect-e0afc09ae893e09da19a6da4ec455c64eb2540e9.tar.bz2
uselect-e0afc09ae893e09da19a6da4ec455c64eb2540e9.zip
Added json profiles partial parsing
-rw-r--r--.uprofile/uprofile.json19
-rwxr-xr-xuprofile.py32
2 files changed, 40 insertions, 11 deletions
diff --git a/.uprofile/uprofile.json b/.uprofile/uprofile.json
new file mode 100644
index 0000000..1f0d75a
--- /dev/null
+++ b/.uprofile/uprofile.json
@@ -0,0 +1,19 @@
+{"profile": {
+ "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"
+ ]
+ }
+}}
+
diff --git a/uprofile.py b/uprofile.py
index cd613f2..5c6e68b 100755
--- a/uprofile.py
+++ b/uprofile.py
@@ -9,7 +9,7 @@ import os
import re
import sys
import stat
-import string
+import json
import traceback
from umodule import *
@@ -22,21 +22,30 @@ printsystem.set_type('profile')
class Profile(Module):
- def __init__(self, name):
- self.name = name
- self.author = 'unnamed'
- self.version = '0.1'
- self.description = 'Empty'
-
+ def __init__(self, path):
self.actions = []
+ self.parameters = []
+ self.output = []
+
+ str = ''
+ for line in filesystem.read_file('.uprofile/' + path):
+ 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']
+
self.actions.append(Action(name = 'set', \
description = 'Set this profile for this folder.', \
type = 'profile'))
self.actions.append(Action(name = 'default', \
description = 'Set this profile the default profile.', \
type = 'profile'))
- self.parameters = []
- self.output = []
class UniversalProfileTool:
@@ -46,13 +55,14 @@ class UniversalProfileTool:
return
def get_profile(self, name):
- profile = Profile(name)
+ profile = Profile(name + '.json')
return profile
def get_profiles(self):
""" Returns the list of available uprofiles """
for profile in filesystem.list_dir('.uprofile/'):
- self.profiles.append(Profile(profile))
+ if re.match('.*.json$', profile):
+ self.profiles.append(Profile(profile))
return
def parse_argv(self, args):