OpenQuizz
Une application de gestion des contenus pédagogiques
ResourceManager Class Reference

Public Member Functions

def __init__ (self)
 
def resource_exists (self, package_or_requirement, resource_name)
 
def resource_isdir (self, package_or_requirement, resource_name)
 
def resource_filename (self, package_or_requirement, resource_name)
 
def resource_stream (self, package_or_requirement, resource_name)
 
def resource_string (self, package_or_requirement, resource_name)
 
def resource_listdir (self, package_or_requirement, resource_name)
 
def extraction_error (self)
 
def get_cache_path (self, archive_name, names=())
 
def postprocess (self, tempname, filename)
 
def set_extraction_path (self, path)
 
def cleanup_resources (self, force=False)
 

Data Fields

 cached_files
 

Static Public Attributes

 extraction_path
 

Detailed Description

Manage resource extraction and packages

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self)

Member Function Documentation

◆ cleanup_resources()

def cleanup_resources (   self,
  force = False 
)
Delete all extracted resource files and directories, returning a list
of the file and directory names that could not be successfully removed.
This function does not have any concurrency protection, so it should
generally only be called when the extraction path is a temporary
directory exclusive to a single process.  This method is not
automatically called; you must call it explicitly or register it as an
``atexit`` function if you wish to ensure cleanup of a temporary
directory used for extractions.

◆ extraction_error()

def extraction_error (   self)
Give an error message for problems extracting file(s)

◆ get_cache_path()

def get_cache_path (   self,
  archive_name,
  names = () 
)
Return absolute location in cache for `archive_name` and `names`

The parent directory of the resulting path will be created if it does
not already exist.  `archive_name` should be the base filename of the
enclosing egg (which may not be the name of the enclosing zipfile!),
including its ".egg" extension.  `names`, if provided, should be a
sequence of path name parts "under" the egg's extraction location.

This method should only be called by resource providers that need to
obtain an extraction location, and only for names they intend to
extract, as it tracks the generated names for possible cleanup later.

◆ postprocess()

def postprocess (   self,
  tempname,
  filename 
)
Perform any platform-specific postprocessing of `tempname`

This is where Mac header rewrites should be done; other platforms don't
have anything special they should do.

Resource providers should call this method ONLY after successfully
extracting a compressed resource.  They must NOT call it on resources
that are already in the filesystem.

`tempname` is the current (temporary) name of the file, and `filename`
is the name it will be renamed to by the caller after this routine
returns.

◆ resource_exists()

def resource_exists (   self,
  package_or_requirement,
  resource_name 
)
Does the named resource exist?

◆ resource_filename()

def resource_filename (   self,
  package_or_requirement,
  resource_name 
)
Return a true filesystem path for specified resource

◆ resource_isdir()

def resource_isdir (   self,
  package_or_requirement,
  resource_name 
)
Is the named resource an existing directory?

◆ resource_listdir()

def resource_listdir (   self,
  package_or_requirement,
  resource_name 
)
List the contents of the named resource directory

◆ resource_stream()

def resource_stream (   self,
  package_or_requirement,
  resource_name 
)
Return a readable file-like object for specified resource

◆ resource_string()

def resource_string (   self,
  package_or_requirement,
  resource_name 
)
Return specified resource as a string

◆ set_extraction_path()

def set_extraction_path (   self,
  path 
)
Set the base path where resources will be extracted to, if needed.

If you do not call this routine before any extractions take place, the
path defaults to the return value of ``get_default_cache()``.  (Which
is based on the ``PYTHON_EGG_CACHE`` environment variable, with various
platform-specific fallbacks.  See that routine's documentation for more
details.)

Resources are extracted to subdirectories of this path based upon
information given by the ``IResourceProvider``.  You may set this to a
temporary directory, but then you must call ``cleanup_resources()`` to
delete the extracted files when done.  There is no guarantee that
``cleanup_resources()`` will be able to remove all extracted files.

(Note: you may not change the extraction path for a given resource
manager once resources have been extracted, unless you first call
``cleanup_resources()``.)

Field Documentation

◆ cached_files

cached_files

◆ extraction_path

extraction_path
static
Set the base path where resources will be extracted to, if needed.

If you do not call this routine before any extractions take place, the
path defaults to the return value of ``get_default_cache()``.  (Which
is based on the ``PYTHON_EGG_CACHE`` environment variable, with various
platform-specific fallbacks.  See that routine's documentation for more
details.)

Resources are extracted to subdirectories of this path based upon
information given by the ``IResourceProvider``.  You may set this to a
temporary directory, but then you must call ``cleanup_resources()`` to
delete the extracted files when done.  There is no guarantee that
``cleanup_resources()`` will be able to remove all extracted files.

(Note: you may not change the extraction path for a given resource
manager once resources have been extracted, unless you first call
``cleanup_resources()``.)

The documentation for this class was generated from the following file: