The writer.py module#

Summary#

convert

Convert an XML directory into an RST dictionary.

copy_template_package

Add files and directory from a template directory path to a new path.

write_global__init__file

Write the __init__.py file for the package generated.

write__init__file

get_library_path

Get the desired library path with the following format:

get_module_info

Get the module name, class name, and module path from command

get_class_info

Get the class name, file name, and file path from the initial class name.

write_source

Write out XML commands as Python source files.

write_docs

Output to the autogenerated package directory.

Module detail#

writer.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:
dict

Dictionary with the following format: {"command_name": command_object}.

dict

Dictionary with the following format: {"initial_command_name": "python_name"}.

writer.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:
Path

Path object containing the source files of the created xml-commands package.

writer.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.

writer.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.

writer.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:
Path

Path object of the new library structure.

writer.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:
str

Module where the command is stored.

str

Class where the command is stored.

Path

Path object of the module directory

writer.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:
str

Class name.

str

File name.

Path

File path.

writer.write_source(command_map: dict, name_map: dict, xml_doc_path: pathlib.Path, target_path: pathlib.Path, path_custom_functions: pathlib.Path | None = None, template_path: 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:
list

List of module names created.

dict

Dictionary with the following format: {'python_module_name': [{'python_class_name': python_names_list}]}.

writer.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:
Path

Path to the new document page.

writer.CONST#
writer.SKIP_XML#