]> git.phdru.name Git - extfs.d.git/blobdiff - obexftp
XML VFS 0.2 - show attributes as a text file
[extfs.d.git] / obexftp
diff --git a/obexftp b/obexftp
index 4cad7b9a68e4bcf8497b3480898731c7eec9f219..211fbf74f9529f118fa3e3f45a67d6d7a404ec69 100755 (executable)
--- a/obexftp
+++ b/obexftp
@@ -10,7 +10,7 @@ from obexftp, and Python is the best of all languages suited for the task ;).
 
 The script requires Midnight Commander 3.1+ (http://www.ibiblio.org/mc/),
 Python 2.3+ (http://www.python.org/),
-OpenOBEX 1.0.1+ (http://openobex.sourceforge.net/) and
+OpenOBEX 1.0.1+ (http://dev.zuckschwerdt.org/openobex/) and
 ObexFTP 0.10.4+ (http://triq.net/obexftp).
 
 Edit the script, and correct the the full path to the obexftp binary (see
@@ -64,7 +64,7 @@ named in $TMP environment variable.
 
 """
 
-__version__ = "1.3.2"
+__version__ = "1.4.0"
 __author__ = "Oleg Broytman <phd@phdru.name>"
 __copyright__ = "Copyright (C) 2004-2013 PhiloSoft Design"
 __license__ = "GPL"
@@ -76,9 +76,34 @@ obexftp_prog = "/usr/bin/obexftp"
 
 import sys, os, shutil
 from time import sleep
-import xml.dom.minidom, locale
+import xml.dom.minidom
 from tempfile import mkstemp, mkdtemp, _candidate_tempdir_list
 
+try:
+   import locale
+   use_locale = True
+except ImportError:
+   use_locale = False
+
+if use_locale:
+   # Get the default charset.
+   try:
+      lcAll = locale.getdefaultlocale()
+   except locale.Error, err:
+      print >>sys.stderr, "WARNING:", err
+      lcAll = []
+
+   if len(lcAll) == 2:
+      default_encoding = lcAll[1]
+   else:
+      try:
+         default_encoding = locale.getpreferredencoding()
+      except locale.Error, err:
+         print >>sys.stderr, "WARNING:", err
+         default_encoding = sys.getdefaultencoding()
+else:
+   default_encoding = sys.getdefaultencoding()
+
 
 import logging
 logger = logging.getLogger('obexftp-mcextfs')
@@ -123,7 +148,6 @@ logger.removeHandler(log_err_handler)
 logger.addHandler(logging.FileHandler(logfile_name))
 
 locale.setlocale(locale.LC_ALL, '')
-charset = locale.getpreferredencoding()
 
 
 # Parse ObexFTP XML directory listings
@@ -238,7 +262,7 @@ def recursive_list(directory='/'):
 
    for entry in directories + files:
       fullpath = "%s/%s" % (directory, entry.name)
-      fullpath = fullpath.encode(charset)
+      fullpath = fullpath.encode(default_encoding)
       if fullpath.startswith('//'): fullpath = fullpath[1:]
       print entry.perm, "1 user group", entry.size, entry.mtime, fullpath