mirror of
https://github.com/YunoHost/package_linter.git
synced 2024-09-03 20:06:12 +02:00
Add new schema validation for manifest v2 (only reports stuff as info for now)
This commit is contained in:
parent
6a5c346ecd
commit
ea1f11b26b
1 changed files with 34 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf8 -*-
|
||||
|
||||
import copy
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
@ -18,6 +19,13 @@ except:
|
|||
os.system('pip3 install toml')
|
||||
import toml
|
||||
|
||||
try:
|
||||
import jsonschema
|
||||
except:
|
||||
os.system('pip3 install toml')
|
||||
import jsonschema
|
||||
|
||||
|
||||
# ############################################################################
|
||||
# Helper list
|
||||
# ############################################################################
|
||||
|
@ -298,6 +306,17 @@ def spdx_licenses():
|
|||
return content
|
||||
|
||||
|
||||
def manifest_v2_schema():
|
||||
cachefile = ".manifest.v2.schema.json"
|
||||
if os.path.exists(cachefile) and time.time() - os.path.getmtime(cachefile) < 3600:
|
||||
return json.loads(open(cachefile).read())
|
||||
|
||||
url = "https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json"
|
||||
content = urlopen(url)["content"]
|
||||
open(cachefile, "w").write(content)
|
||||
return json.loads(content)
|
||||
|
||||
|
||||
tests = {}
|
||||
tests_reports = {
|
||||
"success": [],
|
||||
|
@ -641,7 +660,7 @@ class App(TestSuite):
|
|||
if app_packaging_format <= 1:
|
||||
args = app.manifest["arguments"].get("install", [])
|
||||
else:
|
||||
keyandargs = app.manifest["install"]
|
||||
keyandargs = copy.deepcopy(app.manifest["install"])
|
||||
for key, infos in keyandargs.items():
|
||||
infos["name"] = key
|
||||
args = keyandargs.values()
|
||||
|
@ -1058,7 +1077,7 @@ class Configurations(TestSuite):
|
|||
if app_packaging_format <= 1:
|
||||
args = app.manifest["arguments"].get("install", [])
|
||||
else:
|
||||
keyandargs = app.manifest["install"]
|
||||
keyandargs = copy.deepcopy(app.manifest["install"])
|
||||
for key, infos in keyandargs.items():
|
||||
infos["name"] = key
|
||||
args = keyandargs.values()
|
||||
|
@ -1825,7 +1844,7 @@ class Manifest(TestSuite):
|
|||
if app_packaging_format <= 1:
|
||||
args = self.manifest["arguments"].get("install", [])
|
||||
else:
|
||||
keyandargs = self.manifest["install"]
|
||||
keyandargs = copy.deepcopy(self.manifest["install"])
|
||||
for key, infos in keyandargs.items():
|
||||
infos["name"] = key
|
||||
args = keyandargs.values()
|
||||
|
@ -1896,7 +1915,7 @@ class Manifest(TestSuite):
|
|||
if app_packaging_format <= 1:
|
||||
args = self.manifest["arguments"].get("install", [])
|
||||
else:
|
||||
keyandargs = self.manifest["install"]
|
||||
keyandargs = copy.deepcopy(self.manifest["install"])
|
||||
for key, infos in keyandargs.items():
|
||||
infos["name"] = key
|
||||
args = keyandargs.values()
|
||||
|
@ -1955,6 +1974,17 @@ class Manifest(TestSuite):
|
|||
"When using a postgresql database, you should add postgresql in apt dependencies."
|
||||
)
|
||||
|
||||
@test()
|
||||
def manifest_schema(self):
|
||||
|
||||
v = jsonschema.Draft7Validator(manifest_v2_schema())
|
||||
|
||||
if app_packaging_format <= 1:
|
||||
return
|
||||
|
||||
for error in v.iter_errors(self.manifest):
|
||||
yield Info("Error validating manifest using schema: in key " +' > '.join(error.path) + "\n " + error.message)
|
||||
|
||||
|
||||
########################################
|
||||
# _____ _ _ #
|
||||
|
|
Loading…
Reference in a new issue