Skip to content

Commit 9923582

Browse files
committed
scripts/schema-dump.py: New script to dump schema from tracker through XML-RPC
1 parent 43204a4 commit 9923582

File tree

2 files changed

+107
-1
lines changed

2 files changed

+107
-1
lines changed

scripts/schema-dump.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Use recently documented XML-RPC API to dump
5+
Roundup data schema in human readable form.
6+
7+
Future development may cover:
8+
[ ] unreadable dump formats
9+
[ ] access to local database
10+
[ ] lossless dump/restore cycle
11+
[ ] data dump and filtering with preserved
12+
"""
13+
__license__ = "Public Domain"
14+
__version__ = "1.0"
15+
__authors__ = [
16+
"anatoly techtonik <[email protected]>"
17+
]
18+
19+
import os
20+
import sys
21+
import xmlrpclib
22+
import pprint
23+
import textwrap
24+
from optparse import OptionParser
25+
26+
sname = os.path.basename(sys.argv[0])
27+
usage = """\
28+
usage: %s [options] URL
29+
30+
URL is XML-RPC endpoint for your tracker, such as:
31+
32+
http://localhost:8917/demo/xmlrpc
33+
34+
options:
35+
--pprint (default)
36+
--json
37+
--yaml
38+
--raw
39+
40+
-h --help
41+
--version
42+
""" % sname
43+
44+
def format_pprint(var):
45+
return pprint.pformat(var)
46+
47+
def format_json(var):
48+
jout = pprint.pformat(var)
49+
jout = jout.replace('"', "\\'") # " to \'
50+
jout = jout.replace("'", '"') # ' to "
51+
jout = jout.replace('\\"', "'") # \" to '
52+
return jout
53+
54+
def format_yaml(var):
55+
out = pprint.pformat(var)
56+
out = out.replace('{', ' ')
57+
out = out.replace('}', '')
58+
out = textwrap.dedent(out)
59+
out = out.replace("'", '')
60+
out = out.replace(' [[', '\n [')
61+
out = out.replace(']]', ']')
62+
out = out.replace('],', '')
63+
out = out.replace(']', '')
64+
out2 = []
65+
for line in out.splitlines():
66+
if '[' in line:
67+
line = ' ' + line.lstrip(' [')
68+
line = line.replace('>', '')
69+
line = line.replace('roundup.hyperdb.', '')
70+
# expandtabs(16) with limit=1
71+
n, v = line.split(', <')
72+
if len(n) > 14:
73+
indent = 0
74+
else:
75+
indent = 14 - len(n)
76+
line = line.replace(', <', ': '+' '*indent)
77+
line.split(",")
78+
out2.append(line)
79+
out = '\n'.join(out2)
80+
return out
81+
82+
if __name__ == "__main__":
83+
if len(sys.argv) < 2 or "-h" in sys.argv or "--help" in sys.argv:
84+
sys.exit(usage)
85+
if "--version" in sys.argv:
86+
sys.exit(sname + " " + __version__)
87+
88+
parser = OptionParser()
89+
parser.add_option("--raw", action='store_true')
90+
parser.add_option("--yaml", action='store_true')
91+
parser.add_option("--json", action='store_true')
92+
(options, args) = parser.parse_args()
93+
94+
print sys.argv, args
95+
url = args[0]
96+
roundup_server = xmlrpclib.ServerProxy(url, allow_none=True)
97+
schema = roundup_server.schema()
98+
if options.raw:
99+
print(str(schema))
100+
elif options.yaml:
101+
print(format_yaml(schema))
102+
elif options.json:
103+
print(format_json(schema))
104+
else:
105+
print(format_pprint(schema))
106+
107+
print("")

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
1212
# POSSIBILITY OF SUCH DAMAGE.
1313
#
14-
# BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
1514
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1615
# FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
1716
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,

0 commit comments

Comments
 (0)