#! /usr/bin/python
import jsonschema
import json
import sys
import os
import glob

vm_schema = json.loads(open("vm.schema.json").read());

def validate_vm_spec(filename):
  # Load and parse as JSON
  try:
    vm_spec = json.loads(open(filename).read())
  except:
    raise Exception("JSON load / parse Error for " + filename)

  # Validate JSON according to schema
  try:
    jsonschema.validate(vm_spec, vm_schema)
  except Exception as err:
    raise Exception("JSON schema validation failed: " + err.message)


def has_required_stuff(path):

  # Certain files are mandatory
  required_files = [ "Makefile", "test.py", "README.md", "*.cpp" ]
  for file in required_files:
    if not glob.glob(file):
      raise Exception("missing " + file)

  # JSON-files must conform to VM-schema
  for json in glob.glob("*.json"):
    validate_vm_spec(json)


path = sys.argv[1] if len(sys.argv) > 1 else "."
os.chdir(path)

try:
  has_required_stuff(path)
  print "\tPASS: ",os.getcwd()
except Exception as err:
  print "\tFAIL: unmet requirements in " + path, ": " , err.message

@@ -92,40 +92,124 @@
 a = 
-json.loads(open(%22vm.
+None%0Ajsons = %5B%5D%0Avalid_vms = %5B%5D%0A%0Adef load_schema(filename):%0A  global vm_
 schema
-.json%22
+%0A  vm_schema = json.loads(open(filename
 ).re
@@ -248,16 +248,54 @@
 ename):%0A
+%0A  global valid_vms%0A  vm_spec = None%0A%0A
   # Load
@@ -628,16 +628,45 @@
 ssage)%0A%0A
+  valid_vms.append(vm_spec)%0A%0A
 %0Adef has
@@ -689,16 +689,32 @@
 path):%0A%0A
+  global jsons%0A%0A
   # Cert
@@ -951,19 +951,15 @@
 a%0A  
-for 
 json
- in
+s =
  glo
@@ -974,16 +974,36 @@
 *.json%22)
+%0A  for json in jsons
 :%0A    va
@@ -1024,17 +1024,45 @@
 (json)%0A%0A
-%0A
+if __name__ == %22__main__%22:%0A  
 path = s
@@ -1102,16 +1102,50 @@
 lse %22.%22%0A
+  load_schema(%22vm.schema.json%22)%0A  
 os.chdir
@@ -1155,14 +1155,17 @@
 th)%0A
-%0A
+  
 try:%0A
+  
   ha
@@ -1187,16 +1187,18 @@
 f(path)%0A
+  
   print 
@@ -1198,16 +1198,32 @@
  print %22
+%3Cvalidate_test%3E 
 %5CtPASS: 
@@ -1236,16 +1236,18 @@
 etcwd()%0A
+  
 except E
@@ -1263,16 +1263,18 @@
 as err:%0A
+  
   print 
@@ -1274,16 +1274,32 @@
  print %22
+%3Cvalidate_test%3E 
 %5CtFAIL: 

Test validator can now be used as a module