Mercurial > p > roundup > code
comparison scripts/schema-dump.py @ 7053:b5fffd2a64af
issue2551195: port scripts to argparse
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Tue, 22 Nov 2022 14:29:42 +0100 |
| parents | ed5c19fca083 |
| children | 739b9f017d2c |
comparison
equal
deleted
inserted
replaced
| 7052:4b6a6b794dfa | 7053:b5fffd2a64af |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python3 |
| 2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
| 3 """ | 3 """ |
| 4 Use recently documented XML-RPC API to dump | 4 Use recently documented XML-RPC API to dump |
| 5 Roundup data schema in human readable form. | 5 Roundup data schema in human readable form. |
| 6 | 6 |
| 21 import os | 21 import os |
| 22 import sys | 22 import sys |
| 23 from roundup.anypy import xmlrpc_ | 23 from roundup.anypy import xmlrpc_ |
| 24 import pprint | 24 import pprint |
| 25 import textwrap | 25 import textwrap |
| 26 from optparse import OptionParser | 26 from argparse import ArgumentParser |
| 27 | 27 |
| 28 sname = os.path.basename(sys.argv[0]) | 28 sname = os.path.basename(sys.argv[0]) |
| 29 usage = """\ | 29 usage = """\ |
| 30 usage: %s [options] URL | 30 usage: %s [options] URL |
| 31 | 31 |
| 80 out2.append(line) | 80 out2.append(line) |
| 81 out = '\n'.join(out2) | 81 out = '\n'.join(out2) |
| 82 return out | 82 return out |
| 83 | 83 |
| 84 if __name__ == "__main__": | 84 if __name__ == "__main__": |
| 85 if len(sys.argv) < 2 or "-h" in sys.argv or "--help" in sys.argv: | 85 parser = ArgumentParser() |
| 86 sys.exit(usage) | 86 parser.add_argument("url", nargs=1) |
| 87 if "--version" in sys.argv: | 87 parser.add_argument("--raw", action='store_true') |
| 88 parser.add_argument("--yaml", action='store_true') | |
| 89 parser.add_argument("--json", action='store_true') | |
| 90 parser.add_argument("-v", "--version", action='store_true') | |
| 91 args = parser.parse_args() | |
| 92 if args.version: | |
| 88 sys.exit(sname + " " + __version__) | 93 sys.exit(sname + " " + __version__) |
| 89 | 94 |
| 90 parser = OptionParser() | 95 roundup_server = xmlrpc_.client.ServerProxy(args.url[0], allow_none=True) |
| 91 parser.add_option("--raw", action='store_true') | |
| 92 parser.add_option("--yaml", action='store_true') | |
| 93 parser.add_option("--json", action='store_true') | |
| 94 (options, args) = parser.parse_args() | |
| 95 | |
| 96 url = args[0] | |
| 97 roundup_server = xmlrpc_.client.ServerProxy(url, allow_none=True) | |
| 98 schema = roundup_server.schema() | 96 schema = roundup_server.schema() |
| 99 if options.raw: | 97 if args.raw: |
| 100 print(str(schema)) | 98 print(str(schema)) |
| 101 elif options.yaml: | 99 elif args.yaml: |
| 102 print(format_yaml(schema)) | 100 print(format_yaml(schema)) |
| 103 elif options.json: | 101 elif args.json: |
| 104 print(format_json(schema)) | 102 print(format_json(schema)) |
| 105 else: | 103 else: |
| 106 print(format_pprint(schema)) | 104 print(format_pprint(schema)) |
| 107 | 105 |
| 108 print("") | 106 print("") |
