Common functionality

For various reasons the common functions like errors and config are held not in a seperate repo but here.

rhaptos2.repo.backend

Provide a abstracted SQL Alchemy backend to allow models to connect to postegres.

rhaptos2.repo.backend.clean_dbase(config)[source]

clear down the database tables - used for testing purposes

rhaptos2.repo.backend.initdb(confd)[source]

This could become a conn factory.

rhaptos2.repo.backend.status_dbase(config)[source]

clear down the database tables - used for testing purposes

rhaptos2.repo.configuration

Contains a common configuration parsing class and various utilities for dealing with configuration.

Author: Michael Mulich Copyright (c) 2012 Rice University

This software is subject to the provisions of the GNU Lesser General Public License Version 2.1 (LGPL). See LICENSE.txt for details.

class rhaptos2.repo.configuration.Configuration(settings={}, **sections)[source]

A configuration settings object

The Configuration class reads from a file, is case-sensitive and it transforms the [app] section into top-level dotted values (ie print conf.foo returns “bar”) and stores all other sections under a key of the same name

It looks and acts like a dict. And has

>>> initxt = '''[app]
... appkey=appval
...
... [test]
... foo=1
...
... [test2]
... bar=1
... '''
>>> f = "/tmp/foo.ini"
>>> open(f, "w").write(initxt)
>>> C = Configuration.from_file(f)
>>> expected = {'test': {'foo': '1'},
...            'test2': {'bar': '1'},
...            "appkey":"appval"}
>>> assert C == expected
>>> assert C.test == {'foo': '1'}
>>> assert C.appkey == "appval"
>>> assert C.test["foo"] == '1'
classmethod from_file(file, app_name='app')[source]

Initialize the class from an INI file.

rhaptos2.repo.log

Provide common logging facilites for all rhaptos2 components.

We expect to create two log handlers in the application

  1. to log audit messages to stderr
  2. to fire off statsd events

We combine both into one logger, I think that is the best approach.

See set_logger in rhaptos2.repo for useage

Changelog:

2012-09-13 : removed the get_logger facility, basically each app is
responsible for setting up its own logger. This merely supplies a custom Handler for statsd
class rhaptos2.repo.log.StatsdHandler(host, port, debug=False)[source]

Logging Handler class that emits statsd calls to graphite, then stdout

It only does incr logs, ie event counting. Thats probably appropriate for most all log related stats

issues - we init with host and port, probably a bad idea. Just do not want to muck around with config mdule for logging yet.

>>> lg = logging.getLogger("doctest") 
>>> h = StatsdHandler("localhost", 2222, True)
>>> lg.addHandler(h)
>>> lg.warn("an error", extra={"statsd": ['a.b', 'e.f']})
Firing a.b
Firing e.f

So we take it on trust that statsd fired. This is a unsolved problem with statsd.

emit(record)[source]

given a LogRecord r, extract the dotted names if any and fire off

Hmm, testing this in doctest (in anything) is hard.... So A totally contrived test

Project Versions

Table Of Contents

Previous topic

Authentication API

Next topic

run

This Page