From 9edef14bc23b18e164c42b3a9bfa594355471245 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 13 Jun 2004 19:41:52 +0000 Subject: [PATCH] Temporary directory. CopyOut (get a file from the phone). git-svn-id: file:///home/phd/archive/SVN/mc-extfs/trunk@11 1a6e6372-1aea-0310-bd00-dc960550e1df --- obexftp | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/obexftp b/obexftp index a8ad677..a0b9a4d 100755 --- 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 " __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(): -- 2.39.2