Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 2165:d821918e3bee
Use better names (hg-{usage}-{random}.{suffix}) for temporary files.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Sun, 30 Apr 2006 21:11:22 +0200 |
parents | 635653cd73ab |
children | 6886bc0b77af |
comparison
equal
deleted
inserted
replaced
2164:cbd458228a96 | 2165:d821918e3bee |
---|---|
44 CMD is used as a template to create the real command to be run, | 44 CMD is used as a template to create the real command to be run, |
45 with the strings INFILE and OUTFILE replaced by the real names of | 45 with the strings INFILE and OUTFILE replaced by the real names of |
46 the temporary files generated.''' | 46 the temporary files generated.''' |
47 inname, outname = None, None | 47 inname, outname = None, None |
48 try: | 48 try: |
49 infd, inname = tempfile.mkstemp(prefix='hgfin') | 49 infd, inname = tempfile.mkstemp(prefix='hg-filter-in-') |
50 fp = os.fdopen(infd, 'wb') | 50 fp = os.fdopen(infd, 'wb') |
51 fp.write(s) | 51 fp.write(s) |
52 fp.close() | 52 fp.close() |
53 outfd, outname = tempfile.mkstemp(prefix='hgfout') | 53 outfd, outname = tempfile.mkstemp(prefix='hg-filter-out-') |
54 os.close(outfd) | 54 os.close(outfd) |
55 cmd = cmd.replace('INFILE', inname) | 55 cmd = cmd.replace('INFILE', inname) |
56 cmd = cmd.replace('OUTFILE', outname) | 56 cmd = cmd.replace('OUTFILE', outname) |
57 code = os.system(cmd) | 57 code = os.system(cmd) |
58 if code: raise Abort(_("command '%s' failed: %s") % | 58 if code: raise Abort(_("command '%s' failed: %s") % |
462 p = base | 462 p = base |
463 audit_p = audit | 463 audit_p = audit |
464 | 464 |
465 def mktempcopy(name): | 465 def mktempcopy(name): |
466 d, fn = os.path.split(name) | 466 d, fn = os.path.split(name) |
467 fd, temp = tempfile.mkstemp(prefix=fn, dir=d) | 467 fd, temp = tempfile.mkstemp(prefix=".%s-" % fn, dir=d) |
468 fp = os.fdopen(fd, "wb") | 468 fp = os.fdopen(fd, "wb") |
469 try: | 469 try: |
470 fp.write(file(name, "rb").read()) | 470 fp.write(file(name, "rb").read()) |
471 except: | 471 except: |
472 try: os.unlink(temp) | 472 try: os.unlink(temp) |