structurize 2.16.2__py3-none-any.whl → 2.16.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- avrotize/__init__.py +63 -63
- avrotize/__main__.py +5 -5
- avrotize/_version.py +34 -34
- avrotize/asn1toavro.py +160 -160
- avrotize/avrotize.py +152 -152
- avrotize/avrotocpp.py +483 -483
- avrotize/avrotocsharp.py +992 -992
- avrotize/avrotocsv.py +121 -121
- avrotize/avrotodatapackage.py +173 -173
- avrotize/avrotodb.py +1383 -1383
- avrotize/avrotogo.py +476 -476
- avrotize/avrotographql.py +197 -197
- avrotize/avrotoiceberg.py +210 -210
- avrotize/avrotojava.py +1023 -1023
- avrotize/avrotojs.py +250 -250
- avrotize/avrotojsons.py +481 -481
- avrotize/avrotojstruct.py +345 -345
- avrotize/avrotokusto.py +363 -363
- avrotize/avrotomd.py +137 -137
- avrotize/avrotools.py +168 -168
- avrotize/avrotoparquet.py +208 -208
- avrotize/avrotoproto.py +358 -358
- avrotize/avrotopython.py +622 -622
- avrotize/avrotorust.py +435 -435
- avrotize/avrotots.py +598 -598
- avrotize/avrotoxsd.py +344 -344
- avrotize/commands.json +2493 -2433
- avrotize/common.py +828 -828
- avrotize/constants.py +4 -4
- avrotize/csvtoavro.py +131 -131
- avrotize/datapackagetoavro.py +76 -76
- avrotize/dependency_resolver.py +348 -348
- avrotize/jsonstoavro.py +1698 -1698
- avrotize/jsonstostructure.py +2642 -2642
- avrotize/jstructtoavro.py +878 -878
- avrotize/kstructtoavro.py +93 -93
- avrotize/kustotoavro.py +455 -455
- avrotize/parquettoavro.py +157 -157
- avrotize/proto2parser.py +497 -497
- avrotize/proto3parser.py +402 -402
- avrotize/prototoavro.py +382 -382
- avrotize/structuretocsharp.py +2005 -2005
- avrotize/structuretojsons.py +498 -498
- avrotize/structuretopython.py +772 -772
- avrotize/structuretots.py +653 -0
- avrotize/xsdtoavro.py +413 -413
- structurize-2.16.6.dist-info/METADATA +107 -0
- structurize-2.16.6.dist-info/RECORD +52 -0
- {structurize-2.16.2.dist-info → structurize-2.16.6.dist-info}/licenses/LICENSE +200 -200
- structurize-2.16.2.dist-info/METADATA +0 -805
- structurize-2.16.2.dist-info/RECORD +0 -51
- {structurize-2.16.2.dist-info → structurize-2.16.6.dist-info}/WHEEL +0 -0
- {structurize-2.16.2.dist-info → structurize-2.16.6.dist-info}/entry_points.txt +0 -0
- {structurize-2.16.2.dist-info → structurize-2.16.6.dist-info}/top_level.txt +0 -0
avrotize/avrotize.py
CHANGED
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
"""
|
|
2
|
-
|
|
3
|
-
Command line utility to convert a variety of schema formats to Avrotize schema and vice versa.
|
|
4
|
-
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import argparse
|
|
9
|
-
import tempfile
|
|
10
|
-
import sys
|
|
11
|
-
import os
|
|
12
|
-
import json
|
|
13
|
-
try:
|
|
14
|
-
from avrotize import _version
|
|
15
|
-
VERSION = _version.version
|
|
16
|
-
except ImportError:
|
|
17
|
-
VERSION = "dev"
|
|
18
|
-
|
|
19
|
-
def load_commands():
|
|
20
|
-
"""Load the commands from the commands.json file."""
|
|
21
|
-
commands_path = os.path.join(os.path.dirname(__file__), 'commands.json')
|
|
22
|
-
with open(commands_path, 'r', encoding='utf-8') as f:
|
|
23
|
-
return json.load(f)
|
|
24
|
-
|
|
25
|
-
def create_subparsers(subparsers, commands):
|
|
26
|
-
"""Create subparsers for the commands."""
|
|
27
|
-
for command in commands:
|
|
28
|
-
cmd_parser = subparsers.add_parser(command['command'], help=command['description'])
|
|
29
|
-
for arg in command['args']:
|
|
30
|
-
kwargs = {
|
|
31
|
-
'type': eval(arg['type']),
|
|
32
|
-
'help': arg['help'],
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if 'nargs' in arg:
|
|
36
|
-
kwargs['nargs'] = arg['nargs']
|
|
37
|
-
if 'choices' in arg:
|
|
38
|
-
kwargs['choices'] = arg['choices']
|
|
39
|
-
if 'default' in arg:
|
|
40
|
-
kwargs['default'] = arg['default']
|
|
41
|
-
if arg['type'] == 'bool':
|
|
42
|
-
kwargs['action'] = 'store_true'
|
|
43
|
-
del kwargs['type']
|
|
44
|
-
argname = arg['name']
|
|
45
|
-
if '_' in argname:
|
|
46
|
-
argname2 = argname.replace('_', '-')
|
|
47
|
-
carg = cmd_parser.add_argument(argname, argname2, **kwargs)
|
|
48
|
-
else:
|
|
49
|
-
carg = cmd_parser.add_argument(arg['name'], **kwargs)
|
|
50
|
-
else:
|
|
51
|
-
if '_' in arg['name']:
|
|
52
|
-
argname2 = arg['name'].replace('_', '-')
|
|
53
|
-
carg = cmd_parser.add_argument(arg['name'], argname2, **kwargs)
|
|
54
|
-
else:
|
|
55
|
-
carg = cmd_parser.add_argument(arg['name'], **kwargs)
|
|
56
|
-
carg.required = arg.get('required', True)
|
|
57
|
-
|
|
58
|
-
def dynamic_import(module, func):
|
|
59
|
-
"""Dynamically import a module and function."""
|
|
60
|
-
mod = __import__(module, fromlist=[func])
|
|
61
|
-
return getattr(mod, func)
|
|
62
|
-
|
|
63
|
-
def main():
|
|
64
|
-
"""Main function for the command line utility."""
|
|
65
|
-
commands = load_commands()
|
|
66
|
-
parser = argparse.ArgumentParser(description='Convert a variety of schema formats to Avrotize schema and vice versa.')
|
|
67
|
-
parser.add_argument('--version', action='store_true', help='Print the version of Avrotize.')
|
|
68
|
-
|
|
69
|
-
subparsers = parser.add_subparsers(dest='command')
|
|
70
|
-
create_subparsers(subparsers, commands)
|
|
71
|
-
|
|
72
|
-
args = parser.parse_args()
|
|
73
|
-
|
|
74
|
-
if 'version' in args and args.version:
|
|
75
|
-
print(f'Avrotize {VERSION}')
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
if args.command is None:
|
|
79
|
-
parser.print_help()
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
try:
|
|
83
|
-
command = next((cmd for cmd in commands if cmd['command'] == args.command), None)
|
|
84
|
-
if not command:
|
|
85
|
-
print(f"Error: Command {args.command} not found.")
|
|
86
|
-
exit(1)
|
|
87
|
-
|
|
88
|
-
input_file_path = args.input or getattr(args, 'avsc', None) or getattr(args, 'proto', None) or getattr(args, 'jsons', None) or getattr(args, 'xsd', None) or getattr(args, 'kusto_uri', None) or getattr(args, 'parquet', None) or getattr(args, 'asn', None) or getattr(args, 'kstruct', None)
|
|
89
|
-
temp_input = None
|
|
90
|
-
skip_input_file_handling = command.get('skip_input_file_handling', False)
|
|
91
|
-
if not skip_input_file_handling:
|
|
92
|
-
if input_file_path is None:
|
|
93
|
-
temp_input = tempfile.NamedTemporaryFile(delete=False, mode='w', encoding='utf-8')
|
|
94
|
-
input_file_path = temp_input.name
|
|
95
|
-
# read to EOF
|
|
96
|
-
s = sys.stdin.read()
|
|
97
|
-
while s:
|
|
98
|
-
temp_input.write(s)
|
|
99
|
-
s = sys.stdin.read()
|
|
100
|
-
temp_input.flush()
|
|
101
|
-
temp_input.close()
|
|
102
|
-
|
|
103
|
-
suppress_print = False
|
|
104
|
-
temp_output = None
|
|
105
|
-
output_file_path = ''
|
|
106
|
-
if 'out' in args:
|
|
107
|
-
output_file_path = args.out
|
|
108
|
-
if output_file_path is None:
|
|
109
|
-
suppress_print = True
|
|
110
|
-
temp_output = tempfile.NamedTemporaryFile(delete=False)
|
|
111
|
-
output_file_path = temp_output.name
|
|
112
|
-
|
|
113
|
-
def printmsg(s):
|
|
114
|
-
if not suppress_print:
|
|
115
|
-
print(s)
|
|
116
|
-
|
|
117
|
-
module_name, func_name = command['function']['name'].rsplit('.', 1)
|
|
118
|
-
func = dynamic_import(module_name, func_name)
|
|
119
|
-
func_args = {}
|
|
120
|
-
for arg in command['function']['args']:
|
|
121
|
-
if command['function']['args'][arg] == 'input_file_path':
|
|
122
|
-
func_args[arg] = input_file_path
|
|
123
|
-
elif output_file_path and command['function']['args'][arg] == 'output_file_path':
|
|
124
|
-
func_args[arg] = output_file_path
|
|
125
|
-
else:
|
|
126
|
-
val = command['function']['args'][arg]
|
|
127
|
-
if val.startswith('args.'):
|
|
128
|
-
if hasattr(args, val[5:]):
|
|
129
|
-
func_args[arg] = getattr(args, val[5:])
|
|
130
|
-
else:
|
|
131
|
-
func_args[arg] = val
|
|
132
|
-
if output_file_path:
|
|
133
|
-
printmsg(f'Executing {command["description"]} with input {input_file_path} and output {output_file_path}')
|
|
134
|
-
func(**func_args)
|
|
135
|
-
|
|
136
|
-
if temp_output:
|
|
137
|
-
with open(output_file_path, 'r', encoding='utf-8') as f:
|
|
138
|
-
sys.stdout.write(f.read())
|
|
139
|
-
temp_output.close()
|
|
140
|
-
|
|
141
|
-
except Exception as e:
|
|
142
|
-
print("Error: ", str(e))
|
|
143
|
-
exit(1)
|
|
144
|
-
finally:
|
|
145
|
-
if temp_input:
|
|
146
|
-
try:
|
|
147
|
-
os.remove(temp_input.name)
|
|
148
|
-
except OSError as e:
|
|
149
|
-
print(f"Error: Could not delete temporary input file {temp_input.name}. {e}")
|
|
150
|
-
|
|
151
|
-
if __name__ == "__main__":
|
|
152
|
-
main()
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
Command line utility to convert a variety of schema formats to Avrotize schema and vice versa.
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import tempfile
|
|
10
|
+
import sys
|
|
11
|
+
import os
|
|
12
|
+
import json
|
|
13
|
+
try:
|
|
14
|
+
from avrotize import _version
|
|
15
|
+
VERSION = _version.version
|
|
16
|
+
except ImportError:
|
|
17
|
+
VERSION = "dev"
|
|
18
|
+
|
|
19
|
+
def load_commands():
|
|
20
|
+
"""Load the commands from the commands.json file."""
|
|
21
|
+
commands_path = os.path.join(os.path.dirname(__file__), 'commands.json')
|
|
22
|
+
with open(commands_path, 'r', encoding='utf-8') as f:
|
|
23
|
+
return json.load(f)
|
|
24
|
+
|
|
25
|
+
def create_subparsers(subparsers, commands):
|
|
26
|
+
"""Create subparsers for the commands."""
|
|
27
|
+
for command in commands:
|
|
28
|
+
cmd_parser = subparsers.add_parser(command['command'], help=command['description'])
|
|
29
|
+
for arg in command['args']:
|
|
30
|
+
kwargs = {
|
|
31
|
+
'type': eval(arg['type']),
|
|
32
|
+
'help': arg['help'],
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if 'nargs' in arg:
|
|
36
|
+
kwargs['nargs'] = arg['nargs']
|
|
37
|
+
if 'choices' in arg:
|
|
38
|
+
kwargs['choices'] = arg['choices']
|
|
39
|
+
if 'default' in arg:
|
|
40
|
+
kwargs['default'] = arg['default']
|
|
41
|
+
if arg['type'] == 'bool':
|
|
42
|
+
kwargs['action'] = 'store_true'
|
|
43
|
+
del kwargs['type']
|
|
44
|
+
argname = arg['name']
|
|
45
|
+
if '_' in argname:
|
|
46
|
+
argname2 = argname.replace('_', '-')
|
|
47
|
+
carg = cmd_parser.add_argument(argname, argname2, **kwargs)
|
|
48
|
+
else:
|
|
49
|
+
carg = cmd_parser.add_argument(arg['name'], **kwargs)
|
|
50
|
+
else:
|
|
51
|
+
if '_' in arg['name']:
|
|
52
|
+
argname2 = arg['name'].replace('_', '-')
|
|
53
|
+
carg = cmd_parser.add_argument(arg['name'], argname2, **kwargs)
|
|
54
|
+
else:
|
|
55
|
+
carg = cmd_parser.add_argument(arg['name'], **kwargs)
|
|
56
|
+
carg.required = arg.get('required', True)
|
|
57
|
+
|
|
58
|
+
def dynamic_import(module, func):
|
|
59
|
+
"""Dynamically import a module and function."""
|
|
60
|
+
mod = __import__(module, fromlist=[func])
|
|
61
|
+
return getattr(mod, func)
|
|
62
|
+
|
|
63
|
+
def main():
|
|
64
|
+
"""Main function for the command line utility."""
|
|
65
|
+
commands = load_commands()
|
|
66
|
+
parser = argparse.ArgumentParser(description='Convert a variety of schema formats to Avrotize schema and vice versa.')
|
|
67
|
+
parser.add_argument('--version', action='store_true', help='Print the version of Avrotize.')
|
|
68
|
+
|
|
69
|
+
subparsers = parser.add_subparsers(dest='command')
|
|
70
|
+
create_subparsers(subparsers, commands)
|
|
71
|
+
|
|
72
|
+
args = parser.parse_args()
|
|
73
|
+
|
|
74
|
+
if 'version' in args and args.version:
|
|
75
|
+
print(f'Avrotize {VERSION}')
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
if args.command is None:
|
|
79
|
+
parser.print_help()
|
|
80
|
+
return
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
command = next((cmd for cmd in commands if cmd['command'] == args.command), None)
|
|
84
|
+
if not command:
|
|
85
|
+
print(f"Error: Command {args.command} not found.")
|
|
86
|
+
exit(1)
|
|
87
|
+
|
|
88
|
+
input_file_path = args.input or getattr(args, 'avsc', None) or getattr(args, 'proto', None) or getattr(args, 'jsons', None) or getattr(args, 'xsd', None) or getattr(args, 'kusto_uri', None) or getattr(args, 'parquet', None) or getattr(args, 'asn', None) or getattr(args, 'kstruct', None)
|
|
89
|
+
temp_input = None
|
|
90
|
+
skip_input_file_handling = command.get('skip_input_file_handling', False)
|
|
91
|
+
if not skip_input_file_handling:
|
|
92
|
+
if input_file_path is None:
|
|
93
|
+
temp_input = tempfile.NamedTemporaryFile(delete=False, mode='w', encoding='utf-8')
|
|
94
|
+
input_file_path = temp_input.name
|
|
95
|
+
# read to EOF
|
|
96
|
+
s = sys.stdin.read()
|
|
97
|
+
while s:
|
|
98
|
+
temp_input.write(s)
|
|
99
|
+
s = sys.stdin.read()
|
|
100
|
+
temp_input.flush()
|
|
101
|
+
temp_input.close()
|
|
102
|
+
|
|
103
|
+
suppress_print = False
|
|
104
|
+
temp_output = None
|
|
105
|
+
output_file_path = ''
|
|
106
|
+
if 'out' in args:
|
|
107
|
+
output_file_path = args.out
|
|
108
|
+
if output_file_path is None:
|
|
109
|
+
suppress_print = True
|
|
110
|
+
temp_output = tempfile.NamedTemporaryFile(delete=False)
|
|
111
|
+
output_file_path = temp_output.name
|
|
112
|
+
|
|
113
|
+
def printmsg(s):
|
|
114
|
+
if not suppress_print:
|
|
115
|
+
print(s)
|
|
116
|
+
|
|
117
|
+
module_name, func_name = command['function']['name'].rsplit('.', 1)
|
|
118
|
+
func = dynamic_import(module_name, func_name)
|
|
119
|
+
func_args = {}
|
|
120
|
+
for arg in command['function']['args']:
|
|
121
|
+
if command['function']['args'][arg] == 'input_file_path':
|
|
122
|
+
func_args[arg] = input_file_path
|
|
123
|
+
elif output_file_path and command['function']['args'][arg] == 'output_file_path':
|
|
124
|
+
func_args[arg] = output_file_path
|
|
125
|
+
else:
|
|
126
|
+
val = command['function']['args'][arg]
|
|
127
|
+
if val.startswith('args.'):
|
|
128
|
+
if hasattr(args, val[5:]):
|
|
129
|
+
func_args[arg] = getattr(args, val[5:])
|
|
130
|
+
else:
|
|
131
|
+
func_args[arg] = val
|
|
132
|
+
if output_file_path:
|
|
133
|
+
printmsg(f'Executing {command["description"]} with input {input_file_path} and output {output_file_path}')
|
|
134
|
+
func(**func_args)
|
|
135
|
+
|
|
136
|
+
if temp_output:
|
|
137
|
+
with open(output_file_path, 'r', encoding='utf-8') as f:
|
|
138
|
+
sys.stdout.write(f.read())
|
|
139
|
+
temp_output.close()
|
|
140
|
+
|
|
141
|
+
except Exception as e:
|
|
142
|
+
print("Error: ", str(e))
|
|
143
|
+
exit(1)
|
|
144
|
+
finally:
|
|
145
|
+
if temp_input:
|
|
146
|
+
try:
|
|
147
|
+
os.remove(temp_input.name)
|
|
148
|
+
except OSError as e:
|
|
149
|
+
print(f"Error: Could not delete temporary input file {temp_input.name}. {e}")
|
|
150
|
+
|
|
151
|
+
if __name__ == "__main__":
|
|
152
|
+
main()
|