11import json
22import re
33import sys
4- from os import path
4+ from os import path , listdir
55from abc import ABC , abstractmethod
66import traceback as tb
77
@@ -26,12 +26,12 @@ def warn(msg: str, *context: Any):
2626
2727 service_msg : str
2828 if CURRENT_SERVICE is None :
29- service_msg = "outside any service "
29+ service_msg = ""
3030 else :
31- service_msg = f"in service \033 [36m{ CURRENT_SERVICE } \033 [0m"
31+ service_msg = f"in service \033 [36m{ CURRENT_SERVICE } \033 [0m "
3232
3333 print (
34- f"{ WARN } \033 [31m{ msg } \033 [0m { service_msg } ({ stack_str } )" ,
34+ f"{ WARN } \033 [31m{ msg } \033 [0m { service_msg } ({ stack_str } )" ,
3535 f"\n { WARN_TAB } " if len (context ) > 0 else "" ,
3636 * [f"\033 [2m{ c } \033 [0m" .replace ('\n ' , '\n \033 [0m' + WARN_TAB + " \033 [2m" ) for c in context ],
3737 file = sys .stderr ,
@@ -712,25 +712,57 @@ def extract_function_info(file_content: str) -> list[FunctionInfo]:
712712 warn ("Couldn't find $services" )
713713 else :
714714 services_functions = re .findall (r"'local_lbplanner_([a-z]+)_([a-z_]+)'" , services_function_block [1 ])
715- exit ()
716715
717716 function_infos_copy = function_infos .copy ()
718717 for function in services_functions :
719718 # Extracting function name and group
720719 func_name = function [1 ]
721720 func_group = function [0 ]
722721
722+ found = False
723723 for functioninfo in function_infos_copy :
724724 if functioninfo .name == func_name and functioninfo .group == func_group :
725725 function_infos_copy .remove (functioninfo )
726- continue # found the function
726+ found = True
727+ break
727728
728- warn (f"Couldn't find service function { func_group } _{ func_name } in $functions" )
729+ if not found :
730+ warn (f"Couldn't find service function { func_group } _{ func_name } in $functions" )
729731
730732 for functioninfo in function_infos_copy :
731733 # The ones left here are not in services_function.
732734 warn (f"Couldn't find service function { functioninfo .group } _{ functioninfo .name } in $services" )
733735
736+ # double-checking using existing files
737+ function_infos_copy = function_infos .copy ()
738+ searchdir = './lbplanner/services'
739+ for subdir in listdir (searchdir ):
740+ dirpath = path .join (searchdir , subdir )
741+ if not path .isdir (dirpath ):
742+ warn (f'found file { subdir } in services folder' )
743+ continue
744+
745+ for filename in listdir ('lbplanner/services/' + subdir ):
746+ if path .isdir (filename ):
747+ warn (f'found directory "{ filename } " in folder "{ dirpath } "' )
748+ continue
749+ if not filename .endswith ('.php' ):
750+ warn (f'found non-php file "{ filename } " in folder "{ dirpath } "' )
751+ continue
752+
753+ for functioninfo in function_infos_copy :
754+ if functioninfo .name == filename [:- 4 ] and functioninfo .group == subdir :
755+ function_infos_copy .remove (functioninfo )
756+ found = True
757+ break
758+
759+ if not found :
760+ warn (f"Couldn't find service function { func_group } _{ func_name } in $function" )
761+
762+ for functioninfo in function_infos_copy :
763+ # The ones left here are not in the dirs.
764+ warn (f"Couldn't find file { functioninfo .group } /{ functioninfo .name } .php in services folder" )
765+
734766 return function_infos
735767
736768
0 commit comments