2010-12-07 03:11:40 +03:00
|
|
|
import json
|
|
|
|
from StringIO import StringIO
|
2010-10-18 00:28:14 +04:00
|
|
|
|
|
|
|
import validator.main
|
2010-12-07 03:11:40 +03:00
|
|
|
import validator.testcases.targetapplication
|
2010-10-18 00:28:14 +04:00
|
|
|
from validator.errorbundler import ErrorBundle
|
|
|
|
from validator.constants import PACKAGE_ANY
|
|
|
|
|
|
|
|
|
2010-12-07 18:55:33 +03:00
|
|
|
def validate(path, format="json",
|
|
|
|
approved_applications="validator/app_versions.json",
|
|
|
|
determined=True):
|
2010-10-18 00:28:14 +04:00
|
|
|
"Perform validation in one easy step!"
|
|
|
|
|
|
|
|
output = StringIO()
|
2010-12-07 03:11:40 +03:00
|
|
|
|
|
|
|
# Load up the target applications
|
2010-12-07 18:55:33 +03:00
|
|
|
apps = json.load(open(approved_applications))
|
|
|
|
validator.testcases.targetapplication.APPROVED_APPLICATIONS = apps
|
2010-10-18 00:28:14 +04:00
|
|
|
|
2010-12-07 03:11:40 +03:00
|
|
|
bundle = ErrorBundle(pipe=output, no_color=True, listed=True,
|
|
|
|
determined=determined)
|
2010-10-18 00:28:14 +04:00
|
|
|
validator.main.prepare_package(bundle, path, PACKAGE_ANY)
|
|
|
|
|
|
|
|
# Write the results to the pipe
|
|
|
|
formats = {"json": lambda b:bundle.print_json()}
|
|
|
|
if format in formats:
|
|
|
|
formats[format](bundle)
|
|
|
|
|
|
|
|
# Return the output of the validator
|
|
|
|
return output.getvalue()
|
|
|
|
|