annotate wsgraph/client.py @ 36:5ea58a6ea820

tests for node integrity; TODO: edge integrity
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 14 Dec 2012 20:53:41 -0800
parents 9e173648d848
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
e46b4466abac start a RESTful client; putting this here for now; it could go in model.py as it will inherit from the ABC, but keeping it here avoids a ccertain class of import hell
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
e46b4466abac start a RESTful client; putting this here for now; it could go in model.py as it will inherit from the ABC, but keeping it here avoids a ccertain class of import hell
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
27
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
3 """REST API client for WSGraph"""
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
4
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
5 import json
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
6 import sys
26
60d7e38a20cd mostly notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
7 from model import Graph
24
e46b4466abac start a RESTful client; putting this here for now; it could go in model.py as it will inherit from the ABC, but keeping it here avoids a ccertain class of import hell
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
27
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
9 class WSGraphClient(Graph):
24
e46b4466abac start a RESTful client; putting this here for now; it could go in model.py as it will inherit from the ABC, but keeping it here avoids a ccertain class of import hell
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 """REST client for WSGraph"""
e46b4466abac start a RESTful client; putting this here for now; it could go in model.py as it will inherit from the ABC, but keeping it here avoids a ccertain class of import hell
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11
e46b4466abac start a RESTful client; putting this here for now; it could go in model.py as it will inherit from the ABC, but keeping it here avoids a ccertain class of import hell
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 def __init__(self, server):
e46b4466abac start a RESTful client; putting this here for now; it could go in model.py as it will inherit from the ABC, but keeping it here avoids a ccertain class of import hell
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 self.server = server
e46b4466abac start a RESTful client; putting this here for now; it could go in model.py as it will inherit from the ABC, but keeping it here avoids a ccertain class of import hell
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
27
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
15 def main(args=sys.argv[1:]):
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
16 """CLI interface for REST client for WSGraph"""
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
17
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
18 # parse command line options
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
19 usage = """%prog [options] node [key1=value1] [key2=value2] [...]
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
20 %prog [options] node1 node2 [key1=value1] [key2=value2] [...]"""
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
21 parser = optparse.OptionParser(usage=usage, description=__doc__)
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
22 parser.add_option('-H', '--host', '--server', dest='server',
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
23 help="WSGraph server URL")
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
24 options, args = parser.parse_args(args)
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
25
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
26 # sanity checks
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
27 if not options.server:
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
28 parser.error('-H/--server must be set')
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
29
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
30 # instantiate model
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
31 graph = WSGraphClient(options.server)
9e173648d848 stubbing out client CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
32
24
e46b4466abac start a RESTful client; putting this here for now; it could go in model.py as it will inherit from the ABC, but keeping it here avoids a ccertain class of import hell
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 if __name__ == '__main__':
e46b4466abac start a RESTful client; putting this here for now; it could go in model.py as it will inherit from the ABC, but keeping it here avoids a ccertain class of import hell
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 pass # TODO