Common util methods for concourse resources in python
pip install git+https://github.com/cosee-concourse/concourse-common.git
Note that pip install without a specified version installs the latest tagged version (see Concourse-Common Tags)
To install with a specific version:
pip install git+https://github.com/cosee-concourse/[email protected]
Adding to the requirements.txt as:
git+https://github.com/cosee-concourse/concourse-common.git
compress_folder(filename, folderpath)
: Compresses folder as tar.gz.
uncompress_file(filename, destination)
: Uncompresses file to destination
files(path)
: Returns list of all files at path.
check_system_argument_number
: Checks the number of system arguments the python module gets.
Returns true if the number of arguments is two else it returns false.
join_paths(*paths)
: Wrapper method for os.path.join
log(*args, **kwargs)
: Prints to stderr to create log output in concourse
The other log methods create colored log output using ANSI Escape codes. Defaults back to red after the warning oder info log messages so that pythons exceptions are printed in red
log_error
: Red output.
log_warning
: Yellow output.
log_info
: White output.
validate_filepath(filepath)
: Validates that file at filepath exists
read_file(file_path)
: Reads file contents as string
load_payload
: Loads concourse json input from stdin, logs it in a temporary folder and returns it as json
validate_payload(payload, schema)
: Validates the json payload given a json schema (e.g. generated by JSON Schema)
Prints validation errors to stderr
load_and_validate_payload(schemas, request)
: Calls load_payload
and validate_payload(payload,schema)
.
Chooses correct schema from the schams module based on the request. Request is a enum contained in request module
(CHECK, IN, OUT). Schemas in schemas module need to be named check_schema, in_schema and out_schema.
Returns two values:
-
validity of payload as boolean
-
payload as dictionary
Example usage:
valid, payload = load_and_validate_payload(schemas, Request.CHECK)
Validates payload with check_schema in schemas
get_version(payload, version_key_name)
: For a payload and the name of the version key, returns the version and None
if the key does not exist.
get_versions_as_list(versions, version_key_name)
: Returns list of versions as json. Used for output in check.
Uses version_key_name
as name for the version key.
get_version_output(version, version_key_name)
: Returns version output used for in and out. Uses version_key_name
as name for the version key.
contains_params_key(payload,key_name)
: Checks if parameter key is in concouse payload.
get_source_value(payload,key)
: Get value for key in source dictionary of json payload. Returns None if key does not exist.
get_params_value(payload,key)
: Get value for key in params dictionary of json payload. Returns None if key does not exist.
match_versions(regexp, files, version_request)
: Returns list of all versions where
the file name matches the regexp and the semantic version inside the file name is higher than the version in version_request
mock_stderr
: Mocks stderr with a StringIO object and returns it.
This object can then be used with read_from_io(StringIO)
to read all lines from stderr.
mock_stdout
: Same as mock_stderr
but mocks stdout.
read_from_io(io)
: Reads all lines from a StringIO object from the beginning and strips the new line character from it.
put_stdin(content)
: Mocks stdin with a StringIO object and writes string content to the object.
To create a new version of this package you need to create a new tag with a higher version than the latest tagged version.
For example with git:
git tag -a v0.1.0 -m 'version 0.1.0 initial version'
git push --tags
or create a new tag on GitHub
Note: also bump the version in setup.py before tagging