Skip to main content

Customized App mainline helper

Project description

A framework to simplify and remove duplication when creating a new application. It is opinionated in nature and aims to be declarative.

Getting Started

The most basic example of usage would look something like:

#!/usr/bin/env python
from delfick_app import App

class MyApp(object):
    def start(self, cli_args):
        print "hello world"

class Main(App):
    def execute(self, args, extra_args, cli_args, logging_handler):
        """Start your app!"""
        MyApp().start(cli_args)

main = Main.main
if __name__ == "__main__":
    main()

This will give you a usage that looks like:

$ ./app.py [–verbose|–silent|–debug]

Where –verbose and –debug show more logs and –silent silences all the logs.

Your logs will be colourful and your mainline will catch and print any DelfickError exceptions nicely to the terminal.

Advanced Usage

from my_app import MyApp, VERSION

from delfick_app import App
import logging

class Main(App):

    # Setting both VERSION and boto_useragent_name
    # Will change boto's useragent to include {name}/{VERSION}
    # Not setting them means boto's useragent is unchanged
    VERSION = VERSION
    boto_useragent_name = "myapp"

    # Cli options for configuration special cli options
    cli_categories = ['app']
    cli_description = "My amazing app"
    cli_environment_defaults = {"CONFIG_LOCATION": ("--config", './config.yml')}
    cli_positional_replacements = [('--task', 'list_tasks'), '--environment']

    def execute(self, args, extra_args, cli_args, logging_handler):
        # Optionally set the logging theme between 'light' and 'dark'
        self.setup_logging_theme(logging_handler, colors="dark")

        # Do what is necessary to start the app
        app = MyApp()
        app.start(cli_args)

    def setup_other_logging(self, args, verbose=False, silent=False, debug=False):
        logging.getLogger("boto").setLevel([logging.CRITICAL, logging.ERROR][verbose or debug])

    def specify_other_args(self, parser, defaults):
        parser.add_argument("--task"
            , help = "The task to execute"
            , **defaults['--task']
            )

        parser.add_argument("--environment"
            , help = "the environment to use"
            , **defaults["--environment"]
            )

        parser.add_argument("--config"
            , help = "The configuration to use"
            , **defaults["--config"]
            )

main = Main.main
if __name__ == '__main__':
    main()

With the above configuration, the following three usages are equivalent:

$ ./app.py some_task dev --config ./config.yml

$ ./app.py --task some_task --environment dev --config ./config.yml

$ APP_CONFIG=./config.yml ./app.py some_task dev

Installation

Just use pip:

$ pip install delfick_app

Tests

Run the following:

$ mkvirtualenv delfick_app
$ workon delfick_app
$ pip install -e .
$ pip install -e ".[tests]"

To install delfick_app and it’s dependencies.

Then to run the tests:

$ ./test.sh

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

delfick_app-0.6.9.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file delfick_app-0.6.9.tar.gz.

File metadata

  • Download URL: delfick_app-0.6.9.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for delfick_app-0.6.9.tar.gz
Algorithm Hash digest
SHA256 11a05e1a66090849c4d9da45649f1949c82ed26f12de7203831b0be2ab018b9a
MD5 4cc7e2ea1610168681a55e342ace1e8e
BLAKE2b-256 1dfe5e17c4fbf0402ce0a74f094355023505191fca9a9ac492167eba5d6516d4

See more details on using hashes here.

Supported by

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