|
17 | 17 | # This file incorporates work covered by the following copyright:
|
18 | 18 | # Copyright 2010-2016 RethinkDB, all rights reserved.
|
19 | 19 |
|
20 |
| -'''Dispatcher for interactive functions such as repl and backup''' |
| 20 | +"""Dispatcher for interactive functions such as repl and backup""" |
21 | 21 |
|
22 | 22 | import code
|
23 | 23 | import sys
|
|
27 | 27 |
|
28 | 28 |
|
29 | 29 | def startInterpreter(argv=None, prog=None):
|
30 |
| - repl_variables = {'r': net.Connection._r, 'rethinkdb': net.Connection._r} |
31 |
| - banner = 'The RethinkDB driver has been imported as `r`.' |
| 30 | + repl_variables = {"r": net.Connection._r, "rethinkdb": net.Connection._r} |
| 31 | + banner = "The RethinkDB driver has been imported as `r`." |
32 | 32 |
|
33 | 33 | # -- get host/port setup
|
34 | 34 |
|
35 | 35 | # - parse command line
|
36 | 36 | parser = utils_common.CommonOptionsParser(
|
37 |
| - prog=prog, description='An interactive Python shell (repl) with the RethinkDB driver imported') |
38 |
| - options, args = parser.parse_args(argv if argv is not None else sys.argv[1:], connect=False) |
| 37 | + prog=prog, |
| 38 | + description="An interactive Python shell (repl) with the RethinkDB driver imported", |
| 39 | + ) |
| 40 | + options, args = parser.parse_args( |
| 41 | + argv if argv is not None else sys.argv[1:], connect=False |
| 42 | + ) |
39 | 43 |
|
40 | 44 | if args:
|
41 |
| - parser.error('No positional arguments supported. Unrecognized option(s): %s' % args) |
| 45 | + parser.error( |
| 46 | + "No positional arguments supported. Unrecognized option(s): %s" % args |
| 47 | + ) |
42 | 48 |
|
43 | 49 | # -- open connection
|
44 | 50 |
|
45 | 51 | try:
|
46 |
| - repl_variables['conn'] = options.retryQuery.conn() |
47 |
| - repl_variables['conn'].repl() |
48 |
| - banner += ''' |
| 52 | + repl_variables["conn"] = options.retryQuery.conn() |
| 53 | + repl_variables["conn"].repl() |
| 54 | + banner += """ |
49 | 55 | A connection to %s:%d has been established as `conn`
|
50 |
| - and can be used by calling `run()` on a query without any arguments.''' % (options.hostname, options.driver_port) |
| 56 | + and can be used by calling `run()` on a query without any arguments.""" % ( |
| 57 | + options.hostname, |
| 58 | + options.driver_port, |
| 59 | + ) |
51 | 60 | except errors.ReqlDriverError as e:
|
52 |
| - banner += '\nWarning: %s' % str(e) |
| 61 | + banner += "\nWarning: %s" % str(e) |
53 | 62 | if options.debug:
|
54 |
| - banner += '\n' + traceback.format_exc() |
| 63 | + banner += "\n" + traceback.format_exc() |
55 | 64 |
|
56 | 65 | # -- start interpreter
|
57 | 66 |
|
58 |
| - code.interact(banner=banner + '\n==========', local=repl_variables) |
| 67 | + code.interact(banner=banner + "\n==========", local=repl_variables) |
59 | 68 |
|
60 | 69 |
|
61 |
| -if __name__ == '__main__': |
| 70 | +if __name__ == "__main__": |
62 | 71 | if __package__ is None:
|
63 |
| - __package__ = 'rethinkdb' |
| 72 | + __package__ = "rethinkdb" |
64 | 73 |
|
65 | 74 | # -- figure out which mode we are in
|
66 |
| - modes = ['dump', 'export', 'import', 'index_rebuild', 'repl', 'restore'] |
| 75 | + modes = ["dump", "export", "import", "index_rebuild", "repl", "restore"] |
67 | 76 |
|
68 | 77 | if len(sys.argv) < 2 or sys.argv[1] not in modes:
|
69 |
| - sys.exit('ERROR: Must be called with one of the following verbs: %s' % ', '.join(modes)) |
| 78 | + sys.exit( |
| 79 | + "ERROR: Must be called with one of the following verbs: %s" |
| 80 | + % ", ".join(modes) |
| 81 | + ) |
70 | 82 |
|
71 | 83 | verb = sys.argv[1]
|
72 |
| - prog = 'python -m rethinkdb' |
73 |
| - if sys.version_info < (2, 7) or (sys.version_info >= (3, 0) and sys.version_info < (3, 4)): |
74 |
| - prog += '.__main__' # Python versions 2.6, 3.0, 3.1 and 3.3 do not support running packages |
75 |
| - prog += ' ' + verb |
| 84 | + prog = "python -m rethinkdb" |
| 85 | + if sys.version_info < (2, 7) or ( |
| 86 | + sys.version_info >= (3, 0) and sys.version_info < (3, 4) |
| 87 | + ): |
| 88 | + prog += ".__main__" # Python versions 2.6, 3.0, 3.1 and 3.3 do not support running packages |
| 89 | + prog += " " + verb |
76 | 90 | argv = sys.argv[2:]
|
77 | 91 |
|
78 |
| - if verb == 'dump': |
| 92 | + if verb == "dump": |
79 | 93 | from . import _dump
|
| 94 | + |
80 | 95 | exit(_dump.main(argv, prog=prog))
|
81 |
| - elif verb == 'export': |
| 96 | + elif verb == "export": |
82 | 97 | from . import _export
|
| 98 | + |
83 | 99 | exit(_export.main(argv, prog=prog))
|
84 |
| - elif verb == 'import': |
| 100 | + elif verb == "import": |
85 | 101 | from . import _import
|
| 102 | + |
86 | 103 | exit(_import.main(argv, prog=prog))
|
87 |
| - elif verb == 'index_rebuild': |
| 104 | + elif verb == "index_rebuild": |
88 | 105 | from . import _index_rebuild
|
| 106 | + |
89 | 107 | exit(_index_rebuild.main(argv, prog=prog))
|
90 |
| - elif verb == 'repl': |
| 108 | + elif verb == "repl": |
91 | 109 | startInterpreter(argv, prog=prog)
|
92 |
| - elif verb == 'restore': |
| 110 | + elif verb == "restore": |
93 | 111 | from . import _restore
|
| 112 | + |
94 | 113 | exit(_restore.main(argv, prog=prog))
|
0 commit comments