Fix exceptions raise after quitting history view.

This commit is contained in:
Fatih Aşıcı
2009-12-21 09:07:32 +00:00
parent e34ffcadd9
commit fc877b2687
2 changed files with 38 additions and 5 deletions
+3
View File
@@ -1,3 +1,6 @@
2009-12-21 Fatih Aşıcı <fatih@pardus.org.tr>
* pisi/cli/history.py: Fix exceptions raise after quitting history view.
2009-12-16 Serdar Dalgıç <serdar@pardus.org.tr>
* pisi/cli/blame.py: Several enhancements in blame:
- pisi bl works for LC_ALL=C
+35 -5
View File
@@ -78,10 +78,41 @@ Lists previous operations.""")
print " *", pkg
print
def redirect_output(self):
def redirect_output(self, func):
if os.isatty(sys.stdout.fileno()):
output = os.popen("less","w")
sys.stdout = sys.stderr = output
class LessException(Exception):
pass
class LessPipe():
def __init__(self):
import subprocess
self.less = subprocess.Popen(["less", "-"],
stdin=subprocess.PIPE)
def __del__(self):
self.less.stdin.close()
self.less.wait()
def flush(self):
self.less.stdin.flush()
def write(self, s):
try:
self.less.stdin.write(s)
except IOError:
raise LessException
stdout, stderr = sys.stdout, sys.stderr
sys.stdout = sys.stderr = LessPipe()
try:
func()
except LessException:
pass
finally:
sys.stdout, sys.stderr = stdout, stderr
else:
func()
def run(self):
self.init(database = False, write = False)
@@ -95,5 +126,4 @@ Lists previous operations.""")
self.takeback(opno)
return
self.redirect_output()
self.print_history()
self.redirect_output(self.print_history)