From e0afc09ae893e09da19a6da4ec455c64eb2540e9 Mon Sep 17 00:00:00 2001 From: Sérgio Almeida Date: Tue, 28 Jul 2009 15:01:40 +0100 Subject: Added json profiles partial parsing --- .uprofile/uprofile.json | 19 +++++++++++++++++++ uprofile.py | 32 +++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 .uprofile/uprofile.json 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): -- cgit v1.2.3-65-gdbad