A module to connect a CubicWeb service and send requests.

class cwbrowser.cw_connection.CWInstanceConnection(url, login, password, port=22, server_root='/', verify=True, verbosity=0)[source]

Tool to dump the data stored in a cw instance.

# Import Connection module
from cwbrowser.cw_connection import CWInstanceConnection

# Create dummy rqls
rql1 = ("Any C, G Where X is Subject, X code_in_study C, "
        "X handedness 'ambidextrous', X gender G")
rql2 = ("Any S WHERE S is Scan, S has_data A, A field '3T', "
        "S in_assessment B, B timepoint 'V1', S format 'GIS', "
        "S in_assessment C, C concerns D, D code_in_study 'ab100207'")

# HTTP test
url = @HTTPURL; login = @LOGIN; password = @PWD
connection = CWInstanceConnection(url, login, password, port=9191)
connection.execute(rql1, export_type="json")
connection.execute_with_sync(rql2, "/tmp/fuse", timer=1)

# HTTPS test
url = @HTTPSURL; login = @LOGIN; password = @PWD
connection = CWInstanceConnection(url, login, password,
                                  server_root="/home/$login")
connection.execute(rql)

Attributes

url (str) the url to the cw instance.
login (str) the cw login.
opener: OpenerDirector object that contains the connexion to the cw instance.
execute(rql, export_type='json', nb_tries=2)[source]

Method that loads the rset from a rql request.

Parameters:

rql: str (mandatory)

the rql rquest that will be executed on the cw instance.

export_type: str (optional default ‘json’)

the result set export format: one defined in ‘_EXPORT_TYPES’.

nb_tries: int (optional default 2)

number of times a request will be repeated if it fails.

Returns:

rset: list of list of str

a list that contains the requested entity parameters.

execute_with_sync(rql, sync_dir, timer=3, nb_tries=3)[source]

Method that loads the rset from a rql request through sftp protocol using the CWSearch mechanism.

Parameters:

rql: str (mandatory)

the rql rquest that will be executed on the cw instance.

sync_dir: str (mandatory)

the destination folder where the rql data are synchronized.

timer: int (optional default 3)

the time in seconds we are waiting for the fuse or twisted server update.

nb_tries: int (optional default 3)

if the update has not been detected after ‘nb_of_try’ trials raise an exception.

Returns:

rset: list of list or list of dict

a list that contains the requested cubicweb database parameters when a json rset is generated, a list of dictionaries if a csv rset is generated.

get_genotype_measure(gene_name, genomic_measure, nb_tries=3)[source]

Method that loads the genomic measures stored in PLINK format.

Parameters:

gene_name: str (mandatory)

a gene name used to limit the number of measures that will be loaded.

genomic_measure: str (mandatory)

the genomic measure name associated to PLINK files.

nb_tries: int (optional default 3)

if the update has not been detected after ‘nb_of_try’ trials raise an exception.

Returns:

rset: dict

dictionary with ‘labels’ and ‘records’ (that contains the requested cubicweb database parameters).

importers = {'json': <function loads at 0x7f12cc77a0c8>, 'csv': <function load_csv at 0x7f12c55d5050>, 'cw': <function loads at 0x7f12cc77a0c8>, 'cwsearch': <function loads at 0x7f12cc77a0c8>}
cwbrowser.cw_connection.load_csv(text, delimiter=';')[source]

Load a csv.

Parameters:

text: string (mandatory)

the csv text.

Returns:

csv_lines: list

a list containing all the csv lines.