@@ -372,6 +372,17 @@ class CreationConfig(OswBaseModel):
372372 offline_pages : Optional [Dict [str , WtPage ]] = None
373373 """A dictionary of pages that are already loaded. Pages in this dictionary
374374 will not be fetched again."""
375+ prefer_local_pages : bool = False
376+ """Load the pages from the local working directory
377+ instead of the server if set to True."""
378+ generate_python_code : bool = False
379+ """Whether to generate python code for the data models."""
380+ python_code_working_dir : Optional [Union [str , Path ]] = None
381+ """Working directory for python code generation. If set, pydantic v2 data models
382+ will be generated in this directory, v1 models in a /v1 subdirectory.
383+ """
384+ python_code_filename : Optional [str ] = "_model_generated.py"
385+ """Filename for the generated python code."""
375386
376387 class Config :
377388 arbitrary_types_allowed = True
@@ -418,6 +429,57 @@ def create(
418429 )
419430 },
420431 )
432+
433+ offline_pages = creation_config .offline_pages
434+ local_pages = {}
435+ if creation_config .prefer_local_pages :
436+ # Read the local pages from the package
437+ result = wtsite .read_page_package (
438+ WtSite .ReadPagePackageParam (
439+ package_name = self .name ,
440+ storage_path = Path (creation_config .working_dir ),
441+ )
442+ )
443+ local_pages = {p .title : p for p in result .pages }
444+ if offline_pages is None :
445+ offline_pages = local_pages
446+ else :
447+ # Merge the local pages with the offline pages
448+ offline_pages .update (local_pages )
449+
450+ if (
451+ creation_config .generate_python_code
452+ and creation_config .python_code_working_dir is not None
453+ ):
454+ python_code_path = Path (creation_config .python_code_working_dir )
455+ python_code_path /= creation_config .python_code_filename
456+ schema_titles = self .page_titles
457+ # remove duplicates and entries in ignore_titles
458+ schema_titles = list (
459+ set (schema_titles )
460+ - (
461+ set (creation_config .ignore_titles )
462+ if creation_config .ignore_titles
463+ else set ()
464+ )
465+ )
466+ # remove all schemas that do not start with "Category:"
467+ schema_titles = [
468+ title for title in schema_titles if title .startswith ("Category:" )
469+ ]
470+ from osw .core import OSW
471+
472+ osw_obj = OSW (site = wtsite )
473+
474+ osw_obj .fetch_schema (
475+ fetchSchemaParam = OSW .FetchSchemaParam (
476+ schema_title = schema_titles ,
477+ offline_pages = offline_pages ,
478+ result_model_path = python_code_path ,
479+ mode = "replace" ,
480+ )
481+ )
482+
421483 # Create a PagePackageConfig instance
422484 config = package .PagePackageConfig (
423485 name = self .name ,
@@ -432,7 +494,7 @@ def create(
432494 wtsite .create_page_package (
433495 WtSite .CreatePagePackageParam (
434496 config = config ,
435- offline_pages = creation_config . offline_pages ,
497+ offline_pages = offline_pages ,
436498 )
437499 )
438500
0 commit comments