annotate scripts/schema-dump.py @ 7752:b2dbab2b34bc

fix(refactor): multiple fixups using ruff linter; more testing. Converting to using the ruff linter and its rulesets. Fixed a number of issues. admin.py: sort imports use immutable tuples as default value markers for parameters where a None value is valid. reduced some loops to list comprehensions for performance used ternary to simplify some if statements named some variables to make them less magic (e.g. _default_savepoint_setting = 1000) fixed some tests for argument counts < 2 becomes != 2 so 3 is an error. moved exception handlers outside of loops for performance where exception handler will abort loop anyway. renamed variables called 'id' or 'dir' as they shadow builtin commands. fix translations of form _("string %s" % value) -> _("string %s") % value so translation will be looked up with the key before substitution. end dicts, tuples with a trailing comma to reduce missing comma errors if modified simplified sorted(list(self.setting.keys())) to sorted(self.setting.keys()) as sorted consumes whole list. in if conditions put compared variable on left and threshold condition on right. (no yoda conditions) multiple noqa: suppression removed unneeded noqa as lint rulesets are a bit different do_get - refactor output printing logic: Use fast return if not special formatting is requested; use isinstance with a tuple rather than two isinstance calls; cleaned up flow and removed comments on algorithm as it can be easily read from the code. do_filter, do_find - refactor output printing logic. Reduce duplicate code. do_find - renamed variable 'value' that was set inside a loop. The loop index variable was also named 'value'. do_pragma - added hint to use list subcommand if setting was not found. Replaced condition 'type(x) is bool' with 'isinstance(x, bool)' for various types. test_admin.py added testing for do_list better test coverage for do_get includes: -S and -d for multilinks, error case for -d with non-link. better testing for do_find including all output modes better testing for do_filter including all output modes fixed expected output for do_pragma that now includes hint to use pragma list if setting not found.
author John Rouillard <rouilj@ieee.org>
date Fri, 01 Mar 2024 14:53:18 -0500
parents 739b9f017d2c
children 8d81f89ba246
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7053
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
1 #!/usr/bin/env python3
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
3 """
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
4 Use recently documented XML-RPC API to dump
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
5 Roundup data schema in human readable form.
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
6
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
7 Works with demo tracker using:
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
8
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
9 http://admin:admin@localhost:8917/demo/xmlrpc
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
10
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
11 Future development may cover:
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
12 [ ] unreadable dump formats
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
13 [ ] access to local database
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
14 [ ] lossless dump/restore cycle
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
15 [ ] data dump and filtering with preserved
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
16
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
17 Works in Python 2 as well.
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
18 """
5936
ed5c19fca083 __future__ import was failing, not first command in file.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
19 from __future__ import print_function
ed5c19fca083 __future__ import was failing, not first command in file.
John Rouillard <rouilj@ieee.org>
parents: 5487
diff changeset
20
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
21 __license__ = "Public Domain"
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
22 __version__ = "1.1"
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
23 __authors__ = [
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
24 "anatoly techtonik <techtonik@gmail.com>"
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
25 "John Rouillard <rouilj@users.sourceforge.net>"
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
26 ]
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
27
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
28 import os
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
29 import pprint
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
30 import sys
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
31 import textwrap
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
32 try:
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
33 import urllib.parse as url_parser # python 3
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
34 except ImportError:
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
35 import urlparse as url_parser # python 2
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
36
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
37 from argparse import ArgumentParser
5408
e46ce04d5bbc Python 3 preparation: update xmlrpclib / SimpleXMLRPCServer imports.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4938
diff changeset
38 from roundup.anypy import xmlrpc_
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
39
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
40 sname = os.path.basename(sys.argv[0])
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
41 usage = """\
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
42 usage: %s [options] URL
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
43
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
44 URL is XML-RPC endpoint for your tracker, such as:
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
45
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
46 http://localhost:8917/demo/xmlrpc
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
47
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
48 options:
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
49 --pprint (default)
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
50 --json
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
51 --yaml
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
52 --raw
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
53
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
54 -h --help
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
55 --version
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
56 """ % sname
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
57
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
58
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
59 def format_pprint(var):
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
60 return pprint.pformat(var)
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
61
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
62
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
63 def format_json(var):
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
64 jout = pprint.pformat(var)
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
65 jout = jout.replace('"', "\\'") # " to \'
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
66 jout = jout.replace("'", '"') # ' to "
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
67 jout = jout.replace('\\"', "'") # \" to '
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
68 return jout
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
69
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
70
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
71 def format_yaml(var):
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
72 out = pprint.pformat(var)
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
73 out = out.replace('{', ' ')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
74 out = out.replace('}', '')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
75 out = textwrap.dedent(out)
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
76 out = out.replace("'", '')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
77 out = out.replace(' [[', '\n [')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
78 out = out.replace(']]', ']')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
79 out = out.replace('],', '')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
80 out = out.replace(']', '')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
81 out2 = []
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
82 for line in out.splitlines():
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
83 if '[' in line:
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
84 line = ' ' + line.lstrip(' [')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
85 line = line.replace('>', '')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
86 line = line.replace('roundup.hyperdb.', '')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
87 # expandtabs(16) with limit=1
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
88 n, v = line.split(', <')
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
89 if len(n) > 14:
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
90 indent = 0
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
91 else:
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
92 indent = 14 - len(n)
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
93 line = line.replace(', <', ': '+' '*indent)
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
94 line.split(",")
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
95 out2.append(line)
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
96 out = '\n'.join(out2)
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
97 return out
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
98
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
99
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
100 class SpecialTransport():
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
101 """Mixin for http/https transports to implement new send_content with
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
102 CSRF prevention headers to both of them.
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
103 """
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
104 def send_content(self, connection, request_body):
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
105 connection.putheader("Referer", "%s://%s%s%s/" % (
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
106 self.components.scheme,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
107 self.components.hostname,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
108 ':' + str(self.components.port) if self.components.port else '',
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
109 self.components.path))
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
110 connection.putheader("Origin", "%s://%s%s" % (
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
111 self.components.scheme, self.components.hostname,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
112 ':' + str(self.components.port) if self.components.port else ''))
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
113 connection.putheader("X-Requested-With", "XMLHttpRequest")
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
114
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
115 connection.putheader("Content-Type", "text/xml")
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
116 connection.putheader("Content-Length", str(len(request_body)))
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
117 connection.endheaders()
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
118 if request_body:
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
119 connection.send(request_body)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
120
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
121
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
122 class SpecialHttpTransport(SpecialTransport, xmlrpc_.client.Transport,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
123 object):
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
124 """SpecialTransport must be first to use its send_content. Explicit
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
125 object inheritance required for python2 apparently."""
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
126 def __init__(self, url):
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
127 self.components = url_parser.urlparse(url)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
128 # works both python2 (with object inheritance) and python3
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
129 super(SpecialHttpTransport, self).__init__(self)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
130
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
131
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
132 class SpecialHttpsTransport(SpecialTransport, xmlrpc_.client.SafeTransport,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
133 object):
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
134 """SpecialTransport must be first to use its send_content. Explicit
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
135 object inheritance required for python2 apparently."""
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
136 def __init__(self, url):
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
137 self.components = url_parser.urlparse(url)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
138 # works both python2 (with object inheritance) and python3
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
139 super(SpecialHttpsTransport, self).__init__(self)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
140
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
141
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
142 if __name__ == "__main__":
7053
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
143 parser = ArgumentParser()
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
144 parser.add_argument("url", nargs=1)
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
145 parser.add_argument("--raw", action='store_true')
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
146 parser.add_argument("--yaml", action='store_true')
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
147 parser.add_argument("--json", action='store_true')
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
148 parser.add_argument("-v", "--version", action='store_true')
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
149 args = parser.parse_args()
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
150 if args.version:
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
151 sys.exit(sname + " " + __version__)
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
152
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
153 if args.url[0].lower().startswith('https:'):
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
154 transport = SpecialHttpsTransport
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
155 else:
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
156 transport = SpecialHttpTransport
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
157
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
158 roundup_server = xmlrpc_.client.ServerProxy(
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
159 args.url[0],
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
160 transport=transport(args.url[0]),
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
161 verbose=False,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
162 allow_none=True)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
163
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
164 schema = roundup_server.schema()
7053
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
165 if args.raw:
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
166 print(str(schema))
7053
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
167 elif args.yaml:
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
168 print(format_yaml(schema))
7053
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
169 elif args.json:
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
170 print(format_json(schema))
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
171 else:
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
172 print(format_pprint(schema))
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
173
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
174 print("")

Roundup Issue Tracker: http://roundup-tracker.org/