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