Skip to content

Commit eebb40c

Browse files
committed
[FIX] server: allow creating full path
It is possible to create a full path when creating a file. For example, you can create test/dummy/file.py if dummy doesn't exist. Then dummy AND file will be created in one command. The actual listener to new files wasn't handling it.
1 parent de26cf9 commit eebb40c

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

server/core/odoo.py

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,28 @@ def build_modules(self, ls):
388388
pass
389389
ls.show_message_log(str(len(Odoo.get().modules)) + " modules found")
390390

391+
def get_loaded_part_tree(self, path):
392+
#given a path, return the deepest loaded symbol that match it and the remaining path.
393+
# Ex: if odoo/addons/test/models is loaded, the path odoo/addons/test/models/test.py will return
394+
# (odoo/addons/test/models, "test.py"). the first element is a symbol. return None, None if not in the project
395+
addonSymbol = self.symbols.get_symbol(["odoo", "addons"])
396+
if not addonSymbol:
397+
return ()
398+
symbol = addonSymbol
399+
for dir_path in [self.instance.odooPath] + addonSymbol.paths:
400+
if path.startswith(dir_path):
401+
remains = path.replace(dir_path, "", 1).replace("\\", "/").split("/")
402+
remains.pop(0)
403+
el = remains.pop(0)
404+
while el:
405+
next_symbol = symbol.get_symbol([el])
406+
if not next_symbol:
407+
return symbol, [el] + remains
408+
symbol = next_symbol
409+
el = remains.pop(0)
410+
return symbol, []
411+
return None, None
412+
391413
def get_file_symbol(self, path):
392414
addonSymbol = self.symbols.get_symbol(["odoo", "addons"])
393415
if not addonSymbol:
@@ -430,7 +452,7 @@ def _build_new_symbol(self, ls, path, parent):
430452
pp = PythonArchBuilder(ls, parent, path)
431453
new_symbol = pp.load_arch()
432454
new_symbol_tree = new_symbol.get_tree()
433-
return new_symbol_tree
455+
return new_symbol, new_symbol_tree
434456

435457
def file_change(self, ls, path, text, version):
436458
#snapshot1 = tracemalloc.take_snapshot()
@@ -446,7 +468,7 @@ def file_change(self, ls, path, text, version):
446468
if not parent:
447469
return
448470
#build new
449-
new_symbol_tree = self._build_new_symbol(ls, path, parent)
471+
_, new_symbol_tree = self._build_new_symbol(ls, path, parent)
450472
#rebuild validations
451473
if new_symbol_tree:
452474
self._search_symbols_to_rebuild(new_symbol_tree)
@@ -460,14 +482,21 @@ def file_delete(self, ls, path):
460482

461483
def file_create(self, ls, path):
462484
with Odoo.get().acquire_write(ls):
463-
new_parent = self.get_file_symbol(os.sep.join(path.split(os.sep)[:-1]))
464-
new_tree = new_parent.get_tree()
465-
new_tree[1].append(path.split(os.sep)[-1].replace(".py", ""))
466-
rebuilt_needed = self._search_symbols_to_rebuild(new_tree)
467-
if rebuilt_needed or new_parent.get_tree() == (["odoo", "addons"], []):
468-
#if there is something that is trying to import the new file, build it.
469-
#Else, don't add it to the architecture to not add useless symbols (and overrides)
470-
new_tree = self._build_new_symbol(ls, path, new_parent)
485+
parent, remains = self.get_loaded_part_tree(path)
486+
if not parent or not remains:
487+
return
488+
current_path = parent.get_paths()[0]
489+
new_tree = parent.get_tree()
490+
for new_el in remains:
491+
new_tree[0].append(new_el.replace(".py", ""))
492+
rebuilt_needed = self._search_symbols_to_rebuild(new_tree)
493+
if rebuilt_needed or parent.get_tree() == (["odoo", "addons"], []):
494+
#if there is something that is trying to import the new file, build it.
495+
#Else, don't add it to the architecture to not add useless symbols (and overrides)
496+
current_path = os.path.join(current_path, new_el)
497+
parent, new_tree = self._build_new_symbol(ls, current_path, parent)
498+
else:
499+
return
471500

472501
def add_to_rebuilds(self, symbols):
473502
"""add a dictionnary of symbols to the rebuild list. The dict must have the format
@@ -533,8 +562,8 @@ def _search_symbols_to_rebuild(self, tree):
533562
found_symbols = RegisteredRefSet()
534563
for s in self.not_found_symbols:
535564
for index in range(len(s.not_found_paths)):
536-
step, tree = s.not_found_paths[index]
537-
if flat_tree[:len(tree)] == tree[:len(flat_tree)]:
565+
step, not_found_tree = s.not_found_paths[index]
566+
if flat_tree[:len(not_found_tree)] == not_found_tree[:len(flat_tree)]:
538567
new_dict_to_revalidate[step].add(s)
539568
del s.not_found_paths[index]
540569
if not s.not_found_paths:

0 commit comments

Comments
 (0)