The ``writer.py`` module ======================== .. py:module:: src.pyconverter.xml2py.writer Summary ------- .. py:currentmodule:: writer .. tab-set:: .. tab-item:: Functions .. list-table:: :header-rows: 0 :widths: auto * - :py:obj:`~convert` - Convert an XML directory into an RST dictionary. * - :py:obj:`~copy_template_package` - Add files and directory from a template directory path to a new path. * - :py:obj:`~write_global__init__file` - Write the ``__init__.py`` file for the package generated. * - :py:obj:`~write__init__file` - " * - :py:obj:`~get_library_path` - Get the desired library path with the following format: * - :py:obj:`~get_module_info` - Get the module name, class name, and module path from command * - :py:obj:`~get_class_info` - Get the class name, file name, and file path from the initial class name. * - :py:obj:`~write_source` - Write out XML commands as Python source files. * - :py:obj:`~write_docs` - Output to the autogenerated ``package`` directory. .. tab-item:: Constants .. list-table:: :header-rows: 0 :widths: auto * - :py:obj:`~CONST` - * - :py:obj:`~SKIP_XML` - Module detail ------------- .. py:function:: convert(directory_path) Convert an XML directory into an RST dictionary. :Parameters: **directory_path: Path** Path to the directory containing the XML files to convert. :Returns: :class:`python:dict` Dictionary with the following format: ``{"command_name": command_object}``. :class:`python:dict` Dictionary with the following format: ``{"initial_command_name": "python_name"}``. .. !! processed by numpydoc !! .. py:function:: copy_template_package(template_path: pathlib.Path, new_package_path: pathlib.Path, clean: bool = False) -> pathlib.Path Add files and directory from a template directory path to a new path. :Parameters: **template_path: Path** Path object containing the directory to copy. **new_package_path: Path** Path object containing the directory where the new files and directorys are to be added. **clean: bool, optional** Whether the directories in the path for the new package must be cleared before adding new files. The default value is ``False``. :Returns: :obj:`Path` Path object containing the source files of the created ``xml-commands`` package. .. !! processed by numpydoc !! .. py:function:: write_global__init__file(library_path: pathlib.Path) -> None Write the ``__init__.py`` file for the package generated. :Parameters: **library_path: Path** Path object of the directory containing the generated package. .. !! processed by numpydoc !! .. py:function:: write__init__file(library_path: pathlib.Path) -> None " Write the ``__init__.py`` file within each module directory. :Parameters: **library_path: Path** Path object of the directory containing the generated package. .. !! processed by numpydoc !! .. py:function:: get_library_path(new_package_path: pathlib.Path, config_path: pathlib.Path) -> pathlib.Path Get the desired library path with the following format: ``new_package_path/library_structure``. For instance, if ``library_name_structured`` in the ``config.yaml`` file is ``["pyconverter", "generatedcommands"]``, the function returns ``new_package_path/pyconverter/generatedcommands``. :Parameters: **new_package_path: Path** Path objecy of the new package directory. **config_path: str** Path to the configuration file. :Returns: :obj:`Path` Path object of the new library structure. .. !! processed by numpydoc !! .. py:function:: get_module_info(library_path: pathlib.Path, command: pyconverter.xml2py.ast_tree.XMLCommand) -> Tuple[str, str, pathlib.Path] Get the module name, class name, and module path from command information. :Parameters: **library_path: Path** Path object to the library directory. **command: ast.XMLCommand** Command object. :Returns: :class:`python:str` Module where the command is stored. :class:`python:str` Class where the command is stored. :obj:`Path` Path object of the module directory .. !! processed by numpydoc !! .. py:function:: get_class_info(initial_class_name: str, module_path: pathlib.Path) -> Tuple[str, str, pathlib.Path] Get the class name, file name, and file path from the initial class name. :Parameters: **initial_class_name: str** Initial class name. **module_path: Path** Path object of the module directory. :Returns: :class:`python:str` Class name. :class:`python:str` File name. :obj:`Path` File path. .. !! processed by numpydoc !! .. py:function:: write_source(command_map: dict, name_map: dict, xml_doc_path: pathlib.Path, target_path: pathlib.Path, path_custom_functions: Union[pathlib.Path, None] = None, template_path: Union[pathlib.Path, None] = None, config_path: pathlib.Path = Path('config.yaml'), clean: bool = True, structured: bool = True, check_structure_map: bool = False, check_files: bool = True) -> Tuple[list, dict] Write out XML commands as Python source files. :Parameters: **command_map: dict** Dictionary with the following format: ``{"initial_command_name": command_obj}``. **name_map: dict** Dictionary with the following format: ``{"initial_command_name": "python_name"}``. **xml_doc_path: Path** Path object containing the XML directory to convert. **target_path: Path** Path object to generate the new package to. **path_custom_functions: Path, optional** Path object containing the customized functions. The default value is ``None``. **template_path: Path, optional** Path object of the template to use. If no path is provided, the default template is used. **config_path: Path, optional** Path object of the configuration file. The default value is ``Path(config.yaml)``.`. **clean: bool, optional** Whether the directories in the new package path must be cleared before adding new files. The default value is ``True``. **structured: bool, optional** Whether the package should be structured. The default value is ``True``. **check_structure_map: bool, optional** Whether the structure map must be checked. The default value is ``False``. **check_files: bool, optional** Whether the files must be checked. The default value is ``False``. :Returns: :class:`python:list` List of module names created. :class:`python:dict` Dictionary with the following format: ``{'python_module_name': [{'python_class_name': python_names_list}]}``. .. !! processed by numpydoc !! .. py:function:: write_docs(package_path: pathlib.Path, package_structure: dict = None, config_path: pathlib.Path = Path('config.yaml')) -> pathlib.Path Output to the autogenerated ``package`` directory. :Parameters: **package_path: Path** Path object of the new package folder. **package_structure: dict, optional** Dictionary with the following format: ``{'python_module_name': [{'python_class_name': python_names_list}]}``. **config_path: Path, optional** Path object of the configuration file. The default value is ``Path(config.yaml)``. :Returns: :obj:`Path` Path to the new document page. .. !! processed by numpydoc !! .. py:data:: CONST .. py:data:: SKIP_XML