"""
-__version__ = "0.1.0"
-__revision__ = "$Id: obexftp,v 1.2 2004/06/13 18:49:25 phd Exp $"
-__date__ = "$Date: 2004/06/13 18:49:25 $"[7:-2]
+__version__ = "0.2.0"
+__revision__ = "$Id: obexftp,v 1.3 2004/06/13 19:41:52 phd Exp $"
+__date__ = "$Date: 2004/06/13 19:41:52 $"[7:-2]
__author__ = "Oleg Broytmann <phd@phd.pp.ru>"
__copyright__ = "Copyright (C) 2004 PhiloSoft Design"
obexftp_prog = "/usr/local/obex/bin/obexftp"
-import sys, os, time
+import sys, time
+import os, shutil
import xml.dom.minidom
+from tempfile import mkdtemp
+
def log_error(msg):
sys.stderr.write(msg + '\n')
return entries
-def _recursive_list(obexftp_args, directory):
+def recursive_list(obexftp_args, directory):
"""List the directory recursively"""
debug = open("debug", 'a')
for i in range(3):
for entry in directories:
fullpath = "%s/%s" % (directory, entry.name)
if fullpath.startswith('//'): fullpath = fullpath[1:]
- _recursive_list(obexftp_args, fullpath)
+ recursive_list(obexftp_args, fullpath)
def mcobex_list():
"""List the entire VFS"""
obexftp_args = setup_transport()
- _recursive_list(obexftp_args, '/')
+ recursive_list(obexftp_args, '/')
+
+
+# A unique directory for temporary files
+
+tmpdir_name = None
+
+def setup_tmpdir():
+ global tmpdir_name
+ tmpdir_name = mkdtemp(".tmp", "mcobex-")
+ os.chdir(tmpdir_name)
+
+def cleanup_tmpdir():
+ os.chdir(os.pardir)
+ shutil.rmtree(tmpdir_name)
def mcobex_copyout():
dummy_filename = sys.argv[3]
real_filename = sys.argv[4]
- real_file = open(real_filename, 'w')
- real_file.write("Copied from %s\n" % dummy_filename)
- real_file.write("Copied to %s\n" % real_filename)
- real_file.close()
+ setup_tmpdir()
+ os.system("%s %s -g '%s' 2>/dev/null" % (obexftp_prog, obexftp_args, dummy_filename))
+ os.rename(os.path.basename(dummy_filename), real_filename)
+ cleanup_tmpdir()
def mcobex_copyin():