Skip to content

Commit 4092ee2

Browse files
committed
chunk_processing: add txt splitter
1 parent 9354a87 commit 4092ee2

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

chunk_processing/components/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
from . import splitter
55
from . import splitter_json
66
from . import splitter_xml
7+
from . import splitter_txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2021 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <[email protected]>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
from odoo.addons.component.core import Component
6+
7+
8+
class ChunkSplitterTxt(Component):
9+
_inherit = "chunk.splitter"
10+
_name = "chunk.splitter.txt"
11+
_usage = "txt"
12+
_end_of_line = b"\n"
13+
14+
def _parse_data(self, data):
15+
for idx, item in enumerate(data.split(self._end_of_line)):
16+
yield idx + 1, item
17+
18+
def _convert_items_to_data(self, items):
19+
return self._end_of_line.join([x[1] for x in items])

chunk_processing/models/chunk_group.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ChunkGroup(models.Model):
2020
[
2121
("json", "Json"),
2222
("xml", "XML"),
23+
("txt", "Txt"),
2324
]
2425
)
2526
xml_split_xpath = fields.Char()

0 commit comments

Comments
 (0)