Skip to content

Commit

Permalink
added basic plugin package validation
Browse files Browse the repository at this point in the history
  • Loading branch information
brianleroux committed Apr 23, 2011
1 parent 713600c commit bf6c973
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions generate-template/bin/plugin/validate
@@ -0,0 +1,44 @@
#! /usr/bin/env python
import sys, json, urllib, os


class PluginPackageValidator():
def __init__(self):
plugins_json = urllib.urlopen('http://phonegap-plugins.appspot.com/_je/plugin').read()
self.plugins = json.loads(plugins_json)
self.json_path = os.path.join('lib', 'plugin', sys.argv[1], 'package.json')
# validate
self.package_json_exists()
self.name_is_unique()
self.package_json_readable()
self.has_github_url()
self.www_exists()

def package_json_exists(self):
if not os.path.exists(self.json_path):
raise IOError('package.json missing for plugin ' + sys.argv[1])

def name_is_unique(self):
for index, item in enumerate(self.plugins):
if 'name' in item and item['name'] == sys.argv[1]:
raise RuntimeError('name is not unique')

def package_json_readable(self):
f = open(self.json_path, 'r')
json_str = f.read()
self.package = json.loads(json_str)
f.close()

def has_github_url(self):
if 'repository' not in self.package:
raise RuntimeError('a github repo url required for the time being')

def www_exists(self):
www = os.path.join('lib', 'plugin', sys.argv[1], 'www')
if not os.path.exists(www):
raise RuntimeError('plugin missing www')


# if worse is better then we can't get much better than this!
if __name__ == "__main__":
PluginPackageValidator()

0 comments on commit bf6c973

Please sign in to comment.