toxicbuild.core package

Submodules

toxicbuild.core.client module

class toxicbuild.core.client.BaseToxicClient(host, port)[source]

Bases: toxicbuild.core.utils.LoggerMixin

Base client for access toxicbuild servers.

connect()[source]
disconnect()[source]
get_response()[source]
read()[source]
write(data)[source]

Writes data to the server.

Parameters:data – Data to be sent to the server. Will be converted to json and enconded using utf-8.

toxicbuild.core.cmd module

class toxicbuild.core.cmd.ToxicProgram(*args, **kwargs)[source]

Bases: mando.core.Program

Transforms a python function into a command line program. Extends mando’s Program to execute _generate_command() only when execute() is called to enable toxicbuild command hacks.

execute(*args, **kwargs)[source]

toxicbuild.core.conf module

class toxicbuild.core.conf.Settings(envvar, default_filename)[source]

Bases: object

Simple interface to a settings file.

toxicbuild.core.exceptions module

exception toxicbuild.core.exceptions.BadJsonData[source]

Bases: Exception

exception toxicbuild.core.exceptions.ConfigError[source]

Bases: Exception

exception toxicbuild.core.exceptions.ExecCmdError[source]

Bases: Exception

exception toxicbuild.core.exceptions.ImpossibillityError[source]

Bases: Exception

exception toxicbuild.core.exceptions.PluginNotFound[source]

Bases: Exception

exception toxicbuild.core.exceptions.ToxicClientException[source]

Bases: Exception

exception toxicbuild.core.exceptions.VCSError[source]

Bases: Exception

toxicbuild.core.plugins module

class toxicbuild.core.plugins.Plugin(*args, **kwargs)[source]

Bases: object

This is a base plugin. Plugins may implement aditional behavior to your builds.

classmethod get_plugin(name)[source]

Returns a Plugin subclass based on its name.

Parameters:name – Plugin’s name.
classmethod list_plugins(plugin_type=None)[source]

Returns a list of Plugin subclasses.

Parameters:plugin_type – the plugin’s type.
name = 'BaseCorePlugin'

toxicbuild.core.protocol module

class toxicbuild.core.protocol.BaseToxicProtocol(loop, connection_lost_cb=None)[source]

Bases: asyncio.streams.StreamReaderProtocol, toxicbuild.core.utils.LoggerMixin

Base protocol for toxicbulid servers

check_data()[source]

Checks if the data is valid, it means, checks if has some data, checks if it is a valid json and checks if it has a action key

client_connected()[source]

Coroutine that handles connections. You must implement this in your sub-classes. When this method is called, self.data, containing a dictionary with the data passed in the request and self.action, a string indicating which action to take are already available.

close_connection()[source]

Closes the connection with the client

connection_lost(exc)[source]
connection_made(transport)[source]

Called once, when the client connects.

Parameters:transport – transport for asyncio.StreamReader and asyncio.StreamWriter.
encrypted_token = None
get_json_data()[source]

Returns the json sent by the client.

get_raw_data()[source]

Returns the raw data sent by the client

salt = None
send_response(code, body)[source]

Send a response to client formated by the (unknown) toxicbuild remote build specs. :param code: code for this message. code == 0 is success and code > 0 is error. :param body: response body. It has to be a serializable object.

toxicbuild.core.requests module

This module implements a simple asynchronous interface for http requests.

Usage:

from toxicbuild.core import requests
response = yield from requests.get('http://google.com/')
print(response.text)
class toxicbuild.core.requests.Response(status, text)[source]

Bases: object

Encapsulates a response from a http request

toxicbuild.core.requests.delete(url, **kwargs)[source]

Performs a http DELETE request

Parameters:
  • url – Request’s url.
  • kwargs – Args passed to toxicbuild.core.requests._request().
toxicbuild.core.requests.get(url, **kwargs)[source]

Performs a http GET request

Parameters:
  • url – Request’s url.
  • kwargs – Args passed to toxicbuild.core.requests._request().
toxicbuild.core.requests.post(url, **kwargs)[source]

Performs a http POST request

Parameters:
  • url – Request’s url.
  • kwargs – Args passed to toxicbuild.core.requests._request().
toxicbuild.core.requests.put(url, **kwargs)[source]

Performs a http PUT request

Parameters:
  • url – Request’s url.
  • kwargs – Args passed to toxicbuild.core.requests._request().

toxicbuild.core.utils module

class toxicbuild.core.utils.LoggerMixin[source]

Bases: object

A simple mixin to use log on a class.

log(msg, level='info')[source]

Appends the class name before the log message.

toxicbuild.core.utils.bcrypt_string(string, salt)[source]
class toxicbuild.core.utils.changedir(path)[source]

Bases: object

toxicbuild.core.utils.daemonize(call, cargs, ckwargs, stdout, stderr, workdir, pidfile)[source]

Run a callable as a daemon

Parameters:
  • call – a callable.
  • cargs – args to call.
  • ckwargs – kwargs to call.
  • stdout – daemon’s stdout.
  • stderr – daemon’s stderr.
  • workdir – daemon’s workdir
  • pidfile – pidfile’s path
toxicbuild.core.utils.datetime2string(dt, dtformat='%a %b %d %H:%M:%S %Y %z')[source]

Transforms a datetime object into a formated string.

Parameters:
  • dt – The datetime object.
  • dtformat – The format to use.
toxicbuild.core.utils.exec_cmd(cmd, cwd, timeout=3600, out_fn=None, **envvars)[source]

Executes a shell command. Raises with the command output if return code > 0. :param cmd: command to run. :param cwd: Directory to execute the command. :param timeout: How long we should wait for a command complete. Default is 3600. :param out_fn: A coroutine that receives each line of the step output. The coroutine signature must be in the form: mycoro(line_index, line). :param envvars: Environment variables to be used in the command.

toxicbuild.core.utils.get_toxicbuildconf(directory)[source]

Returns the toxicbuild.conf module.

Parameters:directory – Directory to look for toxicbuild.conf
toxicbuild.core.utils.inherit_docs(cls)[source]

Inherit docstrings from base classes’ methods. Can be used as a decorator

Parameters:cls – Class that will inherit docstrings from its parents.
toxicbuild.core.utils.list_builders_from_config(confmodule, branch, slave)[source]
toxicbuild.core.utils.load_module_from_file(filename)[source]

Load a module from a source file :param filename: full path for file to be loaded.

toxicbuild.core.utils.localtime2utc(localdatetime)[source]

Transforms a local datetime object into a datetime object in utc time.

Parameters:localdatetime – A datetime object.
toxicbuild.core.utils.log(msg, level='info')[source]
toxicbuild.core.utils.now()[source]

Returns the localtime with timezone info.

toxicbuild.core.utils.read_stream(reader)[source]

Reads the input stream. First reads the bytes until the first “n”. These first bytes are the length of the full message.

Parameters:reader – An instance of asyncio.StreamReader
toxicbuild.core.utils.string2datetime(dtstr, dtformat='%a %b %d %H:%M:%S %Y %z')[source]

Transforns a string into a datetime object acording to dtformat.

Parameters:
  • dtstr – The string containing the formated date.
  • dtformat – The format of the formated date.
toxicbuild.core.utils.utc2localtime(utcdatetime)[source]

Transforms a utc datetime object into a datetime object in local time.

Parameters:utcdatetime – A datetime object
toxicbuild.core.utils.write_stream(writer, data)[source]

Writes data to output. Encodes data to utf-8 and prepend the lenth of the data before sending it.

Parameters:
  • writer – An instance of asyncio.StreamWriter
  • data – String data to be sent.

toxicbuild.core.vcs module

class toxicbuild.core.vcs.Git(workdir)[source]

Bases: toxicbuild.core.vcs.VCS

An interface to git version control system

checkout(named_tree)[source]

Checkout to named_tree :param named_tree: A commit, branch, tag...

clone(url)[source]

Clones a repository into self.workdir :param url: repository url

date_format = '%a %b %d %H:%M:%S %Y'
fetch()[source]

Fetch changes from remote repository

get_remote_branches()[source]

Returns a list of the remote branches available.

get_revisions(since={}, branches=None)[source]

Returns the revisions for branches since since. :param since: dictionary in the format: {branch_name: since_date}. since is a datetime object. :param branches: A list of branches to look for new revisions. If branches is None all remote branches will be used.

get_revisions_for_branch(branch, since=None)[source]

Returns the revisions for branch since since. If since is None, all revisions will be returned. :param branch: branch name :param since: datetime

has_changes()[source]

Informs if there are new revisions in the repository

pull(branch_name)[source]

Pull changes from branch_name on remote repo.

Parameters:branch_name – A branch name, like ‘master’.
update_submodule()[source]
vcsbin = 'git'
class toxicbuild.core.vcs.VCS(workdir)[source]

Bases: toxicbuild.core.utils.LoggerMixin

Generic inteface to a vcs (clone, fetch, get revisions etc...).

checkout(named_tree)[source]

Checkout to named_tree :param named_tree: A commit, branch, tag...

clone(url)[source]

Clones a repository into self.workdir :param url: repository url

exec_cmd(cmd, cwd=None)[source]

Executes a shell command. If cwd is None self.workdir will be used.

Parameters:cwd – Directory where the command will be executed.
fetch()[source]

Fetch changes from remote repository

get_remote_branches()[source]

Returns a list of the remote branches available.

get_revisions(since={}, branches=None)[source]

Returns the revisions for branches since since. :param since: dictionary in the format: {branch_name: since_date}. since is a datetime object. :param branches: A list of branches to look for new revisions. If branches is None all remote branches will be used.

get_revisions_for_branch(branch, since=None)[source]

Returns the revisions for branch since since. If since is None, all revisions will be returned. :param branch: branch name :param since: datetime

has_changes()[source]

Informs if there are new revisions in the repository

pull(branch_name)[source]

Pull changes from branch_name on remote repo.

Parameters:branch_name – A branch name, like ‘master’.
vcsbin = None
workdir_exists()[source]

Informs if the workdir for this vcs exists

toxicbuild.core.vcs.get_vcs(vcs_type)[source]

Retuns a subclass of toxicbuild.core.vcs.VCS for vcs_type

Module contents