mewlo.mpacks.core.asset.massetmanager module

massetmanager.py This module contains classes and functions to manage static file assets and aliases.

A MewloSite has a single MewloAssetManager, which it uses to help resolve any references with aliases. A MewloAssetManager allows aliases to be set, and ensures all references to files and urls are resolved with these aliases.

class mewlo.mpacks.core.asset.massetmanager.MewloAssetManager(mewlosite, debugmode)[source]

Bases: mewlo.mpacks.core.manager.manager.MewloManager

The derived signal dispatcher.

absolute_filepath(relpath)[source]

Shortcut to resolve a filepath given a relative path.

absolute_url(relpath)[source]

Shortcut to resolve a url given a relative path.

add_alias(aliasname, aliasval)[source]

Add an alias.

add_assetmount(assetmount)[source]

Add a staticfile_mount dictionary, with keys for ‘filepath’, ‘urlpath’.

add_assetsource(assetsource)[source]

Add a staticfile_mount dictionary, with keys for ‘filepath’, ‘urlpath’.

add_default_replacement_mirror_dirs()[source]

Add default mewlo replacement directory.

add_outside_replacement_mirror_dirs(orig_filedirpath, subdirid, flag_onlyifoutsidemain)[source]

Add mewlo replacement directory – IFF source is outside main mewlo path.

add_replacement_filepath(orig_filepath, new_filepath)[source]

Add a new mapping to replace a filepath.

add_replacement_mirrorfiledir(orig_filedirpath, new_filedirpath, flag_mkpath_root)[source]

Traverse two mirror didrectories and add cases where there exists replacement files in the new filedirpath.

calc_mountpoint_for_assetsource(assetsource)[source]

Calculate which mountpoint this source wants to be mounted at.

canonicalresolve(text)[source]

Resolve string that could include $ aliases, AND THEN canonicalize it.

description = 'The asset manager handles static files that are served to user'
dumps(indent=0)[source]

Debug information.

find_mountpoint_byid(mountid)[source]

Lookup mountpoint by id; return None if not found.

get_resolvedaliases()[source]

Return a dictionary of resolved aliases; might be useful for templates.

get_routegroup_mounting()[source]

We use a single routegroup under which we create our static routes for internal mount points.

is_filepath_under_another(filepath, potentialparent_filepath)[source]
isabsoluteurl(urlpath)[source]

Return True if urlpath is already an absolute path (starting with http).

mirrorcopytree_callback(filepath_source, filepath_dest)[source]

Return a tuple of the form <BoolShouldCopy, new_filepath_source, new_filepath_dest>.

mirrorfiles(filepath_source, filepath_destination, dry_run=0)[source]

We want to mirror some (asset) files between directories (recursive into subdirs). We may have to create the filepath_target deeply. Return failure on error or None.

mountsources()[source]

Mount our asset sources on our asset mounts.

relative_url(relpath)[source]

Shortcut to resolve a url that is relative to our server root.

replace_filepath(filepath)[source]

When one refers to an asseet file path (such as a view template file), it may be that our configuration settings tell us to use an alternative file. For example, a siteaddon may include some default template files (.jn2) files that exist in a subdirectory of the siteaddon module. These files may be referred to in code (or in other templates), using a string with an alias, for example: ‘${addon_account_path}/views/login.jn2’ This path would be expanded by the asset manager resolve() function, to something like ‘/testing/mewlo/mpacks/site_addons/account/view/login.jn2’ But now imagine that a user is creating a custom site and wants to use their own custom login.jn2 replacement template file. There are multiple ways this could be done, including subclassing the account siteaddon, but one simple way is to inform the asset manager that a replacement file exists for this file. This function simply looks up such replacements file paths.

resolve(text)[source]

Resolve a string that could include $ aliases. This is the central function that many places call.

resolve_filepath(text)[source]

Call resolve THEN call replace_filepath.

set_alias_settings(alias_settings)[source]

Assign the alias settings.

startup_prep(stageid, eventlist)[source]

This is invoked by site strtup, for each stage specified in startup_stages_needed() above.

typestr = 'core'
class mewlo.mpacks.core.asset.massetmanager.MewloAssetMount(id)[source]

Bases: object

Object representing a static asset mount point.

get_id()[source]
mount_source(assetsource, assetmanager)[source]

Mount an asset source on us.

class mewlo.mpacks.core.asset.massetmanager.MewloAssetMount_ExternalServer(id, filepath, urlabs, urlrel=None)[source]

Bases: mewlo.mpacks.core.asset.massetmanager.MewloAssetMount

Object representing a static asset mount point - handled by exposing a directory to an external web server.

dumps(indent=0)[source]

Debug information.

mount_source(assetsource, assetmanager)[source]

Mount an asset source on us. For an ExternalServer mount point, this means physically copying (mirroring) the contents of the source file directory to a target path, where some other web server will handle serving the files.

class mewlo.mpacks.core.asset.massetmanager.MewloAssetMount_InternalRoute(id, urlpath='assets')[source]

Bases: mewlo.mpacks.core.asset.massetmanager.MewloAssetMount

Object representing a static asset mount point - handled by internal route.

dumps(indent=0)[source]

Debug information.

mount_source(assetsource, assetmanager)[source]

Mount an asset source on us. For an InternalRoute mount point, this means wiring to a controller that will serve the static assets internally (via mewlo).

class mewlo.mpacks.core.asset.massetmanager.MewloAssetSource(id, mountid, filepath)[source]

Bases: object

Object representing a static asset source directory. remember that one should never refer to the assets by a hardcoded url or file path; always use the aliases created by these functions, which will take the form (where ID is the id of the asset source): ‘asset_ID_urlrel’ | ‘asset_ID_urlabs’ | ‘asset_ID_filepath’

dumps(indent=0)[source]

Debug information.

get_filepath()[source]
get_id()[source]
get_mountid()[source]
set_route(route)[source]