annotate scripts/schema-dump.py @ 8526:0586f25eb25e

ruff: exclusions on imports ignore import locations and import used for side effect
author John Rouillard <rouilj@ieee.org>
date Fri, 20 Feb 2026 16:30:50 -0500
parents 8d81f89ba246
children 9c3ec0a5c7fc
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>"
7783
8d81f89ba246 chore: lint - sort import, add trailing , in dict.
John Rouillard <rouilj@ieee.org>
parents: 7075
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
7783
8d81f89ba246 chore: lint - sort import, add trailing , in dict.
John Rouillard <rouilj@ieee.org>
parents: 7075
diff changeset
32
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
33 try:
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
34 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
35 except ImportError:
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
36 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
37
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
38 from argparse import ArgumentParser
7783
8d81f89ba246 chore: lint - sort import, add trailing , in dict.
John Rouillard <rouilj@ieee.org>
parents: 7075
diff changeset
39
5408
e46ce04d5bbc Python 3 preparation: update xmlrpclib / SimpleXMLRPCServer imports.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4938
diff changeset
40 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
41
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
42 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
43 usage = """\
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
44 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
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 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
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 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
49
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
50 options:
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
51 --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
52 --json
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
53 --yaml
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
54 --raw
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
55
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
56 -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
57 --version
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
58 """ % sname
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
59
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
60
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
61 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
62 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
63
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
64
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
65 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
66 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
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 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
69 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
70 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
71
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
72
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
73 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
74 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
75 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
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 = 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
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(' [[', '\n [')
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 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
82 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
83 out2 = []
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
84 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
85 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
86 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
87 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
88 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
89 # 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
90 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
91 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
92 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
93 else:
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
94 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
95 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
96 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
97 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
98 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
99 return out
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
100
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
101
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
102 class SpecialTransport():
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
103 """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
104 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
105 """
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
106 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
107 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
108 self.components.scheme,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
109 self.components.hostname,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
110 ':' + 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
111 self.components.path))
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
112 connection.putheader("Origin", "%s://%s%s" % (
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
113 self.components.scheme, self.components.hostname,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
114 ':' + 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
115 connection.putheader("X-Requested-With", "XMLHttpRequest")
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
116
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
117 connection.putheader("Content-Type", "text/xml")
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
118 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
119 connection.endheaders()
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
120 if request_body:
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
121 connection.send(request_body)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
122
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
123
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
124 class SpecialHttpTransport(SpecialTransport, xmlrpc_.client.Transport,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
125 object):
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
126 """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
127 object inheritance required for python2 apparently."""
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
128 def __init__(self, url):
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
129 self.components = url_parser.urlparse(url)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
130 # 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
131 super(SpecialHttpTransport, self).__init__(self)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
132
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
133
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
134 class SpecialHttpsTransport(SpecialTransport, xmlrpc_.client.SafeTransport,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
135 object):
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
136 """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
137 object inheritance required for python2 apparently."""
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
138 def __init__(self, url):
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
139 self.components = url_parser.urlparse(url)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
140 # 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
141 super(SpecialHttpsTransport, self).__init__(self)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
142
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
143
4937
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
144 if __name__ == "__main__":
7053
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
145 parser = ArgumentParser()
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
146 parser.add_argument("url", nargs=1)
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
147 parser.add_argument("--raw", action='store_true')
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
148 parser.add_argument("--yaml", action='store_true')
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
149 parser.add_argument("--json", action='store_true')
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
150 parser.add_argument("-v", "--version", action='store_true')
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
151 args = parser.parse_args()
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
152 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
153 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
154
7075
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
155 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
156 transport = SpecialHttpsTransport
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
157 else:
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
158 transport = SpecialHttpTransport
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
159
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
160 roundup_server = xmlrpc_.client.ServerProxy(
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
161 args.url[0],
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
162 transport=transport(args.url[0]),
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
163 verbose=False,
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
164 allow_none=True)
739b9f017d2c issue2551243: Update schema-dump add anti-csrf headers
John Rouillard <rouilj@ieee.org>
parents: 7053
diff changeset
165
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 schema = roundup_server.schema()
7053
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
167 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
168 print(str(schema))
7053
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
169 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
170 print(format_yaml(schema))
7053
b5fffd2a64af issue2551195: port scripts to argparse
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5936
diff changeset
171 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
172 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
173 else:
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(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
175
9369ade6c24b scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
176 print("")

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