Giter Site home page Giter Site logo

tornado_conf's Introduction

Tornado Settings

Instalation

$ pip install tornado_conf

Usage

Project structure:

◉ project root/
├ <project_name>/
│ ├ ...
│ ├ settings/
│ │ ├ __init__.py
│ │ ├ server.cfg
│ │ ├ base.py
│ │ ├ local.py
│ │ ├ prod.py
│ │ └ qa.py
│ ├ ...
│ └ app.py
├ ...
├ LICENSE
├ README
└ .gitignore

settings/base.py:

setting1 = 'base setting'
SETTING = 'COMMON'

settings/local.py:

from .base import *

setting1 = 'local setting'

settings/prod.py:

from .base import *

setting1 = 'prod setting'
SETTING = 'PROD'

app.py:

import tornado.ioloop
import tornado.web
from tornado.options import options

from tornado_conf import setup_settings, settings

# ...

if __name__ == '__main__':
    setup_settings(settings_package='settings')
    options.parse_config_file('settings/server.cfg', final=False)
    options.parse_command_line()

    print settings.SETTING, settings.setting1

    application = tornado.web.Application([
        # ...
    ], **settings)

    application.listen(8765)
    tornado.ioloop.IOLoop.instance().start()

Shell:

$ python app.py
COMMON base setting

$ python app.py --settings=local
COMMON local setting

$ python app.py --settings=prod
PROD prod setting

$ python app.py --settings=unknown
Traceback (most recent call last):
  ...
ImportError: No module named unknown

Bitdeli Badge

tornado_conf's People

Contributors

miphreal avatar bitdeli-chef avatar

Stargazers

songzhengang avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.