gcshelpers: a collection of helper classes and functions for the mozintermittent Google Cloud services.
Project description
About gcshelpers
The gcshelpers library provides helper functions and utility classes for the mozintermittent microservices to interact with the Google Cloud.
Contents
Class: Config
Config
is a wrapper for JSON configuration files. Accessing CONFIG
the first time leads to a
lazy initialization of the configuration object. The name of the configuration file is derived from
the calling instance, i.e. the package gcshelpers
is called from. This means using
gcshelpers.config.CONFIG
from hgminer
will load the hgminer.conf
configuration file. The
library will first look for a file in the current directory, then the user's home directory, and
finally /etc
.
If no configuration file can be found, the library attempts to create one from an example file in
the calling project's asset
directory. Assuming hgminer
is executed and no configuration file is
present, gcshelpers
attempts to copy hgminer/assets/hgminer.conf.example
to the user's home
directory.
The JSON file is converted into an object and can be subscribed to via properties or dictionary access. This means that the following config will yield the below valid accesses:
{
"contact": {
"email": "sascha.just@own-hero.net"
}
}
CONFIG['contact']['email']
If the local assets
directory contains a grammar (ANTLR4), the configuration is checked against
this grammar during construction, i.e. when the config is initially read during the first access.
Grammar example
The example below requires a configuration that consists of a contact entry having a name
and
email
set, while the structure of those is defined in the terminal section.
doc {
contact : {
name: NAME,
email: EMAIL
}
}
@terminals
NAME : [A-Za-z].*;
EMAIL : [a-zA-Z0-9_\-\.\+]+ '@' [a-zA-Z0-9_\-\.]+ '.' [a-zA-Z]{2,};
Class: MozLogger
This class wraps the standard logger with a default configuration. This also provides means to log to Pub/Sub. It features eager initialization and can directly be used. If no log configuration is present, one is created on the fly.
LOGGER.debug('Persisting %s', taskid)
Function: pkgload
This function lets you load assets from the package. Make sure you specify any assets in the
Manifest.in
to make sure they are installed together with the package.
QUERY_INSERT = pkgload(__package__, 'assets/insert_job.sql')
The storage module
The module contains methods to interact with Google Cloud Storage.
The telemetry module
The module contains methods to interact with Google Pub/Sub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for gcshelpers-SaschaJust-0.1a1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | de4d523ca08afbc890e60a90a5cb083ec35eae426e77e51db842042f5e79cf55 |
|
MD5 | 4e99c402b8b593638746d71e13d57f82 |
|
BLAKE2b-256 | 43fd09945cf19aed959b67d5b39d5df60e00eee2241078cec9bb275d11e2beed |
Hashes for gcshelpers_SaschaJust-0.1a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e4356637ca2a34b3bdadcc8a3f6b0809c1b1f6937f20642fca1ae404a3a44d6 |
|
MD5 | fb224a5612c430cd1f0cef126a97d0f9 |
|
BLAKE2b-256 | de93ea7b05b471cfc6aa5a74fbddcae7dd153a1edc7e541b2482fb717cb4d273 |