emodpy.bamboo_api_utils module¶
- emodpy.bamboo_api_utils.bamboo_connection()¶
- class emodpy.bamboo_api_utils.BambooConnection¶
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/v1.21.0/lib/python3.7/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 ¶
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 ¶
Explore all possible server urls, return the first one found to exist.
- Returns
server url
- Return type
- url_exists(url: str) bool ¶
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/v1.21.0/lib/python3.7/site-packages/requests/cookies.py'> ¶
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/v1.21.0/lib/python3.7/site-packages/requests/cookies.py'>)¶
Write post-login cookies for session to disk.
- get_bamboo_api_url(relative_url: str, json: bool = False, params: dict = {}) str ¶
Get fully qualified bamboo api url from a relative url w/ given json mode and appending all parameters.
- save_credentials(username: str, password: str)¶
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()¶
Check if a login session exists using saved cookies, if not login using keyring stored creds.
- login_session_exists() bool ¶
Test whether an existing session cookie exists and an active login session exists.
- Returns
whether an active login session exists
- Return type
- login(username: Optional[str] = None, password=None) bool ¶
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 ¶
Determine whether a url is relative or fully qualified, translate relative urls to fully qualified versions.
- make_get_request(url: str, retries: int = 3) requests.models.Response ¶
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 = {}) requests.models.Response ¶
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¶
Bases:
object
A collection of methods for getting data on build results.
- classmethod build_passed(plan_key: str, build_num: int) bool ¶
Determine whether a given build succeeded or not.
- static successful_build_result(result) bool ¶
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)¶
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)¶
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¶
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 ¶
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 ¶
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 ¶
Find all ‘build essential’ artifact urls (Eradication, schema, reporters) for a specific build
- classmethod find_all_artifacts(plan_key: str, build_num: int) list ¶
Find all artifact urls (Eradication, schema, reporters) for a specific build
- classmethod find_all_artifact_names(plan_key: str, build_num: int) list ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Download Eradication.exe artifact from a specific build.
- classmethod make_exe_executable(file_path: str)¶
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 ¶
Download schema.json artifact from a specific build.
- class emodpy.bamboo_api_utils.BuildPlans¶
Bases:
object
Collection of methods for getting information on build plans.
- emodpy.bamboo_api_utils.login(username=None, password=None)¶
Pass through to BambooConnection.login()
- emodpy.bamboo_api_utils.save_credentials(username, password)¶
Pass through to BambooConnection.save_credentials()