Skip to content

Commit

Permalink
[ADD][14.0] Support for --upgrade-path and apriori.json
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanRijnhart committed Dec 6, 2020
1 parent 01f33c9 commit e06a7f5
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#
##############################################################################

import json
import sys
import os
import inspect
Expand Down Expand Up @@ -58,6 +59,7 @@ def __exit__(self, exc_type, exc_value, traceback):
from psycopg2.extensions import AsIs
from lxml import etree
from . import openupgrade_tools
from .apriori import Apriori

core = None
# The order matters here. We can import odoo in 9.0, but then we get odoo.py
Expand Down Expand Up @@ -269,7 +271,7 @@ def load_data(cr, module_name, filename, idref=None, mode='init'):
:param module_name: the name of the module
:param filename: the path to the filename, relative to the module \
directory.
directory. This may also be the module directory relative to --upgrade-path
:param idref: optional hash with ?id mapping cache?
:param mode:
one of 'init', 'update', 'demo', 'init_no_create'.
Expand All @@ -288,7 +290,15 @@ def load_data(cr, module_name, filename, idref=None, mode='init'):
logger.info('%s: loading %s' % (module_name, filename))
_, ext = os.path.splitext(filename)
pathname = os.path.join(module_name, filename)
fp = tools.file_open(pathname)

try:
fp = tools.file_open(pathname)
except OSError:
if tools.config.get('upgrade_path'):
pathname = os.path.join(
tools.config['upgrade_path'], module_name, filename)
fp = open(pathname)

try:
if ext == '.csv':
noupdate = True
Expand Down Expand Up @@ -2558,3 +2568,22 @@ def convert_to_company_dependent(
)
), args,
)


def _load_apriori(path=None):
""" Load a 14.0+ Apriori object from apriori.json in the root of the
--upgrade-path """
if path is None:
from odoo import tools
path = tools.config['upgrade_path']
apriori_path = os.path.join(path, "apriori.json")
try:
with open(apriori_path) as json_file:
apriori_dict = json.load(json_file)
except FileNotFoundError:
raise UserError(
"Could not import apriori.json: file %s not found" % apriori_path
)
except ValueError:
raise UserError("The contents of apriori.json is not valid json")
return Apriori(apriori_dict)

0 comments on commit e06a7f5

Please sign in to comment.