Skip to content

Commit

Permalink
fixup! [IMP] snippets: move all work from parent to mp workers
Browse files Browse the repository at this point in the history
  • Loading branch information
cawo-odoo committed Nov 14, 2024
1 parent fe9b2c8 commit 0ee95a6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/util/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
from .misc import import_script, log_progress
from .pg import column_exists, column_type, get_max_workers, table_exists

# python3 shims
try:
basestring # noqa: B018
except NameError:
basestring = unicode = str

_logger = logging.getLogger(__name__)
utf8_parser = html.HTMLParser(encoding="utf-8")

Expand Down Expand Up @@ -248,17 +254,22 @@ def _dumps(self, node):


class Convertor:
def __init__(self, converters, callback, dbname, update_query):
def __init__(self, converters, callback, dbname=None, update_query=None):
self.converters = converters
self.callback = callback
self.dbname = dbname
self.update_query = update_query

def __call__(self, query):
# backwards compatibility
if not (self.dbname and self.update_query and isinstance(query, basestring)):
return self._convert_row(query)
# called with a query to fetch a number of rows
with db_connect(self.dbname).cursor() as cr:
cr.execute(query)
for changes in filter(None, map(self._convert_row, cr.fetchall())):
cr.execute(self.update_query, changes)
return None

def _convert_row(self, row):
converters = self.converters
Expand Down

0 comments on commit 0ee95a6

Please sign in to comment.