From: jorgormo Date: Thu, 3 Jul 2008 13:34:27 +0000 (+0200) Subject: Merge branch 'master' into hyades X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=bf8a4ba55f9d016bbe902210fda382aa382f36a1;p=melon.git Merge branch 'master' into hyades Conflicts: melon-watch-dir.py --- bf8a4ba55f9d016bbe902210fda382aa382f36a1 diff --cc melon-watch-dir.py index 58749e2,e4e1e76..2063ab0 --- a/melon-watch-dir.py +++ b/melon-watch-dir.py @@@ -10,41 -9,27 +10,43 @@@ dst_dirname = sys.argv[1 name = sys.argv[2] dirname = sys.argv[3] total = int(sys.argv[4]) -user = os.getlogin() +try: + user = os.getlogin() +except: + user = "jorgormo" hostname = os.uname()[1] +# this is not secure, race conditions are possible +def tempname(suffix, preffix, dirname): + l = os.listdir(dirname) + name = preffix+("%05d"%random.randint(0,99999))+suffix + while name in l: + name = preffix+("%05d"%random.randint(0,99999))+suffix + return dirname+os.sep+name + + if "NamedTemporaryFile" in dir(tempfile): - outfile=tempfile.NamedTemporaryFile("w+b",-1,".melon","log-",dst_dirname) + outfile=tempfile.NamedTemporaryFile("w+b",-1,"","melon-",dst_dirname) else: - outfile=file(dst_dirname + os.sep + tempfile.mktemp(".melon"), "w+b", 0) + outfilename=tempname("", "melon-", dst_dirname) + outfile=file(outfilename, "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.flush() - time.sleep(2) - old_count = count +try: + old_count = -1 count = len(os.listdir(dirname)) -outfile.write("!!%s&%s&%s&%s&%d!!\n"%(name, user, hostname, dirname+" "+str(count)+"/"+str(total), (100*count)/total)) -outfile.flush() -outfile.close() - + 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.flush() + time.sleep(2) + old_count = count + count = len(os.listdir(dirname)) ++ outfile.write("!!%s&%s&%s&%s&%d!!\n"%(name, user, hostname, dirname+" "+str(count)+"/"+str(total), (100*count)/total)) ++ outfile.flush() ++ outfile.close() +except: + if "NamedTemporaryFile" not in dir(tempfile): + os.remove(outfilename) - - -