]> git.phdru.name Git - extfs.d.git/blobdiff - obexftp
Refactor collection of text and comments nodes
[extfs.d.git] / obexftp
diff --git a/obexftp b/obexftp
index a5ef805791972a3074f3c6fb8cb8805b95e3bb87..2eb18849f69aa8401d500b77f2d8917226db2aec 100755 (executable)
--- a/obexftp
+++ b/obexftp
@@ -1,5 +1,4 @@
 #! /usr/bin/env python
 #! /usr/bin/env python
-
 """ObexFTP Virtual FileSystem for Midnight Commander
 
 Manipulate a cell phone's filesystem calling obexftp binary. This is a complete
 """ObexFTP Virtual FileSystem for Midnight Commander
 
 Manipulate a cell phone's filesystem calling obexftp binary. This is a complete
@@ -9,15 +8,16 @@ undocumented "run"; anyway there are no runnable files in cell phones. The
 script is written in Python because I I need to parse XML directory listings
 from obexftp, and Python is the best of all languages suited for the task ;).
 
 script is written in Python because I I need to parse XML directory listings
 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
-ObexFTP 0.10.4+ (http://triq.net/obexftp).
+The script requires Midnight Commander 3.1+
+(http://www.midnight-commander.org/), Python 2.3+ (http://www.python.org/),
+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
 
 Edit the script, and correct the the full path to the obexftp binary (see
-obexftp_prog below). Put the script in the /usr/[local/][lib|share]/mc/extfs,
-and add a line "obexftp" to the /usr/[local/][lib|share]/mc/extfs/extfs.ini.
-Make the script executable.
+obexftp_prog below). For mc 4.7+ put the script in
+$HOME/[.local/share/].mc/extfs.d. For older versions put it in
+/usr/[local/][lib|share]/mc/extfs and add a line "obexftp" to the
+/usr/[local/][lib|share]/mc/extfs/extfs.ini. Make the script executable.
 
 Create somewhere a transport file. The transport file may have any name, and is
 expected to be a text file with at least one line defining the transport to
 
 Create somewhere a transport file. The transport file may have any name, and is
 expected to be a text file with at least one line defining the transport to
@@ -32,6 +32,8 @@ and "channel" is the OBEX File Transfer channel; you can discover the address
 and the channel for your device by using commands like "hcitool scan" and
 "sdptool browse".
 
 and the channel for your device by using commands like "hcitool scan" and
 "sdptool browse".
 
+For the USB put the interface number: "usb interface".
+
 For the TTY put the device name: "tty /dev/ttyUSB0".
 
 For the IrDA: just put "IrDA" in the file.
 For the TTY put the device name: "tty /dev/ttyUSB0".
 
 For the IrDA: just put "IrDA" in the file.
@@ -62,23 +64,46 @@ named in $TMP environment variable.
 
 """
 
 
 """
 
-__version__ = "1.2.4"
-__revision__ = "$Id$"
-__date__ = "$Date$"[7:-2]
-__author__ = "Oleg Broytman <phd@phd.pp.ru>"
-__copyright__ = "Copyright (C) 2004-2009 PhiloSoft Design"
+__version__ = "1.4.0"
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2004-2013 PhiloSoft Design"
 __license__ = "GPL"
 
 
 # Change this to suite your needs
 __license__ = "GPL"
 
 
 # Change this to suite your needs
-obexftp_prog = "/usr/local/obex/bin/obexftp"
+obexftp_prog = "/usr/bin/obexftp"
 
 
 import sys, os, shutil
 from time import sleep
 
 
 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
 
 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')
 
 import logging
 logger = logging.getLogger('obexftp-mcextfs')
@@ -93,8 +118,8 @@ ObexFTP Virtual FileSystem for Midnight Commander version %s
 Author: %s
 %s
 
 Author: %s
 %s
 
-This is not a program. Put the script in /usr/[local/][lib|share]/mc/extfs.
-For more information read the source!""",
+This is not a program. Put the script in $HOME/[.local/share/].mc/extfs.d or
+/usr/[local/][lib|share]/mc/extfs. For more information read the source!""",
    __version__, __author__, __copyright__
 )
    sys.exit(1)
    __version__, __author__, __copyright__
 )
    sys.exit(1)
@@ -123,7 +148,6 @@ logger.removeHandler(log_err_handler)
 logger.addHandler(logging.FileHandler(logfile_name))
 
 locale.setlocale(locale.LC_ALL, '')
 logger.addHandler(logging.FileHandler(logfile_name))
 
 locale.setlocale(locale.LC_ALL, '')
-charset = locale.getpreferredencoding()
 
 
 # Parse ObexFTP XML directory listings
 
 
 # Parse ObexFTP XML directory listings
@@ -238,7 +262,7 @@ def recursive_list(directory='/'):
 
    for entry in directories + files:
       fullpath = "%s/%s" % (directory, entry.name)
 
    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
 
       if fullpath.startswith('//'): fullpath = fullpath[1:]
       print entry.perm, "1 user group", entry.size, entry.mtime, fullpath
 
@@ -334,6 +358,12 @@ def setup_transport():
       elif len(parts) > 3:
          transport_error("too many arguments for 'bluetooth' transport")
       return ' '.join(["-b", parts[1], "-B", parts[2]])
       elif len(parts) > 3:
          transport_error("too many arguments for 'bluetooth' transport")
       return ' '.join(["-b", parts[1], "-B", parts[2]])
+   elif transport == "usb":
+      if len(parts) < 2:
+         transport_error("not enough arguments for 'usb' transport")
+      elif len(parts) > 2:
+         transport_error("too many arguments for 'usb' transport")
+      return ' '.join(["-u", parts[1]])
    elif transport == "tty":
       if len(parts) < 2:
          transport_error("not enough arguments for 'tty' transport")
    elif transport == "tty":
       if len(parts) < 2:
          transport_error("not enough arguments for 'tty' transport")