Skip to content

Commit

Permalink
Add settings and local_settings env variables support
Browse files Browse the repository at this point in the history
  • Loading branch information
limodou committed Apr 18, 2014
1 parent 4eecff6 commit ef89bc7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Uliweb Change Log
And when id and condition given both, only when id is not integer or valid expression
condition will be used. So in most cases, you don't need pass condition.
* If not set url option for session of database type, it'll automatically use ORM settings if exists
* Add settings and local_settings env variables support

0.2.6 Version
-----------------
Expand Down
7 changes: 5 additions & 2 deletions uliweb/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ def execute(self, callback=None):
global_options = self.global_options
args = self.argv

global_options.settings = global_options.settings or os.environ.get('SETTINGS', 'settings.ini')
global_options.local_settings = global_options.local_settings or os.environ.get('LOCAL_SETTINGS', 'local_settings.ini')

if callback:
callback(global_options)

Expand Down Expand Up @@ -333,9 +336,9 @@ class ApplicationCommandManager(CommandManager):
help='show this help message and exit.'),
make_option('-v', '--verbose', action='store_true',
help='Output the result in verbose mode.'),
make_option('-s', '--settings', dest='settings', default='settings.ini',
make_option('-s', '--settings', dest='settings', default='',
help='Settings file name. Default is "settings.ini".'),
make_option('-L', '--local_settings', dest='local_settings', default='local_settings.ini',
make_option('-L', '--local_settings', dest='local_settings', default='',
help='Local settings file name. Default is "local_settings.ini".'),
make_option('--project', default='.', dest='project',
help='Your project directory, default is current directory.'),
Expand Down
25 changes: 16 additions & 9 deletions uliweb/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def install_config(apps_dir):
sys.path.insert(0, p)

def make_application(debug=None, apps_dir='apps', project_dir=None,
include_apps=None, debug_console=True, settings_file='settings.ini',
local_settings_file='local_settings.ini', start=True, default_settings=None,
dispatcher_cls=None, dispatcher_kwargs=None, debug_cls=None, debug_kwargs=None, reuse=True):
include_apps=None, debug_console=True, settings_file=None,
local_settings_file=None, start=True, default_settings=None,
dispatcher_cls=None, dispatcher_kwargs=None, debug_cls=None, debug_kwargs=None,
reuse=True, verbose=False):
"""
Make an application object
"""
Expand All @@ -79,6 +80,10 @@ def make_application(debug=None, apps_dir='apps', project_dir=None,
if reuse and hasattr(SimpleFrame.__global__, 'application') and SimpleFrame.__global__.application:
return SimpleFrame.__global__.application

#process settings and local_settings
settings_file = settings_file or os.environ.get('SETTINGS', 'settings.ini')
local_settings_file = local_settings_file or os.environ.get('LOCAL_SETTINGS', 'local_settings.ini')

dispatcher_cls = dispatcher_cls or SimpleFrame.Dispatcher
dispatcher_kwargs = dispatcher_kwargs or {}

Expand All @@ -103,6 +108,10 @@ def make_application(debug=None, apps_dir='apps', project_dir=None,
default_settings=default_settings,
**dispatcher_kwargs)

if verbose:
log.info(' * settings file is "%s"' % settings_file)
log.info(' * local settings file is "%s"' % local_settings_file)

#settings global application object
SimpleFrame.__global__.application = app

Expand Down Expand Up @@ -148,7 +157,7 @@ def make_application(debug=None, apps_dir='apps', project_dir=None,
return app

def make_simple_application(apps_dir='apps', project_dir=None, include_apps=None,
settings_file='settings.ini', local_settings_file='local_settings.ini',
settings_file='', local_settings_file='',
default_settings=None, dispatcher_cls=None, dispatcher_kwargs=None, reuse=True):
settings = {'ORM/AUTO_DOTRANSACTION':False}
settings.update(default_settings or {})
Expand Down Expand Up @@ -737,7 +746,8 @@ def format(self, record):
def get_app(debug_cls=None):
return make_application(options.debug, project_dir=global_options.project,
include_apps=include_apps, settings_file=global_options.settings,
local_settings_file=global_options.local_settings, debug_cls=debug_cls)
local_settings_file=global_options.local_settings, debug_cls=debug_cls,
verbose=global_options.verbose)

if options.ssl:
ctx = 'adhoc'
Expand Down Expand Up @@ -934,10 +944,7 @@ class ShellCommand(Command):
def make_shell_env(self, global_options):
from uliweb import functions

application = SimpleFrame.Dispatcher(project_dir=global_options.project,
settings_file=global_options.settings,
local_settings_file=global_options.local_settings,
start=False)
application = self.get_application()

if global_options.project not in sys.path:
sys.path.insert(0, global_options.project)
Expand Down

0 comments on commit ef89bc7

Please sign in to comment.