You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/05/03 23:58:16 UTC
[46/50] git commit: [#6110] Log output on all tasks to prevent Broken
pipe errors
[#6110] Log output on all tasks to prevent Broken pipe errors
Signed-off-by: Cory Johns <cj...@slashdotmedia.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/94cd1ede
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/94cd1ede
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/94cd1ede
Branch: refs/heads/db/6007
Commit: 94cd1ede798aa2cb4ec4b3a515cb1a3f627a2eaa
Parents: b4fa50d
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Fri May 3 17:09:19 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri May 3 18:59:22 2013 +0000
----------------------------------------------------------------------
Allura/allura/lib/helpers.py | 23 ++++++++++++++++++++++-
Allura/allura/model/monq_model.py | 4 +++-
Allura/allura/scripts/scripttask.py | 23 ++++-------------------
3 files changed, 29 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/94cd1ede/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 9d97c02..d55b511 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.
+import sys
import os
import os.path
import difflib
@@ -705,4 +706,24 @@ def get_first(d, key):
def datetimeformat(value, format='%Y-%m-%d %H:%M:%S'):
- return value.strftime(format)
\ No newline at end of file
+ return value.strftime(format)
+
+
+@contextmanager
+def log_output(log):
+ class Writer(object):
+ def __init__(self, func):
+ self.func = func
+
+ def write(self, buf):
+ self.func(buf)
+
+ _stdout = sys.stdout
+ _stderr = sys.stderr
+ sys.stdout = Writer(log.info)
+ sys.stderr = Writer(log.error)
+ try:
+ yield log
+ finally:
+ sys.stdout = _stdout
+ sys.stderr = _stderr
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/94cd1ede/Allura/allura/model/monq_model.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/monq_model.py b/Allura/allura/model/monq_model.py
index 49cb6e9..d298c1b 100644
--- a/Allura/allura/model/monq_model.py
+++ b/Allura/allura/model/monq_model.py
@@ -30,6 +30,7 @@ from ming import schema as S
from ming.orm import session, FieldProperty
from ming.orm.declarative import MappedClass
+from allura.lib.helpers import log_output
from .session import task_orm_session
log = logging.getLogger(__name__)
@@ -251,7 +252,8 @@ class MonQTask(MappedClass):
if app_config:
c.app = c.project.app_instance(app_config)
c.user = M.User.query.get(_id=self.context.user_id)
- self.result = func(*self.args, **self.kwargs)
+ with log_output(log):
+ self.result = func(*self.args, **self.kwargs)
self.state = 'complete'
return self.result
except Exception, exc:
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/94cd1ede/Allura/allura/scripts/scripttask.py
----------------------------------------------------------------------
diff --git a/Allura/allura/scripts/scripttask.py b/Allura/allura/scripts/scripttask.py
index 8fa0984..b686838 100644
--- a/Allura/allura/scripts/scripttask.py
+++ b/Allura/allura/scripts/scripttask.py
@@ -55,13 +55,6 @@ from allura.lib.decorators import task
log = logging.getLogger(__name__)
-class Writer(object):
- def __init__(self, func):
- self.func = func
-
- def write(self, buf):
- self.func(buf)
-
class ScriptTask(object):
"""Base class for a command-line script that is also executable as a task."""
@@ -79,18 +72,10 @@ class ScriptTask(object):
@classmethod
def _execute_task(cls, arg_string):
try:
- _stdout = sys.stdout
- _stderr = sys.stderr
- sys.stdout = Writer(log.info)
- sys.stderr = Writer(log.error)
- try:
- options = cls.parser().parse_args(shlex.split(arg_string or ''))
- except SystemExit:
- raise Exception("Error parsing args: '%s'" % arg_string)
- cls.execute(options)
- finally:
- sys.stdout = _stdout
- sys.stderr = _stderr
+ options = cls.parser().parse_args(shlex.split(arg_string or ''))
+ except SystemExit:
+ raise Exception("Error parsing args: '%s'" % arg_string)
+ cls.execute(options)
@classmethod
def execute(cls, options):