fix some little issues. Rename gui to core, use logging lib instead of the...

fix some little issues. Rename gui to core, use logging lib instead of the custom debug option. Add a -d option
parent df6d2fc2
#!/usr/bin/env sh #!/usr/bin/env sh
cd src/ && python3 poezio.py "$@" python3 src/poezio.py "$@"
...@@ -51,16 +51,6 @@ ROOM_STATE_PRIVATE = 15 ...@@ -51,16 +51,6 @@ ROOM_STATE_PRIVATE = 15
ROOM_STATE_MESSAGE = 12 ROOM_STATE_MESSAGE = 12
ROOM_STATE_HL = 13 ROOM_STATE_HL = 13
def debug(string):
"""
Print a string in a file.
Useful since debuging cannot be displayed on screen because it's
a CLI software
"""
fdes = open("/tmp/debug", 'a')
fdes.write(string)
fdes.close()
def get_base64_from_file(path): def get_base64_from_file(path):
""" """
Convert the content of a file to base64 Convert the content of a file to base64
......
...@@ -137,13 +137,8 @@ if not path.isfile(CONFIG_PATH+'poezio.cfg'): ...@@ -137,13 +137,8 @@ if not path.isfile(CONFIG_PATH+'poezio.cfg'):
parser = OptionParser() parser = OptionParser()
parser.add_option("-f", "--file", dest="filename", default=CONFIG_PATH+'poezio.cfg', parser.add_option("-f", "--file", dest="filename", default=CONFIG_PATH+'poezio.cfg',
help="the config file you want to use", metavar="CONFIG_FILE") help="The config file you want to use", metavar="CONFIG_FILE")
parser.add_option("-d", "--debug", dest="debug",
help="The file where debug will be written", metavar="DEBUG_FILE")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
config = Config(options.filename) config = Config(options.filename)
if __name__ == '__main__':
# tests
import sys
(dummy, filename, section, option, value) = sys.argv
conf = Config(sys.argv[1])
conf.write_in_file(section, option, value)
...@@ -58,3 +58,6 @@ class Connection(sleekxmpp.ClientXMPP): ...@@ -58,3 +58,6 @@ class Connection(sleekxmpp.ClientXMPP):
else: else:
self.connect() self.connect()
self.process(threaded=True) self.process(threaded=True)
# Global connection object
connection = Connection()
...@@ -34,6 +34,7 @@ import common ...@@ -34,6 +34,7 @@ import common
import theme import theme
import multiuserchat as muc import multiuserchat as muc
from connection import connection
from handler import Handler from handler import Handler
from config import config from config import config
from tab import MucTab, InfoTab, PrivateTab, RosterInfoTab, ConversationTab from tab import MucTab, InfoTab, PrivateTab, RosterInfoTab, ConversationTab
...@@ -68,7 +69,7 @@ SHOW_NAME = { ...@@ -68,7 +69,7 @@ SHOW_NAME = {
resize_lock = threading.Lock() resize_lock = threading.Lock()
class Gui(object): class Core(object):
""" """
User interface using ncurses User interface using ncurses
""" """
...@@ -77,8 +78,8 @@ class Gui(object): ...@@ -77,8 +78,8 @@ class Gui(object):
self.stdscr = curses.initscr() self.stdscr = curses.initscr()
self.init_curses(self.stdscr) self.init_curses(self.stdscr)
self.xmpp = xmpp self.xmpp = xmpp
default_tab = InfoTab(self.stdscr, "Info") if self.xmpp.anon\ default_tab = InfoTab(self.stdscr, self, "Info") if self.xmpp.anon\
else RosterInfoTab(self.stdscr) else RosterInfoTab(self.stdscr, self)
default_tab.on_gain_focus() default_tab.on_gain_focus()
self.tabs = [default_tab] self.tabs = [default_tab]
# self.roster = Roster() # self.roster = Roster()
...@@ -159,7 +160,7 @@ class Gui(object): ...@@ -159,7 +160,7 @@ class Gui(object):
return return
self.information_win_size += 1 self.information_win_size += 1
for tab in self.tabs: for tab in self.tabs:
tab.on_info_win_size_changed(self.information_win_size, self.stdscr) tab.on_info_win_size_changed(self.stdscr)
self.refresh_window() self.refresh_window()
def shrink_information_win(self): def shrink_information_win(self):
...@@ -169,7 +170,7 @@ class Gui(object): ...@@ -169,7 +170,7 @@ class Gui(object):
return return
self.information_win_size -= 1 self.information_win_size -= 1
for tab in self.tabs: for tab in self.tabs:
tab.on_info_win_size_changed(self.information_win_size, self.stdscr) tab.on_info_win_size_changed(self.stdscr)
self.refresh_window() self.refresh_window()
def on_got_offline(self, presence): def on_got_offline(self, presence):
...@@ -639,7 +640,7 @@ class Gui(object): ...@@ -639,7 +640,7 @@ class Gui(object):
Open a new MucTab containing a muc Room, using the specified nick Open a new MucTab containing a muc Room, using the specified nick
""" """
r = Room(room, nick) r = Room(room, nick)
new_tab = MucTab(self.stdscr, r, self.information_win_size) new_tab = MucTab(self.stdscr, self, r)
if self.current_tab().nb == 0: if self.current_tab().nb == 0:
self.tabs.append(new_tab) self.tabs.append(new_tab)
else: else:
...@@ -738,7 +739,7 @@ class Gui(object): ...@@ -738,7 +739,7 @@ class Gui(object):
open a new conversation tab and focus it if needed open a new conversation tab and focus it if needed
""" """
r = Room(room_name, self.xmpp.boundjid.full) r = Room(room_name, self.xmpp.boundjid.full)
new_tab = ConversationTab(self.stdscr, r, self.information_win_size) new_tab = ConversationTab(self.stdscr, self, r)
# insert it in the rooms # insert it in the rooms
if self.current_tab().nb == 0: if self.current_tab().nb == 0:
self.tabs.append(new_tab) self.tabs.append(new_tab)
...@@ -766,7 +767,7 @@ class Gui(object): ...@@ -766,7 +767,7 @@ class Gui(object):
return None return None
own_nick = room.own_nick own_nick = room.own_nick
r = Room(complete_jid, own_nick) # PrivateRoom here r = Room(complete_jid, own_nick) # PrivateRoom here
new_tab = PrivateTab(self.stdscr, r, self.information_win_size) new_tab = PrivateTab(self.stdscr, self, r)
# insert it in the tabs # insert it in the tabs
if self.current_tab().nb == 0: if self.current_tab().nb == 0:
self.tabs.append(new_tab) self.tabs.append(new_tab)
...@@ -1391,3 +1392,7 @@ class Gui(object): ...@@ -1391,3 +1392,7 @@ class Gui(object):
def doupdate(self): def doupdate(self):
self.current_tab().just_before_refresh() self.current_tab().just_before_refresh()
curses.doupdate() curses.doupdate()
# # global core object
core = Core(connection)
...@@ -45,8 +45,7 @@ def change_show(xmpp, jid, own_nick, show, status): ...@@ -45,8 +45,7 @@ def change_show(xmpp, jid, own_nick, show, status):
""" """
Change our 'Show' Change our 'Show'
""" """
pres = xmpp.makePresence(pto='%s/%s' % (jid, own_nick), pres = xmpp.makePresence(pto='%s/%s' % (jid, own_nick))
pfrom=xmpp.boundjid.full)
if show: # if show is None, don't put a <show /> tag. It means "online" if show: # if show is None, don't put a <show /> tag. It means "online"
pres['type'] = show pres['type'] = show
if status: if status:
...@@ -60,15 +59,13 @@ def change_subject(xmpp, jid, subject): ...@@ -60,15 +59,13 @@ def change_subject(xmpp, jid, subject):
msg = xmpp.makeMessage(jid) msg = xmpp.makeMessage(jid)
msg['type'] = 'groupchat' msg['type'] = 'groupchat'
msg['subject'] = subject msg['subject'] = subject
msg['from'] = xmpp.boundjid.bare
msg.send() msg.send()
def change_nick(xmpp, jid, nick): def change_nick(xmpp, jid, nick):
""" """
Change our own nick in a room Change our own nick in a room
""" """
xmpp.makePresence(pto='%s/%s' % (jid, nick), xmpp.makePresence(pto='%s/%s' % (jid, nick)).send()
pfrom=xmpp.boundjid.bare).send()
def join_groupchat(xmpp, jid, nick, passwd=''): def join_groupchat(xmpp, jid, nick, passwd=''):
""" """
......
...@@ -21,14 +21,32 @@ Starting point of poezio. Launches both the Connection and Gui ...@@ -21,14 +21,32 @@ Starting point of poezio. Launches both the Connection and Gui
""" """
import os import os
# chdir in the source directory, to import the modules
# also, no need to use a sh script to "cd" in this directoy
# before launching poezio.
os.chdir(os.path.dirname(os.path.abspath(__file__)))
import curses import curses
import sys import sys
import traceback import traceback
import threading
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
def installThreadExcepthook():
"""
Workaround for sys.excepthook thread bug
See http://bugs.python.org/issue1230540
Python, you made me sad :(
"""
init_old = threading.Thread.__init__
def init(self, *args, **kwargs):
init_old(self, *args, **kwargs)
run_old = self.run
def run_with_except_hook(*args, **kw):
try:
run_old(*args, **kw)
except (KeyboardInterrupt, SystemExit):
raise
except:
sys.excepthook(*sys.exc_info())
self.run = run_with_except_hook
threading.Thread.__init__ = init
class MyStdErr(object): class MyStdErr(object):
def __init__(self, fd): def __init__(self, fd):
...@@ -67,23 +85,15 @@ def exception_handler(type_, value, trace): ...@@ -67,23 +85,15 @@ def exception_handler(type_, value, trace):
# sys.excepthook = exception_handler # sys.excepthook = exception_handler
import signal import signal
import logging
from connection import Connection from connection import connection
from config import config from config import config, options
from gui import Gui from core import core
signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c
def main():
"""
The main function consist of the Connection initialization
then the gui (ncurses) init, connection handlers and then the
connection is "started"
"""
xmpp = Connection() # Connection init
gui = Gui(xmpp) # Gui init.
xmpp.start() # Connect to remote server
gui.main_loop() # Refresh the screen, wait for user events etc
if __name__ == '__main__': if __name__ == '__main__':
main() signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c
if options.debug:
logging.basicConfig(filename=options.debug,level=logging.DEBUG)
connection.start() # Connect to remote server
core.main_loop() # Refresh the screen, wait for user events etc
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment