This works for me on Linux, posting to thg-dev so others can try
it out.
# HG changeset patch
# User Steve Borho <st...@borho.org>
# Date 1247115434 18000
# Node ID 76aeafb8f006afc9bc685d7690b2cc2638889a75
# Parent 3df3ae6199d55d896c41da5d843eef06b7cbed12
synch: redirect stdout file descriptor to capture hook output
This works for me on Linux, posting to thg-dev so others can try
it out.
diff -r 3df3ae6199d5 -r 76aeafb8f006 hggtk/synch.py
--- a/hggtk/synch.py Wed Jul 08 11:55:35 2009 -0500
+++ b/hggtk/synch.py Wed Jul 08 23:57:14 2009 -0500
@@ -11,6 +11,7 @@
import Queue
import os
import sys
+import threading
import urllib
from mercurial import hg, ui, extensions, url
@@ -35,12 +36,11 @@
self.last_drop_time = None
self.lastcmd = []
- self.saved_stdout = sys.stdout
- self.saved_stderr = sys.stderr
- if os.name == 'nt':
- # Pipe stderr, stdout to self.write
- sys.stdout = self
- sys.stderr = self
+ # Replace stdout file descriptor with our own pipe
+ self.oldstdout = os.dup(sys.__stdout__.fileno())
+ self.stdoutq = Queue.Queue()
+ self.readfd, writefd = os.pipe()
+ os.dup2(writefd, sys.__stdout__.fileno())
# persistent app data
self._settings = settings.Settings('synch')
@@ -254,7 +254,20 @@
self.load_settings()
self.update_pull_setting()
- gobject.idle_add(self.update_buttons)
+ gobject.idle_add(self.finalize_startup)
+
+ def finalize_startup(self, *args):
+ self.update_buttons()
+ def pollstdout(*args):
+ while True:
+ # blocking read of stdout pipe
+ o = os.read(self.readfd, 1024)
+ if o:
+ self.stdoutq.put(o)
+ else:
+ break
+ thread = threading.Thread(target=pollstdout, args=[])
+ thread.start()
def update_pull_setting(self):
ppull = self.repo.ui.config('tortoisehg', 'postpull', 'None')
@@ -287,7 +300,7 @@
elif not os.path.isdir(path) and path.endswith('.hg'):
self.pathtext.set_text(hglib.toutf(path))
- def update_buttons(self, *args):
+ def update_buttons(self):
self.buttonhbox.hide()
try:
# open a new repo, rebase can confuse cached repo
@@ -376,8 +389,8 @@
else:
self.update_settings()
self._settings.write()
- sys.stdout = self.saved_stdout
- sys.stderr = self.saved_stderr
+ os.dup2(self.oldstdout, sys.__stdout__.fileno())
+ os.close(self.oldstdout)
return False
def delete(self, widget, event):
@@ -596,6 +609,12 @@
self.write_err(msg)
except Queue.Empty:
pass
+ while self.stdoutq.qsize():
+ try:
+ msg = self.stdoutq.get(0)
+ self.write_err(msg)
+ except Queue.Empty:
+ pass
if self.cmd_running():
return True
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Tortoisehg-develop mailing list
Tortoisehg-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop