module documentation

_mediadb.py - ZMS Media Data Management

The mediadb module provides functionality for managing binary assets (files, images, blobs) in a ZMS instance. It handles storage, retrieval, and organization of uploaded files in a filesystem-based repository.

Key Features:

  • Store and retrieve binary files (blobs) from disk
  • Organize files in flat or hierarchical directory structures
  • Track file references across ZMS objects and recordsets
  • Migrate between different directory structures
  • Identify and manage orphaned files
  • Serve files as HTTP streaming responses
  • Validate file integrity and references

License: GNU General Public License v2 or later, Organization: ZMS Publishing

Class MediaDb Persistent Zope object that stores uploaded binary assets in a flat or hierarchical filesystem.
Function containerFilter Return True for containers whose meta_type is 'ZMS' (used by addable object filter).
Function getFilenamesFromValue Return a flat list of mediadb filenames referenced inside an attribute value.
Function manage_addMediaDb Initialize a new MediaDb instance at the specified filesystem location and recursively attach all existing blob attributes from the object tree.
Function manage_delMediaDb Detach the mediadb from this object and remove the acl_mediadb child. The method calls recurse_delMediaDb to restore all blob data back into the ZODB, then deletes the mediadb object itself. CAVE: Restoring the blob-files back into the ZODB can massively enlarge it's size.
Function manage_packMediaDb Scan the mediadb and move all orphaned files (not referenced by any ZMS object) to a temporary folder for cleanup or archival.
Function manage_structureMediaDb Reorganise mediadb files into the requested directory structure. The method moves all files into their new target location as computed by mediadb.targetFile(), which may involve creating intermediate directories for hierarchical structures...
Function recurse_addMediaDb Recursively attach all blob attributes of the object tree to the given mediadb.
Function recurse_delMediaDb Recursively detach blobs from the mediadb and restore their data back into ZODB. The method traverses the object tree and for each blob attribute found, it retrieves the file from the mediadb using the stored filename reference, restores the blob's data attribute with the file content, and removes the mediadb reference...
def containerFilter(container): (source)

Return True for containers whose meta_type is 'ZMS' (used by addable object filter).

def getFilenamesFromValue(v): (source)

Return a flat list of mediadb filenames referenced inside an attribute value.

def manage_addMediaDb(self, location, REQUEST=None, RESPONSE=None): (source)

Initialize a new MediaDb instance at the specified filesystem location and recursively attach all existing blob attributes from the object tree.

Parameters
self:objectZMS object to attach the mediadb to.
location:strFilesystem path where the mediadb should store its files.
REQUEST:HTTPRequestOptional HTTP request object (not used).
RESPONSE:HTTPResponseOptional HTTP response object for redirection after creation.
def manage_delMediaDb(self, REQUEST=None, RESPONSE=None): (source)

Detach the mediadb from this object and remove the acl_mediadb child. The method calls recurse_delMediaDb to restore all blob data back into the ZODB, then deletes the mediadb object itself. CAVE: Restoring the blob-files back into the ZODB can massively enlarge it's size.

def manage_packMediaDb(self, REQUEST=None, RESPONSE=None): (source)

Scan the mediadb and move all orphaned files (not referenced by any ZMS object) to a temporary folder for cleanup or archival.

The method traverses the entire mediadb directory structure and identifies files that are not referenced by any blob attribute in the ZMS object tree. It moves these orphaned files to a temporary folder for manual review and cleanup. The method returns a message summarizing the number of orphaned files found and their new location.

def manage_structureMediaDb(self, structure, REQUEST=None, RESPONSE=None): (source)

Reorganise mediadb files into the requested directory structure. The method moves all files into their new target location as computed by mediadb.targetFile(), which may involve creating intermediate directories for hierarchical structures. The method also updates the mediadb structure property to ensure future uploads are stored in the correct location.

Parameters
selfUndocumented
structure:intDesired directory nesting depth (0 = flat).
REQUESTUndocumented
RESPONSEUndocumented
Returns
strMessage summarizing the restructuring outcome.
def recurse_addMediaDb(self, mediadb): (source)

Recursively attach all blob attributes of the object tree to the given mediadb.

def recurse_delMediaDb(self, mediadb): (source)

Recursively detach blobs from the mediadb and restore their data back into ZODB. The method traverses the object tree and for each blob attribute found, it retrieves the file from the mediadb using the stored filename reference, restores the blob's data attribute with the file content, and removes the mediadb reference. The method also processes recordsets by iterating through their list attributes and applying the same logic to any blob values found within the records. Finally, the method recurses into child objects to ensure all blobs in the tree are processed. CAVE: Restoring the blob-files back into the ZODB can massively enlarge it's size.

Parameters
self:objectRoot object to start traversal from.
mediadb:MediaDbMediaDb instance to retrieve files from.