forked from mozilla/amo-validator
/
validate.py
57 lines (47 loc) · 2.17 KB
/
validate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
import os
from StringIO import StringIO
import validator.constants
import validator.loader
import validator.submain
import validator.testcases.targetapplication
from validator.errorbundler import ErrorBundle
from validator.constants import PACKAGE_ANY
def validate(path, format="json",
approved_applications=os.path.join(os.path.dirname(__file__),
"app_versions.json"),
determined=True, spidermonkey=False, listed=True,
expectation=PACKAGE_ANY, for_appversions=None,
overrides=None, scrape=False):
"""
Perform validation in one easy step!
format : The format to output the results in
approved_applications : Path to the list of approved application versions
determined : Whether the validator should continue after a tier fails
spidermonkey : Path to the local spidermonkey installation (Default: False)
listed : True if the add-on is destined for AMO, false if not
expectation : The type of package that should be expected
for_appversions : A dict of app GUIDs referencing lists of versions.
Determines which version-dependant tests should be run.
overrides : A dictionary of values to override validator functions.
scrape : When enabled, extra information will be collected about the
add-on, including JavaScript source code.
"""
# Load up the target applications
apps = json.load(open(approved_applications))
validator.constants.APPROVED_APPLICATIONS.clear()
validator.constants.APPROVED_APPLICATIONS.update(apps)
bundle = ErrorBundle(listed=listed, determined=determined)
if overrides:
bundle.overrides = overrides
if spidermonkey != False:
bundle.save_resource("SPIDERMONKEY", spidermonkey)
bundle.save_resource("scrape", scrape, pushable=False)
validator.submain.prepare_package(bundle, path, expectation,
for_appversions=for_appversions)
# Write the results to the pipe
formats = {"json": lambda b: b.render_json()}
if format is not None:
return formats[format](bundle)
else:
return bundle