Skip to content

[IMP] *: deprecate ustr() #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions odoo_module_migrate/migration_scripts/migrate_170_180.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,33 @@ def replace_user_has_groups(
logger.error(f"Error processing file {file}: {str(e)}")


def replace_ustr(
logger, module_path, module_name, manifest_path, migration_steps, tools
):
files_to_process = tools.get_files(module_path, (".py",))
replaces = {
r"from\s+odoo\.tools\s+import\s+ustr\s*\n": "",
r"from\s+odoo\.tools\.misc\s+import\s+ustr\s*\n": "",
r"from\s+odoo\.tools\s+import\s+([^,\n]*,\s*)?ustr,\s*([^,\n]*)": r"from odoo.tools import \1\2",
r"from\s+odoo\.tools\.misc\s+import\s+([^,\n]*,\s*)?ustr,\s*([^,\n]*)": r"from odoo.tools.misc import \1\2",
r",\s*ustr(\s*,)?": r"\1",
r"tools\.ustr\(([^)]+)\)": r"\1",
r"misc\.ustr\(([^)]+)\)": r"\1",
r"=\s*ustr\(([^)]+)\)": r"= \1",
}
for file in files_to_process:
try:
tools._replace_in_file(
file, replaces, log_message=f"Deprecate ustr in: {file}"
)
except Exception as e:
logger.error(f"Error processing file {file}: {str(e)}")


class MigrationScript(BaseMigrationScript):
_GLOBAL_FUNCTIONS = [
replace_tree_with_list_in_views,
replace_chatter_blocks,
replace_user_has_groups,
replace_ustr,
]
1 change: 1 addition & 0 deletions tests/data_result/module_170_180/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import res_partner
from . import fetchmail
20 changes: 20 additions & 0 deletions tests/data_result/module_170_180/models/fetchmail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from odoo import models, tools, _
from odoo.tools import misc
from odoo.tools.misc import find_in_path
from odoo.tools import config, consteq, file_path
from odoo.tools.misc import lazy
from odoo.tools import config, consteq, file_path
from ssl import SSLError
from odoo.exceptions import UserError


class FetchMailServer(models.Model):
_inherit = "fetchmail.server"

def example_method_use_ustr(self):
try:
server_name = self.name
description = self._description
connection = self.connect(allow_archived=True)
except SSLError as e:
raise UserError(_(e))
1 change: 1 addition & 0 deletions tests/data_template/module_170/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import res_partner
from . import fetchmail
22 changes: 22 additions & 0 deletions tests/data_template/module_170/models/fetchmail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo import models, tools, _
from odoo.tools import misc
from odoo.tools import ustr
from odoo.tools.misc import ustr
from odoo.tools.misc import ustr, find_in_path
from odoo.tools import ustr, config, consteq, file_path
from odoo.tools.misc import lazy, ustr
from odoo.tools import config, consteq, ustr, file_path
from ssl import SSLError
from odoo.exceptions import UserError


class FetchMailServer(models.Model):
_inherit = "fetchmail.server"

def example_method_use_ustr(self):
try:
server_name = ustr(self.name)
description = misc.ustr(self._description)
connection = self.connect(allow_archived=True)
except SSLError as e:
raise UserError(_(tools.ustr(e)))
Loading