tabpro 0.4.0__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.
- tabpro/__init__.py +7 -0
- tabpro/cli.py +87 -0
- tabpro/commands/convert_tables.py +86 -0
- tabpro/commands/merge_tables.py +76 -0
- tabpro/core/actions.py +752 -0
- tabpro/core/config.py +357 -0
- tabpro/core/constants.py +5 -0
- tabpro/core/convert.py +209 -0
- tabpro/core/functions/assign_id.py +153 -0
- tabpro/core/functions/flatten_row.py +24 -0
- tabpro/core/functions/get_nested_field_value.py +31 -0
- tabpro/core/functions/nest_row.py +25 -0
- tabpro/core/functions/search_column_value.py +26 -0
- tabpro/core/functions/set_flat_field_value.py +23 -0
- tabpro/core/functions/set_nested_field_value.py +41 -0
- tabpro/core/functions/set_row_value.py +33 -0
- tabpro/core/io/__init__.py +12 -0
- tabpro/core/io/io_csv.py +41 -0
- tabpro/core/io/io_excel.py +45 -0
- tabpro/core/io/io_json.py +86 -0
- tabpro/core/io/loader.py +33 -0
- tabpro/core/io/saver.py +31 -0
- tabpro/core/merge.py +184 -0
- tabpro/core/types.py +146 -0
- tabpro-0.4.0.dist-info/LICENSE +21 -0
- tabpro-0.4.0.dist-info/METADATA +30 -0
- tabpro-0.4.0.dist-info/RECORD +29 -0
- tabpro-0.4.0.dist-info/WHEEL +4 -0
- tabpro-0.4.0.dist-info/entry_points.txt +7 -0
tabpro/__init__.py
ADDED
tabpro/cli.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from icecream import ic
|
|
9
|
+
|
|
10
|
+
def parse_and_run(
|
|
11
|
+
parser: argparse.ArgumentParser,
|
|
12
|
+
):
|
|
13
|
+
if os.environ.get('DEBUG', '').lower() in ['1', 'true', 'yes', 'on']:
|
|
14
|
+
pass
|
|
15
|
+
else:
|
|
16
|
+
ic.disable()
|
|
17
|
+
ic()
|
|
18
|
+
args = parser.parse_args()
|
|
19
|
+
if args.verbose:
|
|
20
|
+
ic.enable()
|
|
21
|
+
ic(args)
|
|
22
|
+
if args.handler:
|
|
23
|
+
args.handler(args)
|
|
24
|
+
else:
|
|
25
|
+
parser.print_help()
|
|
26
|
+
sys.exit(1)
|
|
27
|
+
|
|
28
|
+
def command_convert_tables(
|
|
29
|
+
parser: argparse.ArgumentParser|None = None,
|
|
30
|
+
):
|
|
31
|
+
if parser is None:
|
|
32
|
+
command_parser = argparse.ArgumentParser(
|
|
33
|
+
description='Convert a table to a different format.'
|
|
34
|
+
)
|
|
35
|
+
else:
|
|
36
|
+
command_parser = parser
|
|
37
|
+
from table_processor.commands.convert_tables import setup_parser
|
|
38
|
+
setup_parser(command_parser)
|
|
39
|
+
if parser is None:
|
|
40
|
+
parse_and_run(command_parser)
|
|
41
|
+
|
|
42
|
+
def command_merge_tables(
|
|
43
|
+
parser: argparse.ArgumentParser|None = None,
|
|
44
|
+
):
|
|
45
|
+
if parser is None:
|
|
46
|
+
command_parser = argparse.ArgumentParser(
|
|
47
|
+
description='Merge tables.'
|
|
48
|
+
)
|
|
49
|
+
else:
|
|
50
|
+
command_parser = parser
|
|
51
|
+
from table_processor.commands.merge_tables import setup_parser
|
|
52
|
+
setup_parser(command_parser)
|
|
53
|
+
if parser is None:
|
|
54
|
+
parse_and_run(command_parser)
|
|
55
|
+
|
|
56
|
+
def setup_common_args(
|
|
57
|
+
parser: argparse.ArgumentParser,
|
|
58
|
+
):
|
|
59
|
+
parser.add_argument(
|
|
60
|
+
'--verbose', '-v',
|
|
61
|
+
action='store_true',
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
def main():
|
|
65
|
+
parser = argparse.ArgumentParser(description='Table Data Converter')
|
|
66
|
+
setup_common_args(parser)
|
|
67
|
+
parser.set_defaults(handler=None)
|
|
68
|
+
subparsers = parser.add_subparsers(dest='command')
|
|
69
|
+
|
|
70
|
+
parser_convert_tables = subparsers.add_parser(
|
|
71
|
+
'convert',
|
|
72
|
+
help='Convert a table to a different format.'
|
|
73
|
+
)
|
|
74
|
+
setup_common_args(parser_convert_tables)
|
|
75
|
+
command_convert_tables(parser_convert_tables)
|
|
76
|
+
|
|
77
|
+
parser_merge_tables = subparsers.add_parser(
|
|
78
|
+
'merge',
|
|
79
|
+
help='Merge tables.'
|
|
80
|
+
)
|
|
81
|
+
setup_common_args(parser_merge_tables)
|
|
82
|
+
command_merge_tables(parser_merge_tables)
|
|
83
|
+
|
|
84
|
+
parse_and_run(parser)
|
|
85
|
+
|
|
86
|
+
if __name__ == '__main__':
|
|
87
|
+
main()
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
from icecream import ic
|
|
6
|
+
|
|
7
|
+
from .. core.convert import convert
|
|
8
|
+
|
|
9
|
+
def run(
|
|
10
|
+
args: argparse.Namespace,
|
|
11
|
+
):
|
|
12
|
+
convert(
|
|
13
|
+
input_files = args.input_files,
|
|
14
|
+
output_file = args.output_file,
|
|
15
|
+
output_file_filtered_out = args.output_file_filtered_out,
|
|
16
|
+
config_path = args.config,
|
|
17
|
+
list_actions = args.do_actions,
|
|
18
|
+
list_pick_columns = args.pick_columns,
|
|
19
|
+
action_delimiter = args.action_delimiter,
|
|
20
|
+
output_debug = args.output_debug,
|
|
21
|
+
verbose = args.verbose,
|
|
22
|
+
ignore_file_rows = args.ignore_file_rows,
|
|
23
|
+
skip_header = args.skip_header,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def setup_parser(
|
|
27
|
+
parser: argparse.ArgumentParser,
|
|
28
|
+
):
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
'input_files',
|
|
31
|
+
metavar='INPUT_FILE',
|
|
32
|
+
nargs='+',
|
|
33
|
+
help='Path to the input file.'
|
|
34
|
+
)
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
'--output-file', '--output', '-o',
|
|
37
|
+
metavar='OUTPUT_FILE',
|
|
38
|
+
required=False,
|
|
39
|
+
help='Path to the output file.'
|
|
40
|
+
)
|
|
41
|
+
parser.add_argument(
|
|
42
|
+
'--output-file-filtered-out', '--output-filtered-out', '-f',
|
|
43
|
+
metavar='OUTPUT_FILE_FILTERED_OUT',
|
|
44
|
+
required=False,
|
|
45
|
+
help='Path to the output file for filtered out rows.',
|
|
46
|
+
)
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
'--config', '-c',
|
|
49
|
+
type=str,
|
|
50
|
+
help='Path to the configuration file.',
|
|
51
|
+
)
|
|
52
|
+
parser.add_argument(
|
|
53
|
+
'--pick-columns', '--pick',
|
|
54
|
+
type=str,
|
|
55
|
+
nargs='+',
|
|
56
|
+
help='Pick column map',
|
|
57
|
+
)
|
|
58
|
+
parser.add_argument(
|
|
59
|
+
'--action-delimiter', '--do-delimiter', '--do-delim',
|
|
60
|
+
type=str,
|
|
61
|
+
default=':',
|
|
62
|
+
help='Action delimiter',
|
|
63
|
+
)
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
'--do-actions', '--actions', '--do',
|
|
66
|
+
nargs='+',
|
|
67
|
+
type=str,
|
|
68
|
+
help='Actions to do',
|
|
69
|
+
)
|
|
70
|
+
parser.add_argument(
|
|
71
|
+
'--ignore-file-rows', '--ignore-rows', '--ignore',
|
|
72
|
+
nargs='+',
|
|
73
|
+
type=str,
|
|
74
|
+
help='Ignore tuples of file name and row index',
|
|
75
|
+
)
|
|
76
|
+
parser.add_argument(
|
|
77
|
+
'--output-debug',
|
|
78
|
+
action='store_true',
|
|
79
|
+
help='Output debug information',
|
|
80
|
+
)
|
|
81
|
+
parser.add_argument(
|
|
82
|
+
'--skip-header',
|
|
83
|
+
action='store_true',
|
|
84
|
+
help='Skip header',
|
|
85
|
+
)
|
|
86
|
+
parser.set_defaults(handler=run)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
from icecream import ic
|
|
6
|
+
|
|
7
|
+
from .. core.merge import merge
|
|
8
|
+
|
|
9
|
+
def run(
|
|
10
|
+
args: argparse.Namespace,
|
|
11
|
+
):
|
|
12
|
+
merge(
|
|
13
|
+
previous_files=args.previous_files,
|
|
14
|
+
modification_files=args.modification_files,
|
|
15
|
+
keys=args.keys,
|
|
16
|
+
allow_duplicate_keys=args.allow_duplicate_keys,
|
|
17
|
+
ignore_not_found=args.ignore_not_found,
|
|
18
|
+
output_base_data_file=args.output_base_data_file,
|
|
19
|
+
output_modified_data_file=args.output_modified_data_file,
|
|
20
|
+
output_remaining_data_file=args.output_remaining_data_file,
|
|
21
|
+
merge_fields=args.merge_fields,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def setup_parser(
|
|
25
|
+
parser: argparse.ArgumentParser,
|
|
26
|
+
):
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
'--previous-files', '--previous-file', '--previous', '--old', '-P',
|
|
29
|
+
nargs='+',
|
|
30
|
+
required=True,
|
|
31
|
+
help='Previous files to merge',
|
|
32
|
+
)
|
|
33
|
+
parser.add_argument(
|
|
34
|
+
'--modification-files', '--modification', '--modify', '--modified', '--new', '-M',
|
|
35
|
+
nargs='+',
|
|
36
|
+
required=True,
|
|
37
|
+
help='Modification files to merge',
|
|
38
|
+
)
|
|
39
|
+
parser.add_argument(
|
|
40
|
+
'--keys', '-K',
|
|
41
|
+
nargs='+',
|
|
42
|
+
required=True,
|
|
43
|
+
help='Primary keys',
|
|
44
|
+
)
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
'--allow-duplicate-keys', '--allow-duplicate',
|
|
47
|
+
action='store_true',
|
|
48
|
+
help='Allow duplicate keys',
|
|
49
|
+
)
|
|
50
|
+
parser.add_argument(
|
|
51
|
+
'--ignore-not-found',
|
|
52
|
+
action='store_true',
|
|
53
|
+
help='Ignore not found',
|
|
54
|
+
)
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
'--output-base-data-file', '--output-base',
|
|
57
|
+
required=False,
|
|
58
|
+
help='Path to output base data file',
|
|
59
|
+
)
|
|
60
|
+
parser.add_argument(
|
|
61
|
+
'--output-modified-data-file', '--output-modified',
|
|
62
|
+
required=False,
|
|
63
|
+
help='Path to output modified data file',
|
|
64
|
+
)
|
|
65
|
+
parser.add_argument(
|
|
66
|
+
'--output-remaining-data-file', '--output-remaining', '--output-remain',
|
|
67
|
+
required=False,
|
|
68
|
+
help='Path to output remaining data file',
|
|
69
|
+
)
|
|
70
|
+
parser.add_argument(
|
|
71
|
+
'--merge-fields', '--merge-field', '--merge-keys', '--merge-key',
|
|
72
|
+
nargs='+',
|
|
73
|
+
required=False,
|
|
74
|
+
help='Fields to merge',
|
|
75
|
+
)
|
|
76
|
+
parser.set_defaults(handler=run)
|