Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcshelpers-SaschaJust-0.1a1.tar.gz (10.1 kB view hashes)

Uploaded Source

Built Distribution

gcshelpers_SaschaJust-0.1a1-py3-none-any.whl (12.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page