do not fail if ~/.gajim is file or ~/.gajim/logs is file. also use os.path.join() for / to become \ for 9x until now I think we have been failing
This commit is contained in:
parent
e98a0d8846
commit
47eb596780
|
@ -1,8 +1,9 @@
|
||||||
## plugins/logger.py
|
## logger.py
|
||||||
##
|
##
|
||||||
## Gajim Team:
|
## Gajim Team:
|
||||||
## - Yann Le Boulanger <asterix@lagaule.org>
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
||||||
## - Vincent Hanquez <tab@snarc.org>
|
## - Vincent Hanquez <tab@snarc.org>
|
||||||
|
## - Nikos Kouremenos <kourem@gmail.com>
|
||||||
##
|
##
|
||||||
## Copyright (C) 2003-2005 Gajim Team
|
## Copyright (C) 2003-2005 Gajim Team
|
||||||
##
|
##
|
||||||
|
@ -17,25 +18,31 @@
|
||||||
##
|
##
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import common.gajim
|
import common.gajim
|
||||||
from common import i18n
|
from common import i18n
|
||||||
LOGPATH = os.path.expanduser('~/.gajim/logs/')
|
LOGPATH = os.path.expanduser('~/.gajim/logs')
|
||||||
_ = i18n._
|
_ = i18n._
|
||||||
|
|
||||||
class Logger:
|
class Logger:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
#create ~/.gajim/logs/ if it doesn't exist
|
dot_gajim = os.path.expanduser('~/.gajim')
|
||||||
try:
|
if os.path.isfile(dot_gajim):
|
||||||
os.stat(os.path.expanduser('~/.gajim'))
|
print '~/.gajim is file but it should be a directory'
|
||||||
except OSError:
|
print 'Gajim will now exit'
|
||||||
|
sys.exit()
|
||||||
|
if os.path.isdir(dot_gajim):
|
||||||
|
if os.path.isfile(LOGPATH):
|
||||||
|
print '~/.gajim/logs is file but it should be a directory'
|
||||||
|
print 'Gajim will now exit'
|
||||||
|
sys.exit()
|
||||||
|
else: #create ~/.gajim/logs/ if it doesn't exist
|
||||||
os.mkdir(os.path.expanduser('~/.gajim'))
|
os.mkdir(os.path.expanduser('~/.gajim'))
|
||||||
print 'creating ~/.gajim/'
|
print 'creating ~/.gajim directory'
|
||||||
try:
|
|
||||||
os.stat(LOGPATH)
|
|
||||||
except OSError:
|
|
||||||
os.mkdir(LOGPATH)
|
os.mkdir(LOGPATH)
|
||||||
print 'creating ~/.gajim/logs/'
|
print 'creating ~/.gajim/logs directory'
|
||||||
|
|
||||||
|
|
||||||
def write(self, kind, msg, jid, show = None, tim = None):
|
def write(self, kind, msg, jid, show = None, tim = None):
|
||||||
if not tim:
|
if not tim:
|
||||||
|
@ -74,7 +81,8 @@ class Logger:
|
||||||
nick = jids[1]
|
nick = jids[1]
|
||||||
show = nick
|
show = nick
|
||||||
for f in files:
|
for f in files:
|
||||||
fic = open(LOGPATH + f, 'a')
|
path_to_file = os.path.join(LOGPATH, f)
|
||||||
|
fic = open(path_to_file, 'a')
|
||||||
fic.write('%s:%s:%s' % (tim, jid, show))
|
fic.write('%s:%s:%s' % (tim, jid, show))
|
||||||
if msg:
|
if msg:
|
||||||
fic.write(':' + msg)
|
fic.write(':' + msg)
|
||||||
|
@ -82,7 +90,8 @@ class Logger:
|
||||||
fic.close()
|
fic.close()
|
||||||
|
|
||||||
def get_nb_line(self, jid):
|
def get_nb_line(self, jid):
|
||||||
fic = open(LOGPATH + jid.split('/')[0], 'r')
|
path_to_file = os.path.join(LOGPATH, jid.split('/')[0])
|
||||||
|
fic = open(path_to_file, 'r')
|
||||||
nb = 0
|
nb = 0
|
||||||
while (fic.readline()):
|
while (fic.readline()):
|
||||||
nb += 1
|
nb += 1
|
||||||
|
@ -90,7 +99,8 @@ class Logger:
|
||||||
return nb
|
return nb
|
||||||
|
|
||||||
def read(self, jid, begin_line, end_line):
|
def read(self, jid, begin_line, end_line):
|
||||||
fic = open(LOGPATH + jid.split('/')[0], 'r')
|
path_to_file = os.path.join(LOGPATH, jid.split('/')[0])
|
||||||
|
fic = open(path_to_file, 'r')
|
||||||
nb = 0
|
nb = 0
|
||||||
lines = []
|
lines = []
|
||||||
while (nb < begin_line and fic.readline()):
|
while (nb < begin_line and fic.readline()):
|
||||||
|
|
Loading…
Reference in New Issue