use mktemp in older pythons
authorJorge Gorbe Moya <jgorbe@dsic.upv.es>
Fri, 27 Jun 2008 15:00:14 +0000 (17:00 +0200)
committerJorge Gorbe Moya <jgorbe@dsic.upv.es>
Fri, 27 Jun 2008 15:00:14 +0000 (17:00 +0200)
melon-watch-dir.py

index ba9eac09798bf40ab5f8547b4ae6f44577bb79d2..9c4edcdeb0a90d432e32eaebf9ca2adcd66484e2 100755 (executable)
@@ -12,15 +12,17 @@ total = int(sys.argv[4])
 user = os.getlogin()
 hostname = os.uname()[1]
 
-
-outfile=tempfile.NamedTemporaryFile("w+b",-1,".melon","log-",dst_dirname)
+if "NamedTemporaryFile" in dir(tempfile):
+       outfile=tempfile.NamedTemporaryFile("w+b",-1,".melon","log-",dst_dirname)
+else:
+       outfile=file(tempfile.mktemp(".melon", "log-", dst_dirname), "w+b", 0)
 
 old_count = -1
 count = len(os.listdir(dirname))
 
 while count < total:
        if old_count != count:
-               outfile.write("!!%s&%s&%s&%s&%d!!\n"%(name, user, hostname, "dirname "+str(count)+"/"+str(total), (100*count)/total))
+               outfile.write("!!%s&%s&%s&%s&%d!!\n"%(name, user, hostname, dirname+" "+str(count)+"/"+str(total), (100*count)/total))
                outfile.flush()
        time.sleep(2)
        old_count = count