@@ -384,11 +384,11 @@ def register_schema(self, schema_registration: SchemaRegistration):
384384
385385 page .set_slot_content ("jsonschema" , schema )
386386 else :
387- print ("Error: Unsupported entity type" )
387+ _logger . error ("Error: Unsupported entity type" )
388388 return
389389
390390 page .edit ()
391- print ("Entity stored at " + page .get_url ())
391+ _logger . info ("Entity stored at " + page .get_url ())
392392
393393 class SchemaUnregistration (BaseModel ):
394394 """dataclass param of register_schema()"""
@@ -421,7 +421,7 @@ def unregister_schema(self, schema_unregistration: SchemaUnregistration):
421421 ):
422422 uuid = schema_unregistration .model_cls .__uuid__
423423 else :
424- print ("Error: Neither model nor model id provided" )
424+ _logger . error ("Error: Neither model nor model id provided" )
425425
426426 entity_title = "Category:" + OSW .get_osw_id (uuid )
427427 page = self .site .get_page (WtSite .GetPageParam (titles = [entity_title ])).pages [0 ]
@@ -607,15 +607,15 @@ def _fetch_schema(
607607 fetchSchemaParam .offline_pages is not None
608608 and schema_title in fetchSchemaParam .offline_pages
609609 ):
610- print (f"Fetch { schema_title } from offline pages" )
610+ _logger . info (f"Fetch { schema_title } from offline pages" )
611611 page = fetchSchemaParam .offline_pages [schema_title ]
612612 else :
613- print (f"Fetch { schema_title } from online pages" )
613+ _logger . info (f"Fetch { schema_title } from online pages" )
614614 page = self .site .get_page (WtSite .GetPageParam (titles = [schema_title ])).pages [
615615 0
616616 ]
617617 if not page .exists :
618- print (f"Error: Page { schema_title } does not exist" )
618+ _logger . error (f"Error: Page { schema_title } does not exist" )
619619 # the $ref that led here was already rewritten to this file name
620620 write_schema_stub (get_model_dir_path (), schema_name )
621621 return OSW .FetchSchemaResult (
@@ -637,7 +637,7 @@ def _fetch_schema(
637637 )
638638 schema_str = json .dumps (schema )
639639 if (schema_str is None ) or (schema_str == "" ):
640- print (f"Warning: Schema slot of { schema_title } is empty" )
640+ _logger . warning (f"Warning: Schema slot of { schema_title } is empty" )
641641 schema_str = "{}" # empty schema to make reference work
642642 if fetchSchemaParam .warning_messages is None :
643643 fetchSchemaParam .warning_messages = []
@@ -1027,7 +1027,7 @@ def _fetch_schema(
10271027 # may overlap partially, e.g.
10281028 # from datetime import date
10291029 # from datetime import date, datetime
1030- print ( "Replace import statement:" , import_stmt )
1030+ _logger . info ( f "Replace import statement: { import_stmt } " )
10311031 content = re .sub (
10321032 r"^" + re .escape (import_stmt ) + r"$" ,
10331033 "" ,
@@ -1216,7 +1216,7 @@ def load_entity(
12161216 param = entity_title
12171217
12181218 if param .model_to_use :
1219- print (f"Using schema { param .model_to_use .__name__ } to create entity" )
1219+ _logger . info (f"Using schema { param .model_to_use .__name__ } to create entity" )
12201220
12211221 # store original cache state
12221222 cache_state = self .site .get_cache_enabled ()
@@ -1266,7 +1266,7 @@ def load_entity(
12661266 )
12671267 if not hasattr (model , cls_name ):
12681268 schemas_fetched = False
1269- print (
1269+ _logger . error (
12701270 f"Error: Model { cls_name } not found. Schema { category } "
12711271 f"needs to be fetched first."
12721272 )
@@ -1408,7 +1408,7 @@ def validate_entity(cls, entity, values):
14081408 try :
14091409 uuid_from_title = get_uuid (title )
14101410 except ValueError :
1411- print (
1411+ _logger . error (
14121412 f"Error: UUID could not be determined from title: '{ title } ', "
14131413 f"nor fromjsondata: { jsondata } "
14141414 )
@@ -1450,7 +1450,7 @@ def _apply_overwrite_policy(param: OSW._ApplyOverwriteParam) -> WtPage:
14501450
14511451 def set_content (content_to_set : dict ) -> None :
14521452 if param .debug :
1453- print (f"content_to_set: { content_to_set !s} " )
1453+ _logger . debug (f"content_to_set: { content_to_set !s} " )
14541454 for slot_ in content_to_set .keys ():
14551455 page .set_slot_content (slot_ , content_to_set [slot_ ])
14561456
@@ -1481,7 +1481,7 @@ def set_content(content_to_set: dict) -> None:
14811481 page .exists
14821482 and param .policy .overwrite == AddOverwriteClassOptions .keep_existing
14831483 ):
1484- print (
1484+ _logger . warning (
14851485 f"Entity '{ entity_title } ' already exists and won't be stored "
14861486 f"with overwrite set to 'keep existing'!"
14871487 )
@@ -1509,15 +1509,15 @@ def set_content(content_to_set: dict) -> None:
15091509 if remote_content ["footer" ]:
15101510 new_content ["footer" ] = remote_content ["footer" ]
15111511 if param .debug :
1512- print (f"'remote_content': { remote_content !s} " )
1512+ _logger . debug (f"'remote_content': { remote_content !s} " )
15131513 # Get the local content
15141514 # Properties that are not set in the local content will be set to None
15151515 # We want those not to be listed as keys
15161516 local_content ["jsondata" ] = json .loads (param .entity .json (exclude_none = True ))
15171517 if param .remove_empty :
15181518 remove_empty (local_content ["jsondata" ])
15191519 if param .debug :
1520- print (f"'local_content': { local_content !s} " )
1520+ _logger . debug (f"'local_content': { local_content !s} " )
15211521 # Apply the overwrite logic
15221522 # a) If there is a key in the remote content that is not in the local
15231523 # content, we have to keep it
@@ -1530,7 +1530,7 @@ def set_content(content_to_set: dict) -> None:
15301530 # if key not in local_content["jsondata"].keys()
15311531 # }
15321532 if param .debug :
1533- print (f"'New content' after 'remote' update: { new_content !s} " )
1533+ _logger . debug (f"'New content' after 'remote' update: { new_content !s} " )
15341534 # b) If there is a key in the local content that is not in the remote
15351535 # content, we have to keep it
15361536 new_content ["jsondata" ].update ({
@@ -1539,7 +1539,7 @@ def set_content(content_to_set: dict) -> None:
15391539 if key not in remote_content ["jsondata" ].keys ()
15401540 })
15411541 if param .debug :
1542- print (f"'New content' after 'local' update: { new_content !s} " )
1542+ _logger . debug (f"'New content' after 'local' update: { new_content !s} " )
15431543 # c) If there is a key in both contents, we have to apply the overwrite
15441544 # logic
15451545 # todo: include logic for hidden and read_only properties!
@@ -1549,14 +1549,14 @@ def set_content(content_to_set: dict) -> None:
15491549 if param .policy .get_overwrite_setting (key ) == OverwriteOptions .true
15501550 })
15511551 if param .debug :
1552- print (f"'New content' after 'True' update: { new_content !s} " )
1552+ _logger . debug (f"'New content' after 'True' update: { new_content !s} " )
15531553 new_content ["jsondata" ].update ({
15541554 key : value
15551555 for (key , value ) in remote_content ["jsondata" ].items ()
15561556 if param .policy .get_overwrite_setting (key ) == OverwriteOptions .false
15571557 })
15581558 if param .debug :
1559- print (f"'New content' after 'False' update: { new_content !s} " )
1559+ _logger . debug (f"'New content' after 'False' update: { new_content !s} " )
15601560 new_content ["jsondata" ].update ({
15611561 key : value
15621562 for (key , value ) in local_content ["jsondata" ].items ()
@@ -1566,8 +1566,8 @@ def set_content(content_to_set: dict) -> None:
15661566 )
15671567 })
15681568 if param .debug :
1569- print (f"'New content' after 'only empty' update: { new_content !s} " )
1570- print (f"'New content' to be stored: { new_content !s} " )
1569+ _logger . debug (f"'New content' after 'only empty' update: { new_content !s} " )
1570+ _logger . debug (f"'New content' to be stored: { new_content !s} " )
15711571 set_content (new_content )
15721572 return page # Guard clause --> exit function
15731573
@@ -1792,7 +1792,9 @@ def store_entity_(
17921792 )
17931793 generated_schemas [key ] = json .loads (schema_str )
17941794 except Exception as e :
1795- print (f"Schema generation from template failed for { entity_ } : { e } " )
1795+ _logger .error (
1796+ f"Schema generation from template failed for { entity_ } : { e } "
1797+ )
17961798
17971799 mode = AggregateGeneratedSchemasParamMode .ROOT_LEVEL
17981800 # Put generated schema in definitions section,
@@ -1816,16 +1818,16 @@ def store_entity_(
18161818 ) # will set page.changed if the content of the page has changed
18171819 if not param .offline and page .changed :
18181820 if index is None :
1819- print (f"Entity stored at '{ page .get_url ()} '." )
1821+ _logger . info (f"Entity stored at '{ page .get_url ()} '." )
18201822 else :
1821- print (
1823+ _logger . info (
18221824 f"({ index + 1 } /{ max_index } ) Entity stored at "
18231825 f"'{ page .get_url ()} '."
18241826 )
18251827 created_pages [page .title ] = page
18261828
18271829 sorted_entities = OSW .sort_list_of_entities_by_class (param .entities )
1828- print (
1830+ _logger . info (
18291831 "Entities to be uploaded have been sorted according to their type.\n "
18301832 "If you would like to overwrite existing entities or properties, "
18311833 "pass a StoreEntityParam to store_entity() with "
@@ -1853,7 +1855,7 @@ class UploadObject(BaseModel):
18531855 overwrite = param .overwrite ,
18541856 )
18551857 if param .debug :
1856- print (
1858+ _logger . debug (
18571859 f"Now adding entities of class type '{ class_type } ' "
18581860 f"({ entity_model .__name__ } ) to upload list. No class specific"
18591861 f" overwrite setting found. Using fallback option '"
@@ -1978,7 +1980,7 @@ def delete_entity_(entity_, comment_: str = None):
19781980 if title_ is None :
19791981 title_ = OSW .get_osw_id (entity_ .uuid )
19801982 if namespace_ is None or title_ is None :
1981- print ("Error: Unsupported entity type" )
1983+ _logger . error ("Error: Unsupported entity type" )
19821984 return
19831985 entity_title = namespace_ + ":" + title_
19841986 page = self .site .get_page (WtSite .GetPageParam (titles = [entity_title ])).pages [
@@ -1987,9 +1989,9 @@ def delete_entity_(entity_, comment_: str = None):
19871989
19881990 if page .exists :
19891991 page .delete (comment_ )
1990- print ("Entity deleted: " + page .get_url ())
1992+ _logger . info ("Entity deleted: " + page .get_url ())
19911993 else :
1992- print (f"Entity '{ entity_title } ' does not exist!" )
1994+ _logger . warning (f"Entity '{ entity_title } ' does not exist!" )
19931995
19941996 if entity .parallel :
19951997 _ = parallelize (
0 commit comments