forked from 2600hz/kazoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* validate-js: add validate-js script * validate-js: fix an actual issue!
- Loading branch information
1 parent
41bd177
commit 124878c
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python2 | ||
|
||
# print 'Usage: ' + sys.argv[0] + ' file.json+' | ||
|
||
import sys | ||
import json | ||
from subprocess import call | ||
import os | ||
|
||
if len(sys.argv) < 2: | ||
pass | ||
|
||
def fmap(F, data): | ||
if isinstance(data, dict): | ||
for key, value in data.iteritems(): | ||
fmap(F, (key,value)) | ||
elif isinstance(data, tuple): | ||
(key, value) = data | ||
if isinstance(value, basestring): | ||
if value.startswith('function'): | ||
F(data) | ||
else: | ||
fmap(F, value) | ||
elif isinstance(data, list): | ||
for i, value in enumerate(data): | ||
fmap(F, (i,value)) | ||
elif isinstance(data, int): | ||
pass | ||
|
||
def couchjs((field, js)): | ||
TMP = '_' | ||
with open(TMP, 'w') as wd: | ||
wd.write(js + '\n') | ||
try: | ||
code = call(['couchjs', TMP]) | ||
if code != 0: | ||
print 'Key:', field | ||
print 'Code:', js | ||
exit(1) | ||
else: | ||
print field, 'passed' | ||
finally: | ||
os.remove(TMP) | ||
|
||
for fn in sys.argv[1:]: | ||
print 'checking ' + fn | ||
with open(fn) as rd: | ||
data = json.load(rd) | ||
fmap(couchjs, data) |