changeset 12:421d5119e324

reluctantly make this a CLI entry point
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 10 Dec 2012 17:30:44 -0800
parents 7b8e40eda563
children 7459702bf574
files setup.py wsgraph/web.py
diffstat 2 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Mon Dec 10 17:16:21 2012 -0800
+++ b/setup.py	Mon Dec 10 17:30:44 2012 -0800
@@ -13,6 +13,7 @@
     from setuptools import setup
     kw['entry_points'] = """
       [console_scripts]
+      wsgraph = wsgraph.web:main
 """
     kw['install_requires'] = dependencies
 except ImportError:
--- a/wsgraph/web.py	Mon Dec 10 17:16:21 2012 -0800
+++ b/wsgraph/web.py	Mon Dec 10 17:30:44 2012 -0800
@@ -5,6 +5,7 @@
 """
 
 import json
+import sys
 from webob import Request, Response, exc
 
 # rank constants
@@ -106,11 +107,15 @@
 
         # get resource requestor
         segments = self.path_segments(request.path_info)
-        if len(segments) not in (0,1,2):
+        rank = len(segments)
+        if rank not in (0,1,2):
             return exc.HTTPNotFound()
 
 
         # is resource in the graph? [TODO]
+        if (rank == EDGE) or (rank == NODE):
+            if tuple(segments) not in self.graph:
+                retun exc.HTTPNotFound()
 
         # formatter
         formatter = self.formatters[len(segments)]
@@ -135,9 +140,9 @@
     def OPTIONS(self, request):
         return Response() # TODO: Allow=', '.join(self.methods); Content-Length=0
 
-if __name__ == '__main__':
 
-    ### example web server
+def main(args=sys.argv[1:]):
+    """example web server"""
 
     # imports
     from wsgiref import simple_server
@@ -159,3 +164,5 @@
     print 'http://localhost:%s/' % options.port
     server.serve_forever()
 
+if __name__ == '__main__':
+    main()