]> git.phdru.name Git - extfs.d.git/commitdiff
Temporary directory. CopyOut (get a file from the phone).
authorOleg Broytman <phd@phdru.name>
Sun, 13 Jun 2004 19:41:52 +0000 (19:41 +0000)
committerOleg Broytman <phd@phdru.name>
Sun, 13 Jun 2004 19:41:52 +0000 (19:41 +0000)
git-svn-id: file:///home/phd/archive/SVN/mc-extfs/trunk@11 1a6e6372-1aea-0310-bd00-dc960550e1df

obexftp

diff --git a/obexftp b/obexftp
index a8ad677a9572cddc78732e1128b7dd6b87b64dfb..a0b9a4d8e69beba1301043dd692daade451ce470 100755 (executable)
--- a/obexftp
+++ b/obexftp
@@ -37,9 +37,9 @@ make the scanning process faster. Midnight Commander caches the result.
 
 """
 
-__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"
 
@@ -48,8 +48,11 @@ __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')
@@ -137,7 +140,7 @@ def get_entries(dom, tag):
    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):
@@ -178,12 +181,26 @@ def _recursive_list(obexftp_args, directory):
    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():
@@ -192,10 +209,10 @@ 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():