Skip to content

Commit aff400b

Browse files
committed
[FIX] snippets: use local imports instead of using util
No reason to use the `odoo.upgrade.util` namespace. Part-of: #125 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 86bd61f commit aff400b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/util/snippets.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
from psycopg2.extras import Json
1313

1414
from .exceptions import MigrationError
15-
from odoo.upgrade import util
15+
from .helpers import table_of_model
16+
from .misc import import_script, log_progress
17+
from .pg import column_exists, column_type, get_max_workers, table_exists
1618

1719
_logger = logging.getLogger(__name__)
1820
utf8_parser = html.HTMLParser(encoding="utf-8")
@@ -38,7 +40,7 @@ def add_snippet_names(cr, table, column, snippets, select_query):
3840
_logger.info("Add snippet names on %s.%s", table, column)
3941
cr.execute(select_query)
4042

41-
it = util.log_progress(cr.fetchall(), _logger, qualifier="rows", size=cr.rowcount, log_hundred_percent=True)
43+
it = log_progress(cr.fetchall(), _logger, qualifier="rows", size=cr.rowcount, log_hundred_percent=True)
4244

4345
def quote(ident):
4446
return quote_ident(ident, cr._cnx)
@@ -103,11 +105,11 @@ def html_fields(cr):
103105
"""
104106
)
105107
for model, columns in cr.fetchall():
106-
table = util.table_of_model(cr, model)
107-
if not util.table_exists(cr, table):
108+
table = table_of_model(cr, model)
109+
if not table_exists(cr, table):
108110
# an SQL VIEW
109111
continue
110-
existing_columns = [column for column in columns if util.column_exists(cr, table, column)]
112+
existing_columns = [column for column in columns if column_exists(cr, table, column)]
111113
if existing_columns:
112114
yield table, existing_columns
113115

@@ -169,7 +171,7 @@ def make_pickleable_callback(callback):
169171
"""
170172
callback_filepath = inspect.getfile(callback)
171173
name = f"_upgrade_{uuid.uuid4().hex}"
172-
mod = sys.modules[name] = util.import_script(callback_filepath, name=name)
174+
mod = sys.modules[name] = import_script(callback_filepath, name=name)
173175
try:
174176
return getattr(mod, callback.__name__)
175177
except AttributeError:
@@ -257,7 +259,7 @@ def convert_html_columns(cr, table, columns, converter_callback, where_column="I
257259
"""
258260
assert "id" not in columns
259261

260-
converters = {column: "->>'en_US'" if util.column_type(cr, table, column) == "jsonb" else "" for column in columns}
262+
converters = {column: "->>'en_US'" if column_type(cr, table, column) == "jsonb" else "" for column in columns}
261263
select = ", ".join(f'"{column}"' for column in columns)
262264
where = " OR ".join(f'"{column}"{converters[column]} {where_column}' for column in columns)
263265

@@ -275,9 +277,9 @@ def convert_html_columns(cr, table, columns, converter_callback, where_column="I
275277
update_sql = ", ".join(f'"{column}" = %({column})s' for column in columns)
276278
update_query = f"UPDATE {table} SET {update_sql} WHERE id = %(id)s"
277279

278-
with ProcessPoolExecutor(max_workers=util.get_max_workers()) as executor:
280+
with ProcessPoolExecutor(max_workers=get_max_workers()) as executor:
279281
convert = Convertor(converters, converter_callback)
280-
for query in util.log_progress(split_queries, logger=_logger, qualifier=f"{table} updates"):
282+
for query in log_progress(split_queries, logger=_logger, qualifier=f"{table} updates"):
281283
cr.execute(query)
282284
for data in executor.map(convert, cr.fetchall(), chunksize=1000):
283285
if "id" in data:

0 commit comments

Comments
 (0)