|
12 | 12 | __import__("lib.utils.versioncheck") # this has to be the first non-standard import |
13 | 13 |
|
14 | 14 | import logging |
15 | | -import optparse |
16 | 15 | import os |
17 | 16 | import warnings |
18 | 17 |
|
19 | 18 | warnings.filterwarnings(action="ignore", category=UserWarning) |
20 | 19 | warnings.filterwarnings(action="ignore", category=DeprecationWarning) |
21 | 20 |
|
| 21 | +try: |
| 22 | + from optparse import OptionGroup |
| 23 | + from optparse import OptionParser as ArgumentParser |
| 24 | + |
| 25 | + ArgumentParser.add_argument = ArgumentParser.add_option |
| 26 | + |
| 27 | + def _add_argument(self, *args, **kwargs): |
| 28 | + return self.add_option(*args, **kwargs) |
| 29 | + |
| 30 | + OptionGroup.add_argument = _add_argument |
| 31 | + |
| 32 | +except ImportError: |
| 33 | + from argparse import ArgumentParser |
| 34 | + |
| 35 | +finally: |
| 36 | + def get_actions(instance): |
| 37 | + for attr in ("option_list", "_group_actions", "_actions"): |
| 38 | + if hasattr(instance, attr): |
| 39 | + return getattr(instance, attr) |
| 40 | + |
| 41 | + def get_groups(parser): |
| 42 | + return getattr(parser, "option_groups", None) or getattr(parser, "_action_groups") |
| 43 | + |
| 44 | + def get_all_options(parser): |
| 45 | + retVal = set() |
| 46 | + |
| 47 | + for option in get_actions(parser): |
| 48 | + if hasattr(option, "option_strings"): |
| 49 | + retVal.update(option.option_strings) |
| 50 | + else: |
| 51 | + retVal.update(option._long_opts) |
| 52 | + retVal.update(option._short_opts) |
| 53 | + |
| 54 | + for group in get_groups(parser): |
| 55 | + for option in get_actions(group): |
| 56 | + if hasattr(option, "option_strings"): |
| 57 | + retVal.update(option.option_strings) |
| 58 | + else: |
| 59 | + retVal.update(option._long_opts) |
| 60 | + retVal.update(option._short_opts) |
| 61 | + |
| 62 | + return retVal |
| 63 | + |
22 | 64 | from lib.core.common import getUnicode |
23 | 65 | from lib.core.common import setPaths |
24 | 66 | from lib.core.data import logger |
@@ -52,16 +94,17 @@ def main(): |
52 | 94 | setPaths(modulePath()) |
53 | 95 |
|
54 | 96 | # Parse command line options |
55 | | - apiparser = optparse.OptionParser() |
56 | | - apiparser.add_option("-s", "--server", help="Run as a REST-JSON API server", action="store_true") |
57 | | - apiparser.add_option("-c", "--client", help="Run as a REST-JSON API client", action="store_true") |
58 | | - apiparser.add_option("-H", "--host", help="Host of the REST-JSON API server (default \"%s\")" % RESTAPI_DEFAULT_ADDRESS, default=RESTAPI_DEFAULT_ADDRESS, action="store") |
59 | | - apiparser.add_option("-p", "--port", help="Port of the the REST-JSON API server (default %d)" % RESTAPI_DEFAULT_PORT, default=RESTAPI_DEFAULT_PORT, type="int", action="store") |
60 | | - apiparser.add_option("--adapter", help="Server (bottle) adapter to use (default \"%s\")" % RESTAPI_DEFAULT_ADAPTER, default=RESTAPI_DEFAULT_ADAPTER, action="store") |
61 | | - apiparser.add_option("--database", help="Set IPC database filepath (optional)") |
62 | | - apiparser.add_option("--username", help="Basic authentication username (optional)", action="store") |
63 | | - apiparser.add_option("--password", help="Basic authentication password (optional)", action="store") |
64 | | - (args, _) = apiparser.parse_args() |
| 97 | + apiparser = ArgumentParser() |
| 98 | + apiparser.add_argument("-s", "--server", help="Run as a REST-JSON API server", action="store_true") |
| 99 | + apiparser.add_argument("-c", "--client", help="Run as a REST-JSON API client", action="store_true") |
| 100 | + apiparser.add_argument("-H", "--host", help="Host of the REST-JSON API server (default \"%s\")" % RESTAPI_DEFAULT_ADDRESS, default=RESTAPI_DEFAULT_ADDRESS) |
| 101 | + apiparser.add_argument("-p", "--port", help="Port of the the REST-JSON API server (default %d)" % RESTAPI_DEFAULT_PORT, default=RESTAPI_DEFAULT_PORT, type=int) |
| 102 | + apiparser.add_argument("--adapter", help="Server (bottle) adapter to use (default \"%s\")" % RESTAPI_DEFAULT_ADAPTER, default=RESTAPI_DEFAULT_ADAPTER) |
| 103 | + apiparser.add_argument("--database", help="Set IPC database filepath (optional)") |
| 104 | + apiparser.add_argument("--username", help="Basic authentication username (optional)") |
| 105 | + apiparser.add_argument("--password", help="Basic authentication password (optional)") |
| 106 | + (args, _) = apiparser.parse_known_args() if hasattr(apiparser, "parse_known_args") else apiparser.parse_args() |
| 107 | + |
65 | 108 |
|
66 | 109 | # Start the client or the server |
67 | 110 | if args.server: |
|
0 commit comments