pyfarm.agent.utility module

Utilities

Top level utilities for the agent to use internally. Many of these are copied over from the master (which we can’t import here).

pyfarm.agent.utility.validate_environment(values)[source]

Ensures that values is a dictionary and that it only contains string keys and values.

pyfarm.agent.utility.validate_uuid(value)[source]

Ensures that value can be converted to or is a UUID object.

pyfarm.agent.utility.TASKS_SCHEMA(values)
pyfarm.agent.utility.default_json_encoder(obj, return_obj=False)[source]
pyfarm.agent.utility.json_safe(source)[source]

Recursively converts source into something that should be safe for json.dumps() to handle. This is used in conjunction with default_json_encoder() to also convert keys to something the json encoder can understand.

pyfarm.agent.utility.quote_url(source_url)[source]

This function serves as a wrapper around urlsplit() and quote() and a url that has the path quoted.

pyfarm.agent.utility.dumps(*args, **kwargs)[source]

Agent’s implementation of json.dumps() or pyfarm.master.utility.jsonify()

pyfarm.agent.utility.request_from_master(request)[source]

Returns True if the request appears to be coming from the master

class pyfarm.agent.utility.UTF8Recoder(f, encoding)[source]

Bases: object

Iterator that reads an encoded stream and reencodes the input to UTF-8

next()[source]
class pyfarm.agent.utility.UnicodeCSVReader(f, dialect=<class csv.excel at 0x7f9c46d3e808>, encoding='utf-8', **kwds)[source]

Bases: object

A CSV reader which will iterate over lines in the CSV file “f”, which is encoded in the given encoding.

next()[source]
class pyfarm.agent.utility.UnicodeCSVWriter(f, dialect=<class csv.excel at 0x7f9c46d3e808>, encoding='utf-8', **kwds)[source]

Bases: object

A CSV writer which will write rows to CSV file “f”, which is encoded in the given encoding.

writerow(row)[source]
writerows(rows)[source]
pyfarm.agent.utility.total_seconds(td)[source]

Returns the total number of seconds in the time delta object. This function is provided for backwards comparability with Python 2.6.

class pyfarm.agent.utility.AgentUUID[source]

Bases: object

This class wraps all the functionality required to load, cache and retrieve an Agent’s UUID.

log = <pyfarm.agent.logger.python.Logger object at 0x7f9c46aa4c10>
classmethod load(path)[source]

A classmethod to load a UUID object from a path. If the provided path does not exist or does not contain data which can be converted into a UUID object None will be returned.

classmethod save(agent_uuid, path)[source]

Saves agent_uuid to path. This classmethod will also create the necessary parent directories and handle conversion from the input type uuid.UUID.

classmethod generate()[source]

Generates a UUID object. This simply wraps uuid.uuid4() and logs a warning.