From: Agnibho Mondal Date: Thu, 15 Mar 2018 07:14:47 +0000 (+0530) Subject: No temp file in cwd X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=04a0ede02c255a86b18ea07c30ce400af60dd095;p=statin.git No temp file in cwd --- diff --git a/statin/statin.py b/statin/statin.py index f2c51cb..1c2dc07 100644 --- a/statin/statin.py +++ b/statin/statin.py @@ -95,17 +95,18 @@ def main(): outfile = OUTPUT_DIR + path.splitext(path.basename(filename))[0] + ".html" temp = [] fdir = path.dirname(path.realpath(filename)) + orig = filename # Run before-commands if(args.before): if(args.verbose): print("Running " + args.before) - tf = tempfile.NamedTemporaryFile(dir=fdir, prefix=".", delete=False) + tf = tempfile.NamedTemporaryFile(delete = False) copyfile(filename, tf.name) filename = tf.name try: with open(tf.name) as f: - p = run(args.before, shell=True, input = f.read(), stdout=PIPE, encoding="utf-8") + p = run(args.before, shell = True, input = f.read(), stdout = PIPE, encoding = "utf-8") with open(tf.name, "w") as f: if(p.returncode == 0): f.write(p.stdout) @@ -121,15 +122,15 @@ def main(): if(not args.quiet): print("Creating temporary files") rlvl = 0 - temp.append(tempfile.NamedTemporaryFile(dir=fdir, prefix=".", delete=False)) - temp.append(tempfile.NamedTemporaryFile(dir=fdir, prefix=".", delete=False)) + temp.append(tempfile.NamedTemporaryFile(delete = False)) + temp.append(tempfile.NamedTemporaryFile(delete = False)) copyfile(filename, temp[0].name) if(args.verbose): print("'" + filename + "' copied to '" + temp[0].name + "'") if(args.verbose): print("Processing '" + temp[0].name + "' to '" + temp[1].name + "'") - while(rlvl < MAX_RECURSION and not process_file(temp[0].name, temp[1].name, filename)): - temp.append(tempfile.NamedTemporaryFile(dir=fdir, prefix=".", delete=False)) + while(rlvl < MAX_RECURSION and not process_file(temp[0].name, temp[1].name, directory = fdir, original = orig)): + temp.append(tempfile.NamedTemporaryFile(delete = False)) unlink(temp.pop(0).name) if(args.verbose): print("Processing '" + temp[0].name + "' to '" + temp[1].name + "'") @@ -145,7 +146,7 @@ def main(): unlink(t.name) # Simple processing else: - process_file(filename, outfile) + process_file(filename, outfile, directory = fdir, original = orig) if(not args.quiet): print("Output saved to '" + outfile + "'") @@ -162,7 +163,7 @@ def main(): print("Running " + args.after) try: with open(outfile) as f: - p = run(args.after, shell=True, input = f.read(), stdout=PIPE, encoding="utf-8") + p = run(args.after, shell = True, input = f.read(), stdout = PIPE, encoding = "utf-8") with open(outfile, "w") as f: if(p.returncode == 0): f.write(p.stdout) @@ -174,14 +175,12 @@ def main(): print(args.after + ": command failed") # Process the file -def process_file(filename, outfile, original = None): +def process_file(filename, outfile, directory, original): global args global openif, ifstatus, ifskip # Assign variable values no_directive = True - if(original == None): - original = filename try: varlist["DOCUMENT_URI"] = original @@ -194,7 +193,7 @@ def process_file(filename, outfile, original = None): if(item.strip()): if(item.strip()[:5] == "