User:Legoktm/wmflib

From Wikitech

"wmflib" is a simple Python library to help with some common tasks that labs users might encounter. Source code is here and in the public domain. Patches welcome.

Installation

pip install wmflabs. Should probably ask for this to be installed labs-wide....

Examples

An example how to connect to a replicating database without needing to remember all the various options.

from wmflabs import db
conn = db.connect('enwiki')  # You can also use "enwiki_p"
# conn is a oursql.connection object.
with conn.cursor() as cur:
    cur.execute(query)  # Or something....

An example on how to submit a job to the grid engine. This should also work for CGI scripts.

from wmflabs import grid
grid.submit('python script.py', N='script_test', mem="500M")
# Equivalent to running: $ jsub -N "script_test" -mem "500M" python script.py
# Return value is the job number.