Skip to content

Commit e957067

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

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed
+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from . import processor
22
from . import processor_xml
33
from . import processor_json
4+
from . import processor_txt
45
from . import splitter
56
from . import splitter_json
67
from . import splitter_xml
8+
from . import splitter_txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
import base64
6+
7+
from odoo.addons.component.core import AbstractComponent
8+
9+
10+
class ChunkProcessorTxt(AbstractComponent):
11+
_name = "chunk.importer.txt"
12+
_inherit = "chunk.processor"
13+
_collection = "chunk.item"
14+
_end_of_line = b"\n"
15+
16+
def _parse_data(self):
17+
return base64.b64decode(self.collection.data).split(self._end_of_line)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
if item:
17+
yield idx + 1, item
18+
19+
def _convert_items_to_data(self, items):
20+
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)