new helpers.check_paths() function that creates LOGPATH and VCARDPATH
This commit is contained in:
		
							parent
							
								
									b69bc501ae
								
							
						
					
					
						commit
						b4d9a6aab0
					
				
					 4 changed files with 76 additions and 51 deletions
				
			
		| 
						 | 
					@ -18,6 +18,7 @@
 | 
				
			||||||
##
 | 
					##
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import mutex
 | 
					import mutex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,6 +39,23 @@ log.addHandler(h)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
logger = common.logger.Logger()
 | 
					logger = common.logger.Logger()
 | 
				
			||||||
DATA_DIR = '../data'
 | 
					DATA_DIR = '../data'
 | 
				
			||||||
 | 
					LOGPATH = os.path.expanduser('~/.gajim/logs')
 | 
				
			||||||
 | 
					VCARDPATH = os.path.expanduser('~/.gajim/vcards')
 | 
				
			||||||
 | 
					if os.name == 'nt':
 | 
				
			||||||
 | 
						try:
 | 
				
			||||||
 | 
							# Documents and Settings\[User Name]\Application Data\Gajim\logs
 | 
				
			||||||
 | 
							LOGPATH = os.environ['appdata'] + '/Gajim/Logs'
 | 
				
			||||||
 | 
							VCARDPATH = os.environ['appdata'] + '/Gajim/Vcards'
 | 
				
			||||||
 | 
						except KeyError:
 | 
				
			||||||
 | 
							# win9x, ./logs
 | 
				
			||||||
 | 
							LOGPATH = 'Logs'
 | 
				
			||||||
 | 
							LOGPATH = 'Vcards'
 | 
				
			||||||
 | 
					try:
 | 
				
			||||||
 | 
						LOGPATH = LOGPATH.decode(sys.getfilesystemencoding())
 | 
				
			||||||
 | 
						VCARDPATH = VCARDPATH.decode(sys.getfilesystemencoding())
 | 
				
			||||||
 | 
					except:
 | 
				
			||||||
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LANG = os.getenv('LANG') # en_US, fr_FR, el_GR etc..
 | 
					LANG = os.getenv('LANG') # en_US, fr_FR, el_GR etc..
 | 
				
			||||||
if LANG:
 | 
					if LANG:
 | 
				
			||||||
	LANG = LANG[:2] # en, fr, el etc..
 | 
						LANG = LANG[:2] # en, fr, el etc..
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,8 @@ import sre
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import urllib
 | 
					import urllib
 | 
				
			||||||
import errno
 | 
					import errno
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					import stat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import gajim
 | 
					import gajim
 | 
				
			||||||
from common import i18n
 | 
					from common import i18n
 | 
				
			||||||
| 
						 | 
					@ -43,6 +45,52 @@ def temp_failure_retry(func, *args, **kwargs):
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                raise
 | 
					                raise
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def check_paths():
 | 
				
			||||||
 | 
						LOGPATH = gajim.LOGPATH
 | 
				
			||||||
 | 
						VCARDPATH = gajim.VCARDPATH
 | 
				
			||||||
 | 
						dot_gajim = os.path.dirname(LOGPATH)
 | 
				
			||||||
 | 
						if os.path.isfile(dot_gajim):
 | 
				
			||||||
 | 
							print _('%s is file but it should be a directory') % dot_gajim
 | 
				
			||||||
 | 
							print _('Gajim will now exit')
 | 
				
			||||||
 | 
							sys.exit()
 | 
				
			||||||
 | 
						elif os.path.isdir(dot_gajim):
 | 
				
			||||||
 | 
							s = os.stat(dot_gajim)
 | 
				
			||||||
 | 
							if s.st_mode & stat.S_IROTH: # others have read permission!
 | 
				
			||||||
 | 
								os.chmod(dot_gajim, 0700) # rwx------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if not os.path.exists(LOGPATH):
 | 
				
			||||||
 | 
								print _('creating %s directory') % LOGPATH
 | 
				
			||||||
 | 
								os.mkdir(LOGPATH, 0700)
 | 
				
			||||||
 | 
							elif os.path.isfile(LOGPATH):
 | 
				
			||||||
 | 
								print _('%s is file but it should be a directory') % LOGPATH
 | 
				
			||||||
 | 
								print _('Gajim will now exit')
 | 
				
			||||||
 | 
								sys.exit()
 | 
				
			||||||
 | 
							elif os.path.isdir(LOGPATH):
 | 
				
			||||||
 | 
									s = os.stat(LOGPATH)
 | 
				
			||||||
 | 
									if s.st_mode & stat.S_IROTH: # others have read permission!
 | 
				
			||||||
 | 
										os.chmod(LOGPATH, 0700) # rwx------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if not os.path.exists(VCARDPATH):
 | 
				
			||||||
 | 
								print _('creating %s directory') % VCARDPATH
 | 
				
			||||||
 | 
								os.mkdir(VCARDPATH, 0700)
 | 
				
			||||||
 | 
							elif os.path.isfile(VCARDPATH):
 | 
				
			||||||
 | 
								print _('%s is file but it should be a directory') % VCARDPATH
 | 
				
			||||||
 | 
								print _('Gajim will now exit')
 | 
				
			||||||
 | 
								sys.exit()
 | 
				
			||||||
 | 
							elif os.path.isdir(VCARDPATH):
 | 
				
			||||||
 | 
									s = os.stat(VCARDPATH)
 | 
				
			||||||
 | 
									if s.st_mode & stat.S_IROTH: # others have read permission!
 | 
				
			||||||
 | 
										os.chmod(VCARDPATH, 0700) # rwx------
 | 
				
			||||||
 | 
						else: # dot_gajim doesn't exist
 | 
				
			||||||
 | 
							if dot_gajim: # is '' on win9x so avoid that
 | 
				
			||||||
 | 
								print _('creating %s directory') % dot_gajim
 | 
				
			||||||
 | 
								os.mkdir(dot_gajim, 0700)
 | 
				
			||||||
 | 
							if not os.path.isdir(LOGPATH):
 | 
				
			||||||
 | 
								print _('creating %s directory') % LOGPATH
 | 
				
			||||||
 | 
								os.mkdir(LOGPATH, 0700)
 | 
				
			||||||
 | 
							if not os.path.isdir(VCARDPATH):
 | 
				
			||||||
 | 
								print _('creating %s directory') % VCARDPATH
 | 
				
			||||||
 | 
								os.mkdir(VCARDPATH, 0700)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def convert_bytes(string):
 | 
					def convert_bytes(string):
 | 
				
			||||||
	suffix = ''
 | 
						suffix = ''
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,59 +18,17 @@
 | 
				
			||||||
##
 | 
					##
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import sys
 | 
					 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
import stat
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import common.gajim
 | 
					import common.gajim
 | 
				
			||||||
from common import i18n
 | 
					from common import i18n
 | 
				
			||||||
_ = i18n._
 | 
					_ = i18n._
 | 
				
			||||||
import helpers
 | 
					import helpers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LOGPATH = os.path.expanduser('~/.gajim/logs')
 | 
					 | 
				
			||||||
if os.name == 'nt':
 | 
					 | 
				
			||||||
	try:
 | 
					 | 
				
			||||||
		# Documents and Settings\[User Name]\Application Data\Gajim\logs
 | 
					 | 
				
			||||||
		LOGPATH = os.environ['appdata'] + '/Gajim/Logs'
 | 
					 | 
				
			||||||
	except KeyError:
 | 
					 | 
				
			||||||
		# win9x, ./logs
 | 
					 | 
				
			||||||
		LOGPATH = 'Logs'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
try:
 | 
					 | 
				
			||||||
	LOGPATH = LOGPATH.decode(sys.getfilesystemencoding())
 | 
					 | 
				
			||||||
except:
 | 
					 | 
				
			||||||
	pass
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Logger:
 | 
					class Logger:
 | 
				
			||||||
	def __init__(self):
 | 
						def __init__(self):
 | 
				
			||||||
		dot_gajim = os.path.dirname(LOGPATH)
 | 
							pass
 | 
				
			||||||
		if os.path.isfile(dot_gajim):
 | 
					 | 
				
			||||||
			print _('%s is file but it should be a directory') % dot_gajim
 | 
					 | 
				
			||||||
			print _('Gajim will now exit')
 | 
					 | 
				
			||||||
			sys.exit()
 | 
					 | 
				
			||||||
		elif os.path.isdir(dot_gajim):
 | 
					 | 
				
			||||||
			s = os.stat(dot_gajim)
 | 
					 | 
				
			||||||
			if s.st_mode & stat.S_IROTH: # others have read permission!
 | 
					 | 
				
			||||||
				os.chmod(dot_gajim, 0700) # rwx------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if not os.path.exists(LOGPATH):
 | 
					 | 
				
			||||||
				print _('creating %s directory') % LOGPATH
 | 
					 | 
				
			||||||
				os.mkdir(LOGPATH, 0700)
 | 
					 | 
				
			||||||
			elif os.path.isfile(LOGPATH):
 | 
					 | 
				
			||||||
				print _('%s is file but it should be a directory') % LOGPATH
 | 
					 | 
				
			||||||
				print _('Gajim will now exit')
 | 
					 | 
				
			||||||
				sys.exit()
 | 
					 | 
				
			||||||
			elif os.path.isdir(LOGPATH):
 | 
					 | 
				
			||||||
					s = os.stat(LOGPATH)
 | 
					 | 
				
			||||||
					if s.st_mode & stat.S_IROTH: # others have read permission!
 | 
					 | 
				
			||||||
						os.chmod(LOGPATH, 0700) # rwx------
 | 
					 | 
				
			||||||
		else: # dot_gajim doesn't exist
 | 
					 | 
				
			||||||
			if dot_gajim: # is '' on win9x so avoid that
 | 
					 | 
				
			||||||
				print _('creating %s directory') % dot_gajim
 | 
					 | 
				
			||||||
				os.mkdir(dot_gajim, 0700)
 | 
					 | 
				
			||||||
			if not os.path.isdir(LOGPATH):
 | 
					 | 
				
			||||||
				print _('creating %s directory') % LOGPATH
 | 
					 | 
				
			||||||
				os.mkdir(LOGPATH, 0700)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	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:
 | 
				
			||||||
| 
						 | 
					@ -92,7 +50,7 @@ class Logger:
 | 
				
			||||||
			if not show:
 | 
								if not show:
 | 
				
			||||||
				show = 'online'
 | 
									show = 'online'
 | 
				
			||||||
			if common.gajim.config.get('log_notif_in_user_file'):
 | 
								if common.gajim.config.get('log_notif_in_user_file'):
 | 
				
			||||||
				path_to_file = os.path.join(LOGPATH, ji)
 | 
									path_to_file = os.path.join(common.gajim.LOGPATH, ji)
 | 
				
			||||||
				if os.path.isdir(path_to_file):
 | 
									if os.path.isdir(path_to_file):
 | 
				
			||||||
					jid = 'gcstatus'
 | 
										jid = 'gcstatus'
 | 
				
			||||||
					msg = show + ':' + msg
 | 
										msg = show + ':' + msg
 | 
				
			||||||
| 
						 | 
					@ -105,7 +63,7 @@ class Logger:
 | 
				
			||||||
			if common.gajim.config.get('log_notif_in_sep_file'):
 | 
								if common.gajim.config.get('log_notif_in_sep_file'):
 | 
				
			||||||
				files.append('notify.log')
 | 
									files.append('notify.log')
 | 
				
			||||||
		elif kind == 'incoming': # we save time:recv:message
 | 
							elif kind == 'incoming': # we save time:recv:message
 | 
				
			||||||
			path_to_file = os.path.join(LOGPATH, ji)
 | 
								path_to_file = os.path.join(common.gajim.LOGPATH, ji)
 | 
				
			||||||
			if os.path.isdir(path_to_file):
 | 
								if os.path.isdir(path_to_file):
 | 
				
			||||||
				files.append(jid)
 | 
									files.append(jid)
 | 
				
			||||||
			else:
 | 
								else:
 | 
				
			||||||
| 
						 | 
					@ -114,7 +72,7 @@ class Logger:
 | 
				
			||||||
			show = msg
 | 
								show = msg
 | 
				
			||||||
			msg = ''
 | 
								msg = ''
 | 
				
			||||||
		elif kind == 'outgoing': # we save time:sent:message
 | 
							elif kind == 'outgoing': # we save time:sent:message
 | 
				
			||||||
			path_to_file = os.path.join(LOGPATH, ji)
 | 
								path_to_file = os.path.join(common.gajim.LOGPATH, ji)
 | 
				
			||||||
			if os.path.isdir(path_to_file):
 | 
								if os.path.isdir(path_to_file):
 | 
				
			||||||
				files.append(jid)
 | 
									files.append(jid)
 | 
				
			||||||
			else:
 | 
								else:
 | 
				
			||||||
| 
						 | 
					@ -124,7 +82,7 @@ class Logger:
 | 
				
			||||||
			msg = ''
 | 
								msg = ''
 | 
				
			||||||
		elif kind == 'gc': # we save time:gc:nick:message
 | 
							elif kind == 'gc': # we save time:gc:nick:message
 | 
				
			||||||
			# create the folder if needed
 | 
								# create the folder if needed
 | 
				
			||||||
			ji_fn = os.path.join(LOGPATH, ji)
 | 
								ji_fn = os.path.join(common.gajim.LOGPATH, ji)
 | 
				
			||||||
			if os.path.isfile(ji_fn):
 | 
								if os.path.isfile(ji_fn):
 | 
				
			||||||
				os.remove(ji_fn)
 | 
									os.remove(ji_fn)
 | 
				
			||||||
			if not os.path.isdir(ji_fn):
 | 
								if not os.path.isdir(ji_fn):
 | 
				
			||||||
| 
						 | 
					@ -142,7 +100,7 @@ class Logger:
 | 
				
			||||||
		if msg and isinstance(msg, unicode):
 | 
							if msg and isinstance(msg, unicode):
 | 
				
			||||||
			msg = msg.encode('utf-8')
 | 
								msg = msg.encode('utf-8')
 | 
				
			||||||
		for f in files:
 | 
							for f in files:
 | 
				
			||||||
			path_to_file = os.path.join(LOGPATH, f)
 | 
								path_to_file = os.path.join(common.gajim.LOGPATH, f)
 | 
				
			||||||
			if os.path.isdir(path_to_file):
 | 
								if os.path.isdir(path_to_file):
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			# this does it rw-r-r by default but is in a dir with 700 so it's ok
 | 
								# this does it rw-r-r by default but is in a dir with 700 so it's ok
 | 
				
			||||||
| 
						 | 
					@ -155,12 +113,12 @@ class Logger:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def __get_path_to_file(self, fjid):
 | 
						def __get_path_to_file(self, fjid):
 | 
				
			||||||
		jid = fjid.split('/')[0]
 | 
							jid = fjid.split('/')[0]
 | 
				
			||||||
		path_to_file = os.path.join(LOGPATH, jid)
 | 
							path_to_file = os.path.join(common.gajim.LOGPATH, jid)
 | 
				
			||||||
		if os.path.isdir(path_to_file):
 | 
							if os.path.isdir(path_to_file):
 | 
				
			||||||
			if fjid == jid: # we want to read the gc history
 | 
								if fjid == jid: # we want to read the gc history
 | 
				
			||||||
				path_to_file = os.path.join(LOGPATH, jid + '/' + jid)
 | 
									path_to_file = os.path.join(common.gajim.LOGPATH, jid + '/' + jid)
 | 
				
			||||||
			else: #we want to read pm history
 | 
								else: #we want to read pm history
 | 
				
			||||||
				path_to_file = os.path.join(LOGPATH, fjid)
 | 
									path_to_file = os.path.join(common.gajim.LOGPATH, fjid)
 | 
				
			||||||
		return path_to_file
 | 
							return path_to_file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def get_no_of_lines(self, fjid):
 | 
						def get_no_of_lines(self, fjid):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1224,6 +1224,7 @@ class Interface:
 | 
				
			||||||
			self.remote = None
 | 
								self.remote = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def __init__(self):
 | 
						def __init__(self):
 | 
				
			||||||
 | 
							helpers.check_paths()
 | 
				
			||||||
		gajim.interface = self
 | 
							gajim.interface = self
 | 
				
			||||||
		self.default_values = {
 | 
							self.default_values = {
 | 
				
			||||||
			'inmsgcolor': gajim.config.get('inmsgcolor'),
 | 
								'inmsgcolor': gajim.config.get('inmsgcolor'),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue