allura.lib.helpers

class allura.lib.helpers.DateTimeConverter(*args, **kw)

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
allura.lib.helpers.absurl(url)

Given a root-relative URL, return a full URL including protocol and host

allura.lib.helpers.ago(start_time, show_date_after=7)

Return time since starting time as a rounded, human readable string. E.g., “3 hours ago”

allura.lib.helpers.auditlog_user(message, *args, **kwargs)

Create an audit log entry for a user, including the IP address

Parameters:
allura.lib.helpers.config_with_prefix(d, prefix)

Return a subdictionary keys with a given prefix, with the prefix stripped

allura.lib.helpers.convert_bools(conf, prefix='')

For a given dict, automatically convert any true/false string values into bools. Only applies to keys starting with the prefix.

Parameters:
Returns:

dict

allura.lib.helpers.do_filesizeformat(value, binary=False)

Format the value like a ‘human-readable’ file size (i.e. 13 kB, 4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega, Giga, etc.), if the second parameter is set to True the binary prefixes are used (Mebi, Gibi).

allura.lib.helpers.encode_keys(d)

Encodes the unicode keys of d, making the result a valid kwargs argument

class allura.lib.helpers.exceptionless(error_result, log=None)

Decorator making the decorated function return ‘error_result’ on any exceptions rather than propagating exceptions up the stack

class allura.lib.helpers.fixed_attrs_proxy(obj, **kw)

On attribute lookup, if keyword parameter matching attribute name was provided during object construction, returns it’s value. Otherwise proxies to obj.

allura.lib.helpers.get_filter(ctx, filter_name)

Gets a named Jinja2 filter, passing through any context requested by the filter.

allura.lib.helpers.get_first(d, key)

Return value for d[key][0] if d[key] is a list with elements, else return d[key].

Useful to retrieve values from solr index (e.g. title and text fields), which are stored as lists.

allura.lib.helpers.get_tool_packages(tool_name)

Return package for given tool (e.g. ‘forgetracker’ for ‘tickets’)

allura.lib.helpers.get_user_status(user)

Get user status based on disabled and pending attrs

Parameters:user – a allura.model.auth.User
allura.lib.helpers.iter_entry_points(group, *a, **kw)

Yields entry points that have not been disabled in the config.

If group is “allura” (Allura tool entry points) or one of subgroups (e.g. “allura.phone”), this function also checks for multiple entry points with the same name. If there are multiple entry points with the same name, and one of them is a subclass of the other(s), it will be yielded, and the other entry points with that name will be ignored. If a subclass is not found, an ImportError will be raised.

This treatment of “allura” and “allura.*” entry points allows tool authors to subclass another tool while reusing the original entry point name.

allura.lib.helpers.log_if_changed(artifact, attr, new_val, message)

Set artifact.attr to new_val if changed. Add AuditLog record.

allura.lib.helpers.login_overlay(*args, **kwds)

Override the default behavior of redirecting to the auth.login_url and instead display an overlay with content from auth.login_fragment_url.

This is to allow pages that require authentication for any actions but not for the initial view to be more apparent what you will get once logged in.

This should be wrapped around call to require_access() (presumably in the _check_security() method on a controller). The exceptions param can be given a list of exposed views to leave with the original behavior.

For example:

class MyController(BaseController);
    def _check_security(self):
        with login_overlay(exceptions=['process']):
            require_access(self.neighborhood, 'register')

    @expose
    def index(self, *args, **kw):
        return {}

    @expose
    def list(self, *args, **kw):
        return {}

    @expose
    def process(self, *args, **kw):
        return {}

This would show the overlay to unauthenticated users who visit / or /list but would perform the normal redirect when /process is visited.

allura.lib.helpers.make_safe_path_portion(ustr, relaxed=True)

Return an ascii representation of ustr that conforms to mount point naming rules.

Will return an empty string if no char in ustr is latin1-encodable.

Parameters:relaxed – Use relaxed mount point naming rules (allows more characters. See re_relaxed_tool_mount_point_fragment.
Returns:The converted string.
allura.lib.helpers.ming_config(*args, **kwds)

Temporarily swap in a new ming configuration, restoring the previous one when the contextmanager exits.

Parameters:**conf – keyword arguments defining the new ming configuration
allura.lib.helpers.ming_config_from_ini(*args, **kwds)

Temporarily swap in a new ming configuration, restoring the previous one when the contextmanager exits.

Parameters:ini_path – Path to ini file containing the ming configuration
allura.lib.helpers.notifications_disabled(*args, **kwds)

Temporarily disable email notifications on a project.

allura.lib.helpers.null_contextmanager(*args, **kwds)

A no-op contextmanager.

allura.lib.helpers.paging_sanitizer(limit, page, total_count=9223372036854775807, zero_based_pages=True)

Return limit, page - both converted to int and constrained to valid ranges based on total_count.

Useful for sanitizing limit and page query params.

allura.lib.helpers.rate_limit(cfg_opt, artifact_count, start_date, exception=None)

Check the various config-defined artifact creation rate limits, and if any are exceeded, raise exception.

Parameters:artifact_count – a number or callable (for lazy evaluation)
allura.lib.helpers.render_any_markup(name, txt, code_mode=False, linenumbers_style='table')

renders markdown using allura enhacements if file is in markdown format renders any other markup format using the pypeline Returns jinja-safe text

allura.lib.helpers.topological_sort(items, partial_order)

Perform topological sort. items is a list of items to be sorted. partial_order is a list of pairs. If pair (a,b) is in it, it means that item a should appear before item b. Returns a list of the items in one of the possible orders, or None if partial_order contains a loop.

Modified from: http://www.bitformation.com/art/python_toposort.html

allura.lib.helpers.unidiff(old, new)

Returns unified diff between one and two.

allura.lib.helpers.urlopen(url, retries=3, codes=(408, 500, 502, 503, 504), timeout=None)

Open url, optionally retrying if an error is encountered.

Socket and other IO errors will always be retried if retries > 0. HTTP errors are retried if the error code is passed in codes.

Parameters:
  • retries – Number of time to retry.
  • codes – HTTP error codes that should be retried.