Merge branch 'master' into hyades
authorjorgormo <jorgormo@node001.(none)>
Thu, 3 Jul 2008 13:34:27 +0000 (15:34 +0200)
committerjorgormo <jorgormo@node001.(none)>
Thu, 3 Jul 2008 13:34:27 +0000 (15:34 +0200)
Conflicts:

melon-watch-dir.py

1  2 
melon-watch-dir.py

index 58749e2439b5c42d9f22a5247a2394e1258573de,e4e1e76e409fcf02af78b356ba864d220984e772..2063ab09dd58f726b671be5683ed246fdc6044a0
@@@ -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)