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_obj, args_dict, extra_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_obj, args_dict, extra_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.7.5.tar.gz (8.3 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for delfick_app-0.7.5.tar.gz
Algorithm Hash digest
SHA256 baaafb2c884e1e9652400b02fd1287a1ffd842c2283297556d59d6fe5d96d51e
MD5 afc7c405b2f76d4556210fcec9b68047
BLAKE2b-256 3aa7c1f0cdce15bafb47c4fe2c8827a3fe2d6edd7f25f039cb503ff990bd47f0

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