Hook system bugfixes

This commit is contained in:
Kload 2013-10-28 17:17:13 +00:00
parent 41b90067e5
commit 37d87cad09
3 changed files with 18 additions and 24 deletions

View file

@ -712,7 +712,7 @@ hook:
api: GET /hook/check api: GET /hook/check
arguments: arguments:
file: file:
help: Script to check help: File to check
### hook_exec() ### hook_exec()
exec: exec:

View file

@ -67,27 +67,21 @@ def hook_check(file):
Parse the script file and get arguments Parse the script file and get arguments
Keyword argument: Keyword argument:
file -- Script to check file -- File to check
""" """
try:
with open(file[:file.index('scripts/install')] + 'manifest.json') as f:
manifest = json.loads(str(f.read()))
except:
raise YunoHostError(22, _("Invalid app package"))
with open(file, 'r') as conf: action = file[file.index('scripts/') + 8:]
script_lines = conf.readlines() if action in manifest["arguments"]:
return manifest["arguments"][action]
in_block = False
json_string = ""
for line in script_lines:
if re.search(r'^#### json"', line):
in_block = True
if in_block and re.search(r'^####', line):
in_block = False
elif re.search(r'^##[^#;]', line):
json_string = json_string + line[2:]
if json_string == "":
return {}
else: else:
return json.loads(json_string)['arguments'] return {}
def hook_exec(file, args=None): def hook_exec(file, args=None):
""" """