cmem_client.models.item¤
ImportItem base class and inherited classes
A marketplace package can be installed from a directory, a single file or a zip
archive. These classes hide that difference: create_import_item() picks the right
one for a path, and using it as a context manager yields a directory the import can
read from, extracting the archive first where that is needed and cleaning up after.
Classes:
- DirectoryImportItem – Import from a directory - no transformation needed.
- FileImportItem – Import from a single file, copy to temp directory.
- ImportItem – Abstract base class for different import source types.
- ZipImportItem – Import from a zip archive - extract to temp directory.
Functions:
- create_import_item – Factory function to create appropriate ImportItem instance.
DirectoryImportItem¤
Bases: ImportItem
Import from a directory - no transformation needed.
Functions:
- cleanup – No cleanup needed for directories.
- detect – Detect the appropriate ImportItem type for the given source.
- prepare – Return directory path as-is.
Attributes:
- import_type –
- model_config –
- source –
cleanup¤
No cleanup needed for directories.
detect¤
Detect the appropriate ImportItem type for the given source.
Parameters:
- source (
Path) – Path to analyze
Returns:
type[ImportItem]– The appropriate ImportItem subclass
import_type¤
model_config¤
prepare¤
Return directory path as-is.
source¤
FileImportItem¤
Bases: ImportItem
Import from a single file, copy to temp directory.
Functions:
- cleanup – Remove temporary directory.
- detect – Detect the appropriate ImportItem type for the given source.
- prepare – Copy file to a temporary directory.
Attributes:
- import_type –
- model_config –
- source –
cleanup¤
Remove temporary directory.
detect¤
Detect the appropriate ImportItem type for the given source.
Parameters:
- source (
Path) – Path to analyze
Returns:
type[ImportItem]– The appropriate ImportItem subclass
import_type¤
model_config¤
prepare¤
Copy file to a temporary directory.
source¤
ImportItem¤
Bases: ABC, Model
Abstract base class for different import source types.
Each concrete implementation represents a different source type (file, directory, zip, etc.) and knows how to prepare itself for import by providing a Path to a directory or file.
Attributes:
- import_type (
str) – Name of the source type this class handles, one ofdirectory,fileorzip. - source – Path the import reads from, as passed to the constructor.
Functions:
- cleanup – Clean up any temporary resources created during preparation.
- detect – Detect the appropriate ImportItem type for the given source.
- prepare – Prepare the import source and return a path to import from.
Parameters:
- source (
Path | str) – Source path or identifier for the import
cleanup¤
Clean up any temporary resources created during preparation.
detect¤
Detect the appropriate ImportItem type for the given source.
Parameters:
- source (
Path) – Path to analyze
Returns:
type[ImportItem]– The appropriate ImportItem subclass
import_type¤
model_config¤
prepare¤
Prepare the import source and return a path to import from.
This method transforms the source into a format suitable for import. For example:
- Zip files are extracted to a temp directory
- Directories are returned as-is
Returns:
Path– Path to directory or file ready for import
source¤
ZipImportItem¤
Bases: ImportItem
Import from a zip archive - extract to temp directory.
Functions:
- cleanup – Remove temporary directory.
- detect – Detect the appropriate ImportItem type for the given source.
- prepare – Extract zip to temporary directory.
Attributes:
- import_type –
- model_config –
- source –
cleanup¤
Remove temporary directory.
detect¤
Detect the appropriate ImportItem type for the given source.
Parameters:
- source (
Path) – Path to analyze
Returns:
type[ImportItem]– The appropriate ImportItem subclass
import_type¤
model_config¤
prepare¤
Extract zip to temporary directory.
source¤
create_import_item¤
Factory function to create appropriate ImportItem instance.
Parameters:
- source (
Path) – Path to the import source
Returns:
ImportItem– Appropriate ImportItem instance based on source type