]> git.phdru.name Git - extfs.d.git/commitdiff
Version 1.2.1 (2004-10-03). Put error logfile in the same directory as the transport...
authorOleg Broytman <phd@phdru.name>
Sun, 3 Oct 2004 13:33:03 +0000 (13:33 +0000)
committerOleg Broytman <phd@phdru.name>
Sun, 3 Oct 2004 13:33:03 +0000 (13:33 +0000)
If the directory or the file is not writeable - try to put the logfile in a temporary directory, usually /tmp.

git-svn-id: file:///home/phd/archive/SVN/mc-extfs/trunk@32 1a6e6372-1aea-0310-bd00-dc960550e1df

obexftp
obexftp-ANNOUNCE

diff --git a/obexftp b/obexftp
index 6d8f72ab389b17df4ba36856ee99ddac719ff546..fb183553744999328456220f9e64134296ee8424 100755 (executable)
--- a/obexftp
+++ b/obexftp
@@ -60,13 +60,15 @@ Commander shows the same cached VFS image. Exit Midnight Commander and
 restart it.
 
 If something goes wrong set the logging level (see setLevel() below) to INFO
 restart it.
 
 If something goes wrong set the logging level (see setLevel() below) to INFO
-or DEBUG and look in the obexftp-mcextfs.log file(s).
-
+or DEBUG and look in the obexftp-mcextfs.log file. The file is put in the same
+directory as the transport file, if it possible; if not the file will be put
+into a temporary directory, usually /tmp, or /var/tmp, or whatever directory
+is named in $TMP environment variable.
 """
 
 """
 
-__version__ = "1.2.0"
-__revision__ = "$Id: obexftp,v 1.17 2004/09/25 16:13:39 phd Exp $"
-__date__ = "$Date: 2004/09/25 16:13:39 $"[7:-2]
+__version__ = "1.2.1"
+__revision__ = "$Id: obexftp,v 1.18 2004/10/03 13:33:03 phd Exp $"
+__date__ = "$Date: 2004/10/03 13:33:03 $"[7:-2]
 __author__ = "Oleg Broytmann <phd@phd.pp.ru>"
 __copyright__ = "Copyright (C) 2004 PhiloSoft Design"
 
 __author__ = "Oleg Broytmann <phd@phd.pp.ru>"
 __copyright__ = "Copyright (C) 2004 PhiloSoft Design"
 
@@ -75,29 +77,55 @@ __copyright__ = "Copyright (C) 2004 PhiloSoft Design"
 obexftp_prog = "/usr/local/obex/bin/obexftp"
 
 
 obexftp_prog = "/usr/local/obex/bin/obexftp"
 
 
-import sys, time
-import os, shutil
+import sys, os, shutil
+from time import sleep
 import xml.dom.minidom
 import xml.dom.minidom
-from tempfile import mkstemp, mkdtemp
+from tempfile import mkstemp, mkdtemp, _candidate_tempdir_list
 
 
 import logging
 logger = logging.getLogger('obexftp-mcextfs')
 
 
 import logging
 logger = logging.getLogger('obexftp-mcextfs')
-logger.addHandler(logging.FileHandler('obexftp-mcextfs.log'))
+log_err_handler = logging.StreamHandler(sys.stderr)
+logger.addHandler(log_err_handler)
 logger.setLevel(logging.ERROR)
 
 
 logger.setLevel(logging.ERROR)
 
 
-if len(sys.argv) < 2:
+if len(sys.argv) < 3:
    logger.error("""\
 ObexFTP Virtual FileSystem for Midnight Commander version %s
 Author: %s
 %s
    logger.error("""\
 ObexFTP Virtual FileSystem for Midnight Commander version %s
 Author: %s
 %s
+
+This is not a program. It is ObexFTP Virtual FileSystem for Midnight Commander.
 Put it in /usr/lib/mc/extfs. For more information read the source!""",
    __version__, __author__, __copyright__
 )
    sys.exit(1)
 
 
 Put it in /usr/lib/mc/extfs. For more information read the source!""",
    __version__, __author__, __copyright__
 )
    sys.exit(1)
 
 
+tempdirlist = _candidate_tempdir_list()
+tempdirlist.insert(0, os.path.abspath(os.path.dirname(sys.argv[2])))
+
+found = False
+for tempdir in tempdirlist:
+   try:
+      logfile_name = os.path.join(tempdir, 'obexftp-mcextfs.log')
+      logfile = open(logfile_name, 'w')
+   except IOError:
+      pass
+   else:
+      found = True
+      logfile.close()
+      break
+
+if not found:
+   logger.error("Cannot initialize error log file in directories %s" % str(tempdirlist))
+   sys.exit(1)
+
+logger.removeHandler(log_err_handler)
+logger.addHandler(logging.FileHandler(logfile_name))
+
+
 # Parse ObexFTP XML directory listings
 
 class DirectoryEntry(object):
 # Parse ObexFTP XML directory listings
 
 class DirectoryEntry(object):
@@ -216,7 +244,7 @@ def recursive_list(directory='/'):
    for entry in directories:
       fullpath = "%s/%s" % (directory, entry.name)
       if fullpath.startswith('//'): fullpath = fullpath[1:]
    for entry in directories:
       fullpath = "%s/%s" % (directory, entry.name)
       if fullpath.startswith('//'): fullpath = fullpath[1:]
-      time.sleep(1)
+      sleep(1)
       recursive_list(fullpath)
 
 def mcobex_list():
       recursive_list(fullpath)
 
 def mcobex_list():
index bba60541e2441f56be2a18e1a19f176919f2b559..ff943f5086bc3b58bb3c0d66b1c5108a04e54215 100644 (file)
@@ -6,6 +6,12 @@ WHAT IS IT
 binary.
 
 
 binary.
 
 
+WHAT'S NEW in version 1.2.1 (2004-10-03)
+   Put error logfile in the same directory as the transport file. If the
+directory or the file is not writeable - try to put the logfile in a temporary
+directory, usually /tmp.
+
+
 WHAT'S NEW in version 1.2.0 (2004-09-27)
    Fixed a major bug with blocked read from a pipe. Many thanks to
 Marius Konitzer <m.konitzer@gmx.de> for reporting the bug. Now I use files
 WHAT'S NEW in version 1.2.0 (2004-09-27)
    Fixed a major bug with blocked read from a pipe. Many thanks to
 Marius Konitzer <m.konitzer@gmx.de> for reporting the bug. Now I use files