emodpy.bamboo_api_utils module#
- class emodpy.bamboo_api_utils.BambooConnection[source]#
Bases:
object
Bamboo API config and basic functionality/connectivity wrapper.
Automatically probes the most likely endpoint locations (with and without https, with and without port numbers).
Important functions:
login: logs into the bamboo api, caches the login token so you don’t have to pass creds for every req. in a session
get_bamboo_api_url: translate a relative API URL into a fully qualified URL
normalize_url: detect whether a URL is relative or not, translate relative URLs to fully qualified ones
make_get_request: makes a request to the specified API url, adds some convenient error and login handling
download_file: downloads a file from the specified artifacts url to a location on disk
- property server: str#
str: Keeps track of a single instance of the server base url. (e.g. http://idm-bamboo:8085)
- property session_cookie: <module 'requests.cookies' from '/home/docs/checkouts/readthedocs.org/user_builds/institute-for-disease-modeling-emodpy/envs/latest/lib/python3.9/site-packages/requests/cookies.py'>#
str: Automatically load and instance the login session cookie jar.
- get_server_url(ssl: bool = True, useport: bool = False) str [source]#
Get a particular variant of the server url w/ or w/o ssl and port (e.g. False/False -> http://idm-bamboo)
- find_server() str [source]#
Explore all possible server urls, return the first one found to exist.
- Returns:
server url
- Return type:
- url_exists(url: str) bool [source]#
Try a simple get request given an endpoint url, return whether it was successful (code 200).
- property session_cookie_filename: str#
File where bamboo session cookie is stored.
- Returns:
fully qualified file path of session cookie file
- Return type:
- load_session_cookie() <module 'requests.cookies' from '/home/docs/checkouts/readthedocs.org/user_builds/institute-for-disease-modeling-emodpy/envs/latest/lib/python3.9/site-packages/requests/cookies.py'> [source]#
Load api login session cookies from disk.
- Returns:
session cookie jar
- Return type:
requests.cookies
- write_session_cookie(cookies: <module 'requests.cookies' from '/home/docs/checkouts/readthedocs.org/user_builds/institute-for-disease-modeling-emodpy/envs/latest/lib/python3.9/site-packages/requests/cookies.py'>)[source]#
Write post-login cookies for session to disk.
- get_bamboo_url(relative_url: str) str [source]#
Add bamboo server, port, and protocol to bamboo url.
- get_bamboo_api_url(relative_url: str, json: bool = False, params: dict = {}) str [source]#
Get fully qualified bamboo api url from a relative url w/ given json mode and appending all parameters.
- save_credentials(username: str, password: str)[source]#
Save bamboo api login credentials using keyring.
- Parameters:
username (str) – bamboo api login username (e.g. somebody@idmod.org)
password (str) – bamboo api login password
- ensure_logged_in()[source]#
Check if a login session exists using saved cookies, if not login using keyring stored creds.
- login_session_exists() bool [source]#
Test whether an existing session cookie exists and an active login session exists.
- Returns:
whether an active login session exists
- Return type:
- login(username: str | None = None, password=None) bool [source]#
Login to the bamboo api. If username or password are not provided, use stored credentials from keyring.
- Parameters:
username (str) – bamboo api login username (e.g. somebody@idmod.org)
password (str) – bamboo api login password
- Returns:
success/failure
- Return type:
- normalize_url(url: str) str [source]#
Determine whether a url is relative or fully qualified, translate relative urls to fully qualified versions.
- make_get_request(url: str, retries: int = 3) Response [source]#
Make a get request against the bamboo server.
- Parameters:
url (str) – relative or fully qualified url
- Returns:
request object returned from requests.get()
- Return type:
requests.Response
- make_api_get_request(relative_url: str, json: bool = False, params: dict = {}) Response [source]#
Translate relative api url to the fully qualified bamboo api url, make a get request against it.
- Parameters:
- Returns:
request object returned from requests.get()
- Return type:
requests.Response
- class emodpy.bamboo_api_utils.BuildInfo[source]#
Bases:
object
A collection of methods for getting data on build results.
- classmethod build_passed(plan_key: str, build_num: int) bool [source]#
Determine whether a given build succeeded or not.
- static successful_build_result(result) bool [source]#
Analyze a build result json object and determine if it corresponds to a successful build
- Parameters:
result – json build result
- Returns:
whether the build was successful
- Return type:
- static get_build_info(plan_key: str, index: int)[source]#
Retrieve the build info in json format for a given build plan with a relative index (0=latest)
- classmethod get_latest_successful_build(plan_key: str, scheduled_only: bool = True, max_iterations: int = 100)[source]#
Find the latest successful build within the last max_iterations builds for a given plan.
- Parameters:
- Returns:
- tuple containing:
build_num (str): build number of last successful build build_info: json data structure of build info for that build
- Return type:
(tuple)
- class emodpy.bamboo_api_utils.BuildArtifacts[source]#
Bases:
object
A collection of methods for finding and interacting with build artifacts.
- ERADICATION_EXE = 'Eradication.exe'#
- SCHEMA_JSON = 'schema.json'#
- REPORTER_PLUGINS = 'Reporter-Plugins'#
- classmethod find_artifacts_by_name(plan_key: str, build_num: int, artifact: str) list [source]#
Find all urls for files of an artifact of a given name for a specific build.
- classmethod find_artifacts(plan_key: str, build_num: int, artifact_list: list) list [source]#
Find all urls for files of a list of artifacts for a specific build.
- classmethod find_build_essential_artifacts(plan_key: str, build_num: int) list [source]#
Find all ‘build essential’ artifact urls (Eradication, schema, reporters) for a specific build
- classmethod find_all_artifacts(plan_key: str, build_num: int) list [source]#
Find all artifact urls (Eradication, schema, reporters) for a specific build
- classmethod find_all_artifact_names(plan_key: str, build_num: int) list [source]#
Find all artifact names (e.g. ‘Eradication.exe’) for a specific build (can be plugged into find_artifacts() to get actual urls that can be downloaded)
- classmethod download_artifact_to_file(plan_key: str, build_num: int, artifact, destination: str) list [source]#
Download files found for a named artifact to the filepath provided.
Additional files found will be downloaded as _2, _3, _4, etc. For example, if there are 3 files for ‘Eradication.exe’ the first will be Eradication.exe, the second will be Eradication_2.exe, the third Eradication_3.exe.
- Parameters:
- Returns:
list of local filenames of files that have been downloaded
- Return type:
- classmethod download_artifacts_to_path(plan_key: str, build_num: int, artifact, destination_path: str) list [source]#
Download all the files for a given artifact and build to a specific folder, using their original filenames.
- Parameters:
- Returns:
list of local filenames of files that have been downloaded
- Return type:
- classmethod download_latest_good_Eradication_exe(plan_key: str, destination: str) str [source]#
Find the latest successful build for a specified plan, download the Eradication.exe artifact to a specified path.
- classmethod download_latest_good_schema_json(plan_key: str, destination: str) str [source]#
Find the latest successful build for a specified plan, download the schema.json artifact to a specified path.
- classmethod download_eradication_exe(plan_key: str, build_num: str, destination: str) str [source]#
Download Eradication.exe artifact from a specific build.
- classmethod make_exe_executable(file_path: str)[source]#
On linux change the file permissions on a binary to make it executable
- Parameters:
file_path (str) – binary file to mark as executable
- classmethod download_schema_json(plan_key: str, build_num: str, destination: str) str [source]#
Download schema.json artifact from a specific build.
- class emodpy.bamboo_api_utils.BuildPlans[source]#
Bases:
object
Collection of methods for getting information on build plans.