@@ -1947,3 +1947,82 @@ def test_input(i):
1947
1947
'unknown_keys_str' : unknown_keys_str }
1948
1948
1949
1949
return r
1950
+
1951
+ ##############################################################################
1952
+ def path2 (path ):
1953
+ """
1954
+ Add quotes if spaces in path
1955
+ """
1956
+ new_path = f'"{ path } "' if not path .startswith ('"' ) and ' ' in path else path
1957
+
1958
+ return new_path
1959
+
1960
+ ##############################################################################
1961
+ def update_dict_with_flat_key (key , value , d ):
1962
+ """
1963
+ Update dictionary via flat key (x.y.z)
1964
+ """
1965
+
1966
+ if '.' in key :
1967
+ keys = key .split ('.' )
1968
+
1969
+ new_d = d
1970
+
1971
+ first = True
1972
+
1973
+ for key in keys [:- 1 ]:
1974
+ if first :
1975
+ first = False
1976
+
1977
+ if key not in new_d :
1978
+ new_d [key ] = {}
1979
+
1980
+ new_d = new_d [key ]
1981
+
1982
+ new_d [keys [- 1 ]] = value
1983
+ else :
1984
+ d [key ] = value
1985
+
1986
+ return {'return' :0 }
1987
+
1988
+ ##############################################################################
1989
+ def get_value_from_dict_with_flat_key (key , d ):
1990
+ """
1991
+ Get value from dict via flat key (x.y.z)
1992
+ """
1993
+
1994
+ if '.' in key :
1995
+ keys = key .split ('.' )
1996
+ new_d = d
1997
+ for key in keys [:- 1 ]:
1998
+ if key in new_d :
1999
+ new_d = new_d [key ]
2000
+ value = new_d .get (keys [- 1 ])
2001
+ else :
2002
+ value = d .get (key )
2003
+
2004
+ return value
2005
+
2006
+ ##############################################################################
2007
+ def load_module (cmind , task_path , sub_module_name ):
2008
+ """
2009
+ Universal python module loaders
2010
+ """
2011
+
2012
+ import importlib
2013
+
2014
+ sub_module_obj = None
2015
+
2016
+ sub_module_path = os .path .join (task_path , sub_module_name )
2017
+ if os .path .isfile (sub_module_path ):
2018
+ sub_module_spec = importlib .util .spec_from_file_location (sub_module_name , sub_module_path )
2019
+ if sub_module_spec == None :
2020
+ return cmind .prepare_error (1 , f"Can\' t load Python module file spec { sub_module_path } " )
2021
+
2022
+ try :
2023
+ sub_module_obj = importlib .util .module_from_spec (sub_module_spec )
2024
+ sub_module_spec .loader .exec_module (sub_module_obj )
2025
+ except Exception as e : # pragma: no cover
2026
+ return cmind .prepare_error (1 , f"Can\' t load Python module code { sub_module_path } :\n \n { e } " )
2027
+
2028
+ return {'return' :0 , 'sub_module_obj' : sub_module_obj , 'sub_module_path' : sub_module_path }
0 commit comments