Skip to content

Commit 723f224

Browse files
Bruno Zanottilef-adhoc
authored andcommitted
[IMP] add _get_files as a common tool
1 parent 20d98f8 commit 723f224

2 files changed

Lines changed: 8 additions & 22 deletions

File tree

odoo_module_migrate/migration_scripts/migrate_130_140.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pathlib import Path
88
import lxml.etree as et
99
from odoo_module_migrate.base_migration_script import BaseMigrationScript
10+
from ..tools import get_files
1011

1112

1213
def src_model_new_value(field_elem, model_dot_name):
@@ -112,15 +113,6 @@ def _reformat_file(file_path: Path):
112113
return file_path
113114

114115

115-
def _get_files(module_path, reformat_file_ext):
116-
"""Get files to be reformatted."""
117-
file_paths = list()
118-
if not module_path.is_dir():
119-
raise Exception(f"'{module_path}' is not a directory")
120-
file_paths.extend(module_path.rglob("*" + reformat_file_ext))
121-
return file_paths
122-
123-
124116
def reformat_deprecated_tags(
125117
logger, module_path, module_name, manifest_path, migration_steps, tools
126118
):
@@ -130,8 +122,8 @@ def reformat_deprecated_tags(
130122
they have to be substituted by the `record` tag.
131123
"""
132124

133-
reformat_file_ext = ".xml"
134-
file_paths = _get_files(module_path, reformat_file_ext)
125+
reformat_file_ext = (".xml")
126+
file_paths = get_files(module_path, reformat_file_ext)
135127
logger.debug(f"{reformat_file_ext} files found:\n" f"{list(map(str, file_paths))}")
136128

137129
reformatted_files = list()

odoo_module_migrate/migration_scripts/migrate_160_170.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import ast
99
from typing import Any
10+
from ..tools import get_files
1011

1112
empty_list = ast.parse("[]").body[0].value
1213

@@ -236,13 +237,6 @@ def replace_read_group_signature(logger, filename):
236237
file.write(new_all)
237238

238239

239-
def _get_files(module_path, reformat_file_ext):
240-
"""Get files to be reformatted."""
241-
file_paths = list()
242-
if not module_path.is_dir():
243-
raise Exception(f"'{module_path}' is not a directory")
244-
file_paths.extend(module_path.rglob("*" + reformat_file_ext))
245-
return file_paths
246240

247241

248242
def _check_open_form_view(logger, file_path: Path):
@@ -264,8 +258,8 @@ def _check_open_form_view(logger, file_path: Path):
264258
def _check_open_form(
265259
logger, module_path, module_name, manifest_path, migration_steps, tools
266260
):
267-
reformat_file_ext = ".xml"
268-
file_paths = _get_files(module_path, reformat_file_ext)
261+
reformat_file_ext = (".xml")
262+
file_paths = get_files(module_path, reformat_file_ext)
269263
logger.debug(f"{reformat_file_ext} files found:\n" f"{list(map(str, file_paths))}")
270264

271265
for file_path in file_paths:
@@ -277,8 +271,8 @@ def _reformat_read_group(
277271
):
278272
"""Reformat read_group method in py files."""
279273

280-
reformat_file_ext = ".py"
281-
file_paths = _get_files(module_path, reformat_file_ext)
274+
reformat_file_ext = (".py")
275+
file_paths = get_files(module_path, reformat_file_ext)
282276
logger.debug(f"{reformat_file_ext} files found:\n" f"{list(map(str, file_paths))}")
283277

284278
reformatted_files = list()

0 commit comments

Comments
 (0)