utils — PyCI Utility Module

class Flot(data, options={})

A class to store and return data to be plotted by flot. @data: A list representing list pairs of x and y data points.

Example: [[0, 3], [10, 3]] That is: [[x, y], [x, y]]... and so on
@options: A dictionary of options to be passed to flot.

Valid options are: {

color: color or number label: string lines: specific lines options bars: specific bars options points: specific points options xaxis: 1 or 2 yaxis: 1 or 2 clickable: boolean hoverable: boolean shadowSize: number

}

to_json()
Returns our variables in a json-encoded format that flot likes
class LazyProperty(func)
Decorator to make class methods return attributes only when accessed
connect_tarball_routes(dispatcher, controller, tarball, action=None, plugin_name=None)
Sets up routes for a given tarball using the given dispatcher and assign it ‘action’ (i.e. the path on the webserver)
current_user()
Returns the name of the current logged in user
decode_object(string)
Un-pickles and then Base64-decodes an object
detect_mime_type(filepath)
Attempts to detect the mime type of the given file and sets the appropriate cherrypy response header
encode_object(obj)
Pickles and then Base64-encodes an object so it can be embedded in forms
format_columns(string_list, columns, separator=' ')

A generator to produce equal-width columns from string_list

Thanks to ΤΖΩΤΖΙΟΥ (http://stackoverflow.com/users/6899/)

get_display_name(plugin)
Returns the display_name value of the given plugin. If none is set, return split_uppercase(plugin.__name__).
get_groups(user=None)
Returns a list of groups the given user is a member of. If no user is provided, return a list of all groups.
get_static_file(filepath)
Serves up static content from a direct filepath.
get_tarball_file(tarball, filepath)
Returns files from within a gzip-compressed tar file (e.g. static.tgz). Only intended for returning static content such as images and text files. Note: Will not work with Mako templates.
jeditable_dict(_list, default=None)
Converts a given list into a format jeditable likes
jqgrid_format(header, list_data, id_field_index=None)
Convert a list of lists into a format that jqGrid will like when it is rendered via JSON. If an ‘id_field_index’ is specified, that field will be used as the ‘id’ JSON parameter.
jqgrid_json(self, cell_list, header, id_field_index=None, rows=None, sidx=None, _search=False, searchField=None, searchOper=None, searchString=None, page=None, sord=None)

Returns a list of cells encoded in a format jqgrid likes.

Required variables: @header: The column names (must match cell_list). Example:

header = [‘primary_key’, ‘firstname’, ‘lastname’]
@cell_list: A list containing lists of cells. Example:
cell_list = [
[‘1’, ‘John’, ‘Smith’], [‘2’, ‘Bob’, ‘Jones’]

]

Optional variables: @id_field_index: The index of the field to use as jqGrid’s ‘id’ parameter. @rows: Number of rows to return. If this is not set all rows will be returned. @sidx: Field to sort the output by. @sord: Either ‘asc’ (ascending) or ‘desc’ (descending). @_search: True or False (whether or not this is a search). Default is False. Also takes strings of ‘true’ and ‘false’. @searchField: The field we’re searching on. @searchOper: The type of search (eq = equals, cn = contains, etc–see the docstring of search_cells for all the operators). @searchString: The string to match for our search. @page: The page number to return (if paginating).

jqgrid_select_options(_list)

Turns a list of items into a format compatible with jqGrid selection lists.

Here’s an example of how jqgrid expects selection options:
{value:”FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX”}
This function just takes the items in the given list and doubles them up like so:
‘item1:item1;item2:item2;’
jquery_ui_error_msg(message)
Returns ‘message’ surrounded by jquery-ui divs indicating an error (makes it look nice)
jquery_ui_highlight_msg(message)
Returns ‘message’ surrounded by jquery-ui divs indicating an informational message (makes it look nice)
lookup_template(basedir, _template)
Returns a mako Template from the html directory
normalizeString(string)
Removes/fixes leading/trailing newlines/whitespace and escapes double quotes with double quotes (to comply with CSV format)
plugin_template(plugin, template_path)

Returns a mako template object given the path to the template inside a plugin’s directory or zip archive. Note: If the path doesn’t exist on the filesystem this method will attempt to get the file out of the plugin’s zip archive.

Example:
mytemplate = plugin_template(‘admin’, templates/users_and_groups.mako)
search_cells(header, _list, search_string, search_field, search_type)

Given a tuple of lists (cells) and a header (matching the cells), returns a list of items that match the given search_string, search_field, and search_type.

Valid search types: eq - Equal to ne - Not equal to bw - Begins with ew - Ends with lt - Less than le - Less than or equal to gt - Greater than ge - Greater than or equal to cn - Contains

serve_static(static, filepath)
Serves up static content either from within a tarball or a local directory depending on the detected file type of ‘static’
service_control(service, operation)
This function just runs /etc/init.d/<service> <operation> Returns True if the operation was successful Returns the command output on failure
sortby_field(sort_field, fields, _list)
Sorts a list of lists or tuples (‘_list’) by ‘sort_field’ given a list of ‘fields’ that maps to the sublists’ indexes (if that makes sense?)
split_seq(seq, size)
Split up seq in pieces of size
split_uppercase(string)
Splits TitleCasedString into ‘Title Cased String’
strip_pound(string)
Removes leading # signs from basic anchor links (for use in navigation)
timeout(func, args=(), kwargs={}, timeout_duration=10, default=None)

This function will spawn a thread and run the given function using the args, kwargs and return the given default value if the timeout_duration is exceeded.

Invoking it with a 5 second timeout:
result = timeout(remote_calculate, (myarg,), timeout_duration=5)

(taken from http://stackoverflow.com/questions/492519/timeout-on-a-python-function-call)

Previous topic

quagga — PyCI Quagga Module

Next topic

Build System Documentation

This Page

Quick search