summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.py12
-rw-r--r--src/connection.py2
-rw-r--r--src/poezio.py41
3 files changed, 34 insertions, 21 deletions
diff --git a/src/common.py b/src/common.py
index 9c7d31a3..d5851bed 100644
--- a/src/common.py
+++ b/src/common.py
@@ -33,13 +33,13 @@
"""
various useful functions
"""
+
import base64
import os
import mimetypes
import hashlib
import subprocess
import curses
-import traceback
import sys
import select
import errno
@@ -54,16 +54,6 @@ def debug(string):
fdes.write(string)
fdes.close()
-def exception_handler(type_, value, trace):
- """
- on any traceback: exit ncurses and print the traceback
- then exit the program
- """
- curses.endwin()
- curses.echo()
- traceback.print_exception(type_, value, trace, None, sys.stderr)
- sys.exit(2)
-
def get_base64_from_file(path):
"""
Convert the content of a file to base64
diff --git a/src/connection.py b/src/connection.py
index 8ac8fc21..3b4e6e21 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -30,7 +30,6 @@ import xmpp
from config import config
from logging import logger
from handler import Handler
-from common import exception_handler
import threading
class Connection(threading.Thread):
@@ -57,7 +56,6 @@ class Connection(threading.Thread):
run in a thread
connect to server
"""
- sys.excepthook = exception_handler
if not self.connect_to_server(self.server, self.port):
self.handler.emit('error', msg='Could not connect to server')
sys.exit(-1)
diff --git a/src/poezio.py b/src/poezio.py
index e2e6fd99..501ccfd2 100644
--- a/src/poezio.py
+++ b/src/poezio.py
@@ -21,25 +21,50 @@
Starting point of poezio. Launches both the Connection and Gui
"""
import sys
+import traceback
+import curses
-# disable any printout (this would mess the display)
-if len(sys.argv) == 2:
- sys.stderr = open('errors', 'a')
-else:
- sys.stderr = open('/dev/null', 'a')
+class MyStdErr(object):
+ def __init__(self, fd):
+ """
+ Change sys.stderr to something like /dev/null
+ to disable any printout on the screen that would
+ mess everything
+ """
+ self.old_stderr = sys.stderr
+ sys.stderr = fd
+ def restaure(self):
+ """
+ Restaure the good ol' sys.stderr, because we need
+ it in order to print the tracebacks
+ """
+ sys.stderr = self.old_stderr
+
+my_stderr = MyStdErr(open('/dev/null', 'a'))
+
+def exception_handler(type_, value, trace):
+ """
+ on any traceback: exit ncurses and print the traceback
+ then exit the program
+ """
+ global my_stderr
+ my_stderr.restaure()
+ curses.endwin()
+ curses.echo()
+ traceback.print_exception(type_, value, trace, None, sys.stderr)
+ sys.exit(2)
+
+sys.excepthook = exception_handler
from connection import Connection
from multiuserchat import MultiUserChat
from config import config
from gui import Gui
from curses import initscr
-from common import exception_handler
import signal
signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c
-sys.excepthook = exception_handler
-
def main():
"""
main function