Browse Source

moved custom handler to ext/

bugfixes
harshadyeola 10 years ago
parent
commit
6a79d452b7
  1. 19
      ee/cli/ext/ee_outputhandler.py
  2. 24
      ee/cli/main.py

19
ee/cli/ext/ee_outputhandler.py

@ -0,0 +1,19 @@
# Based on https://github.com/datafolklabs/cement/issues/295
# To avoid encoding releated error,we defined our custom output handler
# I hope we will remove this when we upgarde to Cement 2.6 (Not released yet)
from cement.ext.ext_mustache import MustacheOutputHandler
class EEOutputHandler(MustacheOutputHandler):
class Meta:
label = 'ee_output_handler'
def _load_template_from_file(self, path):
for templ_dir in self.app._meta.template_dirs:
full_path = fs.abspath(os.path.join(templ_dir, path))
if os.path.exists(full_path):
self.app.log.debug('loading template file %s' % full_path)
return open(full_path, encoding='utf-8', mode='r').read()
else:
continue

24
ee/cli/main.py

@ -14,9 +14,9 @@ from cement.core import foundation
from cement.utils.misc import init_defaults
from cement.core.exc import FrameworkError, CaughtSignal
from cement.utils import fs
from cement.ext.ext_mustache import MustacheOutputHandler
from cement.ext.ext_argparse import ArgParseArgumentHandler
from ee.core import exc
from ee.cli.ext.ee_outputhandler import EEOutputHandler
# Application default. Should update config/ee.conf to reflect any
# changes, or additions here.
@ -31,22 +31,12 @@ defaults['ee']['plugin_dir'] = '/var/lib/ee/plugins'
# External templates (generally, do not ship with application code)
defaults['ee']['template_dir'] = '/var/lib/ee/templates'
# Based on https://github.com/datafolklabs/cement/issues/295
# To avoid encoding releated error,we defined our custom output handler
# I hope we will remove this when we upgarde to Cement 2.6 (Not released yet)
class EEOutputHandler(MustacheOutputHandler):
class EEArgHandler(ArgParseArgumentHandler):
class Meta:
label = 'ee_output_handler'
label = 'ee_args_handler'
def _load_template_from_file(self, path):
for templ_dir in self.app._meta.template_dirs:
full_path = fs.abspath(os.path.join(templ_dir, path))
if os.path.exists(full_path):
self.app.log.debug('loading template file %s' % full_path)
return open(full_path, encoding='utf-8', mode='r').read()
else:
continue
def error(self, message):
super(EEArgHandler, self).error("unknown args")
class EEApp(foundation.CementApp):
@ -72,6 +62,8 @@ class EEApp(foundation.CementApp):
# default output handler
output_handler = EEOutputHandler
arg_handler = EEArgHandler
debug = TOGGLE_DEBUG

Loading…
Cancel
Save