diff --git a/essay/log.py b/essay/log.py index 3f58c17..7efac09 100644 --- a/essay/log.py +++ b/essay/log.py @@ -1,12 +1,15 @@ # coding: utf-8 -from os import path +from __future__ import unicode_literals + +import sys import logging.config +from os import path def init_log(log_dir=None): if log_dir and not path.exists(log_dir): - msg = u'指定路径不存在:%s' % log_dir - print msg.encode('utf-8') + msg = '指定路径不存在:%s' % log_dir + sys.stdout(msg) log_dir = None config = { diff --git a/essay/main.py b/essay/main.py index f318fd7..f248d13 100644 --- a/essay/main.py +++ b/essay/main.py @@ -1,4 +1,5 @@ # coding:utf-8 +from __future__ import unicode_literals import re import sys @@ -36,17 +37,17 @@ def main(): if re.match('^[a-zA-Z0-9_]+$', project_name): create_project(project_name, options.template) else: - print u'无效工程名: ' + project_name + sys.stdout.write('无效工程名: ' + project_name) elif len(sys.argv) >= 2 and sys.argv[1] == 'init': options, args = init_options() project_name = sys.argv[2] if re.match('^[a-zA-Z0-9_]+$', project_name): init_project(project_name, options.template) else: - print u'无效工程名: ' + project_name + sys.stdout.write('无效工程名: ' + project_name) elif len(sys.argv) >= 2 and sys.argv[1] == 'pinstall': if len(sys.argv) == 2 or sys.argv[2] == '-h': - print "es pinstall " + sys.stdout.write("es pinstall ") return args = sys.argv[1:] @@ -55,7 +56,7 @@ def main(): pip.main(args) else: if len(sys.argv) == 2 and '-h' in sys.argv: - print help_text + sys.stdout.write(help_text) pip.main() diff --git a/essay/tasks/deploy.py b/essay/tasks/deploy.py index 85b4eac..2986a67 100644 --- a/essay/tasks/deploy.py +++ b/essay/tasks/deploy.py @@ -12,10 +12,11 @@ @task(default=True) @parallel(30) def deploy(version, venv_dir, profile): - """ - 发布指定的版本 + """ 发布指定的版本,会自动安装项目运行所需要的包 - 会自动安装项目运行所需要的包 + version:build之后的版本 + venv_dir:虚拟环境名称 + profile:profile参数会传递到supervisord.conf中 """ if not version: @@ -23,11 +24,18 @@ def deploy(version, venv_dir, profile): virtualenv.ensure(venv_dir) + pre_hook = env.DEPLOY_PRE_HOOK + post_hook = env.DEPLOY_POST_HOOK + with virtualenv.activate(venv_dir): + if callable(pre_hook): + pre_hook(version, venv_dir, profile) supervisor.ensure(project=env.PROJECT, profile=profile) package.install(env.PROJECT, version) supervisor.shutdown() supervisor.start() + if callable(post_hook): + post_hook(version, venv_dir, profile) @task(default=True) diff --git a/essay/templates/default/__project__/log.py.tpl b/essay/templates/default/__project__/log.py.tpl index 8615153..8072816 100644 --- a/essay/templates/default/__project__/log.py.tpl +++ b/essay/templates/default/__project__/log.py.tpl @@ -1,11 +1,13 @@ # coding: utf-8 +from __future__ import unicode_literals + from os import path import logging.config def init_log(log_dir=None): # if log_dir and not path.exists(log_dir): # msg = u'指定路径不存在:%s' % log_dir -# print msg.encode('utf-8') +# print(msg.encode('utf-8')) # return config = { @@ -43,4 +45,4 @@ def init_log(log_dir=None): } } - logging.config.dictConfig(config) \ No newline at end of file + logging.config.dictConfig(config) diff --git a/essay/templates/default/__project__/main.py.tpl b/essay/templates/default/__project__/main.py.tpl index 8c2c5d4..58c3089 100644 --- a/essay/templates/default/__project__/main.py.tpl +++ b/essay/templates/default/__project__/main.py.tpl @@ -12,9 +12,9 @@ class index: return "Hello, world!" def main(): - print 'version:', settings.__version__ - print 'git version:', settings.__git_version__ - print 'release time', settings.__release_time__ + print('version:', settings.__version__) + print('git version:', settings.__git_version__) + print('release time', settings.__release_time__) app = web.application(urls, globals()) app.run()