Ben Bass avatar Ben Bass committed 8a174cf

add command line interface examples

Comments (0)

Files changed (3)

+#!/usr/bin/python -u
+
+import ast
+from rpcpdb import termsock
+
+
+def get_api_connection():
+    """
+    replace this with something to return a proxy to your API
+    """
+    raise NotImplementedError('this function should be replaced')
+
+
+def debug(options):
+    if options.funcname:
+        # get a client connection
+        c = get_api_connection()
+        match_criteria = {}
+        for match in (options.match or []):
+            param, value = map(''.strip, match.split(':', 1))
+            if not param and not value:
+                raise ValueError('invalid match definition "%s"' % match)
+            try:
+                real_value = ast.literal_eval(value)
+            except SyntaxError:
+                raise ValueError('invalid match definition "%s"' % match)
+            except ValueError:
+                # literal_eval gives a ValueError where I would expect
+                # a NameError...
+                real_value = value
+            match_criteria[param] = real_value
+        sock_name = c.debug_func(options.funcname,
+                                 options.once,
+                                 force=options.force,
+                                 match_criteria=match_criteria,
+                                 ignore_count=options.ignore_count)
+    elif options.console:
+        c = get_api_connection()
+        sock_name = c.debug_interactive_console()
+    else:
+        sock_name = options.sockname
+
+    dbg = termsock.TermSock(sock_name)
+    dbg.mainloop()
+
+
+def main():
+    import optparse
+    usage = "%prog: connect to a UPdb debugger"
+    parser = optparse.OptionParser(usage=usage)
+    parser.add_option("-s", "--sockname",
+                      dest="sockname",
+                      help="UNIX-domain socket path")
+    parser.add_option("-a", "--funcname",
+                      dest="funcname",
+                      help="API function to debug")
+    parser.add_option("-c", "--console",
+                      dest="console",
+                      action="store_true",
+                      help="Interactive console")
+    parser.add_option("-m", "--match",
+                      dest="match",
+                      action="append",
+                      help="Add a match criteria in form 'param:value'")
+    parser.add_option("-o", "--once",
+                      dest="once",
+                      action="store_false",
+                      help="Set breakpoint as once-only (default)",
+                      default=True)
+    parser.add_option("-i", "--ignore_count",
+                      dest="ignore_count",
+                      default=0,
+                      type=int,
+                      help="Ignore count (default 0)")
+    parser.add_option("-f", "--force",
+                      dest="force",
+                      action="store_true",
+                      help="Force (overwrite any previous socket)")
+    options, args = parser.parse_args()
+    if len(filter(None, (options.sockname,
+                         options.funcname,
+                         options.console))) != 1:
+        parser.error("Specify exactly one of --funcname, --sockname or --console")
+    if options.match and not options.funcname:
+        parser.error("--match can only be specified for --funcname")
+
+    debug(options)
+
+
+if __name__ == '__main__':
+    main()

rpcpdb/cli_pyro.py

+#!/usr/bin/env python -u
+
+import Pyro.core
+from rpcpdb import cli
+
+
+def get_api_connection():
+    return Pyro.core.getProxyForURI("PYROLOC://localhost:7766/rpc")
+cli.get_api_connection = get_api_connection
+
+
+if __name__ == '__main__':
+    cli.main()

rpcpdb/cli_xmlrpc.py

+#!/usr/bin/env python -u
+
+import xmlrpclib
+from rpcpdb import cli
+
+
+def get_api_connection():
+    return xmlrpclib.ServerProxy('http://localhost:8000')
+cli.get_api_connection = get_api_connection
+
+
+if __name__ == '__main__':
+    cli.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.