]> git.phdru.name Git - extfs.d.git/blobdiff - obexftp
Version 1.2.1 (2004-10-03). Put error logfile in the same directory as the transport...
[extfs.d.git] / obexftp
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():