From 6b97c26b362177717f46ac73f560d9e7801509e1 Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 1 Nov 2008 15:02:09 +1030 Subject: [PATCH] Check if file is on same partition, if so move it, if not copy it. --- autoPathTv.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/autoPathTv.py b/autoPathTv.py index 8d02ab8..dfb523a 100755 --- a/autoPathTv.py +++ b/autoPathTv.py @@ -158,6 +158,8 @@ def does_file_exist(path): file_exists = True return file_exists +def same_partition(f1, f2): + return os.stat(f1).st_dev == os.stat(f2).st_dev ########################### @@ -190,14 +192,23 @@ def main(): if file_exists: print "[!] File already exists, not copying" else: - print "[*] Copying file" - try: - shutil.copy(oldfile, newpath) - except Exception, errormsg: - print "[!] Error copying file! %s" % (errormsg) + if same_partition(oldfile, newpath): + print "[* Moving file]" + try: + shutil.rename(oldfile, newpath) + except: + print "[!] Error moving file! %s" % (errormsg) + #end try else: - print "[*] ..done" - #end try + print "[*] Copying file" + try: + shutil.copy(oldfile, newpath) + except Exception, errormsg: + print "[!] Error copying file! %s" % (errormsg) + else: + print "[*] ..done" + #end try + #end if same_partition #end if not file_exists else: print "Skipping file"