Skip to content

Commit

Permalink
chunk_processing: add txt splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbeau committed May 10, 2022
1 parent 9354a87 commit 4092ee2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions chunk_processing/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from . import splitter
from . import splitter_json
from . import splitter_xml
from . import splitter_txt
19 changes: 19 additions & 0 deletions chunk_processing/components/splitter_txt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2021 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.addons.component.core import Component


class ChunkSplitterTxt(Component):
_inherit = "chunk.splitter"
_name = "chunk.splitter.txt"
_usage = "txt"
_end_of_line = b"\n"

def _parse_data(self, data):
for idx, item in enumerate(data.split(self._end_of_line)):
yield idx + 1, item

def _convert_items_to_data(self, items):
return self._end_of_line.join([x[1] for x in items])
1 change: 1 addition & 0 deletions chunk_processing/models/chunk_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ChunkGroup(models.Model):
[
("json", "Json"),
("xml", "XML"),
("txt", "Txt"),
]
)
xml_split_xpath = fields.Char()
Expand Down

0 comments on commit 4092ee2

Please sign in to comment.