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) |