Skip to main content

Make your Odoo scripts sing.

Project description

Anthem: make your Odoo scripts sing 🐜🎵

https://travis-ci.org/camptocamp/anthem.svg?branch=master

Anthem is a tool to help scripting Odoo instances for automated setup, upgrades, testing and more.

It should be an alternative to the other tools like oerpscenario.

Make your own songs

Writing your songs is as easy as creating a Python Package. The songs functions called by anthem must have a positional ctx argument.

## songs/install.py

def setup_company(ctx):
    """ Setup company """
    company = ctx.env.ref('base.main_company')
    company.name = 'My Company'


def main(ctx):
    setup_company(ctx)

Logs

A song can display some logs when executed with @anthem.log, Context.log and Context.log_line.

import anthem

@anthem.log
def setup_company(ctx):
   """ Setting up company """
   company = ctx.env.ref('base.main_company')
   with ctx.log('Changing name'):
       company.name = 'My Company'
       ctx.log_line('Name changed')
   with ctx.log('Loading a logo'):
       company.logo = b64encode(LOGO_CONTENT)
       ctx.log_line('Logo changed')

The decorator on the function will display the first line of the docstring. Both the decorator and the context manager will show the timing of the execution. The upper example gives:

Setting up company...
    Changing name...
        Name changed
    Changing name: 0.0150s
    Loading a logo...
        Logo changed
    Loading a logo: 0.100s
Setting up company: 0.300s

Execute your songs

Use the command line anthem. Provided your songs and openerp are in the PYTHONPATH:

anthem songs.install::main -c path/to/openerp.cfg

Anthem will execute the function main of the module songs.install with a ctx initialized with an Odoo env.

Instead of using -c for the command line, you can export the environment variable OPENERP_SERVER with the path of the configuration file.

export OPENERP_SERVER=path/to/openerp.cfg
anthem songs.install::main

In order to have openerp in the PYTHONPATH, you might install it as a package with pip install -e or directly modify the PYTHONPATH.

In order to have your songs in the PYTHONPATH, the better is to make a Python package out of them.

Testing

Dependencies

To run the tests, you must have Postgresql running, with accesses for your user (or you will have to modify tests/config/odoo.cfg with your database username and password).

Run the tests

To run anthem’s tests, it is a good idea to do an editable install of it in a virtualenv, and then intall and run tox as follows:

$ git clone https://github.com/camptocamp/anthem.git
Cloning into 'anthem'...
$ cd anthem
$ python2 -m virtualenv env
$ source env/bin/activate
$ pip install -e .
$ pip install pytest invoke tox
$ tox

Additional arguments will be passed to pytest:

$ tox -e py27 -- -x tests/test_cli.py

If you prefer to execute the tests directly with pytest, you can run:

$ OPENERP_SERVER=tests/config/odoo.cfg py.test

But before, you have to ensure to have the proper environment for the tests with:

$ invoke tests.prepare
$ invoke tests.createdb

Those steps, automatically called when using tox, will download the nightly release of Odoo and install it as a package, so tests can be run against it (and that’s also why it is important to use a virtualenv!)

When calling pytest, you have to define the OPENERP_SERVER environment variable with the configuration file for the Odoo database that will be used for the tests.

Release History

Unreleased

Features

Bugfixes

Improvements

Documentation

Build

0.5.0 (2016-10-12)

Features

  • Support Odoo 10

Bugfixes

  • ‘records.add_xmlid’ lyrics do no longer fail when it already exists

0.4.0 (2016-08-19)

Features

  • New lyrics: CSV loaders from path or stream

  • New ctx.log_line to print a line respecting the current indentation

Improvements

  • Add tests for the existing lyrics

Build

  • Finally green builds!

0.3.0 (2016-07-26)

Features

  • Add –quiet mode

Fixes

  • Encode the logged strings to the default encoding or utf8

  • Allow to use Ctrl-c to stop anthem.

  • Set openerp’s loglevel to ERROR, its logs clutter anthem’s own outputs

0.2.0 (2016-07-22)

Features

  • Ability to log descriptions and timings in songs with the context manager Context.log and the decorator anthem.log.

    from anthem import log
    
    @log
    def setup_company(ctx):
        """ Setup company """
        # do stuff
        with ctx.log('other stuff'):
            # do other stuff
    
    @log
    def load_data(ctx):
        """ Load data """
        # load
    
    @log
    def main(ctx):
        setup_company(ctx)
        load_data(ctx)

    If we run anthem on main, we will get:

    running... main
       running... Setup company
          running... other stuff
          other stuff: 0.850s
       Setup company: 1.100s
       running... Load data
       Load data: 2.900s
    main: 4.000s

0.1.3 (2016-07-07)

Fixes

  • Correct lyric to create or update a record

0.1.2 (2016-07-07)

  • Add a lyric to create a xmlid

  • Add a lyric to create or update a record

0.1.1 (2016-06-23)

  • Fixed crash on non-editable install.

0.1.0 (2016-06-23)

Initial release.

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

anthem-0.5.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distributions

anthem-0.5.0.linux-x86_64.tar.gz (11.6 kB view details)

Uploaded Source

anthem-0.5.0-py2.7.egg (16.8 kB view details)

Uploaded Source

anthem-0.5.0-py2-none-any.whl (12.9 kB view details)

Uploaded Python 2

File details

Details for the file anthem-0.5.0.tar.gz.

File metadata

  • Download URL: anthem-0.5.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for anthem-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2712b6d280b3d28d54f2cf5580cb7e6fb3e43ec20b7e0743e87252f0a41b38f6
MD5 fa31e5a0ae3e5a8538f5bafade4ca020
BLAKE2b-256 ce84841207330f10ae4df80657ded64bef8f6ffe0c6269d0efba3099e1b9a637

See more details on using hashes here.

File details

Details for the file anthem-0.5.0.linux-x86_64.tar.gz.

File metadata

File hashes

Hashes for anthem-0.5.0.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 f94f5c7f26d9c62fd2b45fd71a47658bcbecbc6df7df1405555a6cb6886e2326
MD5 388e29b91fc14fc97f883ed2941e00ef
BLAKE2b-256 10b22cfa41cb41f79dc2a9cb3eb8764085ad0ff15375e60c050c043e43927bd2

See more details on using hashes here.

File details

Details for the file anthem-0.5.0-py2.7.egg.

File metadata

  • Download URL: anthem-0.5.0-py2.7.egg
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for anthem-0.5.0-py2.7.egg
Algorithm Hash digest
SHA256 a4030c0a42de7f7b207f8d8d1dbee0f496c62a07827800142063030a53e8bd3a
MD5 1600be9654c7d71e2d88b38c52f8cf19
BLAKE2b-256 2f006b4080042362601d987bef445f23c4ba7be00c631f9e2282658e474daec2

See more details on using hashes here.

File details

Details for the file anthem-0.5.0-py2-none-any.whl.

File metadata

File hashes

Hashes for anthem-0.5.0-py2-none-any.whl
Algorithm Hash digest
SHA256 1119652dff1fdcded62ea95de7b16700b69a00f9fe2720613edd3c404f499f78
MD5 fffea2b362c30056fdb5b31e2ea361bb
BLAKE2b-256 aefa3d7f6e8b240a53bab036319f64657f14d9f498697f4c51ef1ae33d399d96

See more details on using hashes here.

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