Skip to content
Snippets Groups Projects
Commit f871b746 authored by tuhe's avatar tuhe
Browse files

updates

parent 09241609
No related merge requests found
Pipeline #32450 failed
Metadata-Version: 2.1 Metadata-Version: 2.1
Name: codesnipper Name: codesnipper
<<<<<<< HEAD Version: 0.1.18.15
Version: 0.1.18.11
=======
Version: 0.1.18.10
>>>>>>> 6fce20d6e5d8194b6a072056a9a906939d4ee070
Summary: A lightweight framework for censoring student solutions files and extracting code + output Summary: A lightweight framework for censoring student solutions files and extracting code + output
Home-page: https://lab.compute.dtu.dk/tuhe/snipper Home-page: https://lab.compute.dtu.dk/tuhe/snipper
Author: Tue Herlau Author: Tue Herlau
......
...@@ -18,11 +18,12 @@ def o_block_funlines(lines, art, output, all_lines=None): ...@@ -18,11 +18,12 @@ def o_block_funlines(lines, art, output, all_lines=None):
l2 += [id + f"sys.stdout = open('{outf}', 'w')"] l2 += [id + f"sys.stdout = open('{outf}', 'w')"]
l2 += lines l2 += lines
l2 += [indent(lines[-1]) + "sys.stdout.close()"]
l2 += [indent(lines[-1]) + "sys.stdout = sys.__stdout__"] l2 += [indent(lines[-1]) + "sys.stdout = sys.__stdout__"]
return l2 return l2
pass pass
def run_o(lines, file, output,package_base_dir=None): def run_o(lines, file, output,package_base_dir=None, verbose=True):
# def block_fun(lines, start_extra, end_extra, art, output, **kwargs): # def block_fun(lines, start_extra, end_extra, art, output, **kwargs):
# id = indent(lines[0]) # id = indent(lines[0])
# outf = output + ("_" + art if art is not None else "") + ".txt" # outf = output + ("_" + art if art is not None else "") + ".txt"
...@@ -50,6 +51,8 @@ def run_o(lines, file, output,package_base_dir=None): ...@@ -50,6 +51,8 @@ def run_o(lines, file, output,package_base_dir=None):
# ex = b['name'] # ex = b['name']
# o_block_fun(b['block'], None, ) # o_block_fun(b['block'], None, )
l2 = o_block_funlines( b['block'], b['name'], output, all_lines=lines) l2 = o_block_funlines( b['block'], b['name'], output, all_lines=lines)
art = b['name']
output_file = output + ("_" + art if art is not None and art != "" else "") + ".txt"
lines2 = b['first'] + l2 + b['last'] lines2 = b['first'] + l2 + b['last']
lines = b['first'] + b['block'] + b['last'] lines = b['first'] + b['block'] + b['last']
...@@ -61,6 +64,7 @@ def run_o(lines, file, output,package_base_dir=None): ...@@ -61,6 +64,7 @@ def run_o(lines, file, output,package_base_dir=None):
else: else:
with open(file_run, 'w', encoding="utf-8") as f: with open(file_run, 'w', encoding="utf-8") as f:
f.write("\n".join(lines2)) f.write("\n".join(lines2))
python = sys.executable python = sys.executable
if package_base_dir is None: if package_base_dir is None:
cmd = f"cd {os.path.dirname(file_run)} && {python} {os.path.basename(file_run)}" cmd = f"cd {os.path.dirname(file_run)} && {python} {os.path.basename(file_run)}"
...@@ -69,8 +73,23 @@ def run_o(lines, file, output,package_base_dir=None): ...@@ -69,8 +73,23 @@ def run_o(lines, file, output,package_base_dir=None):
rp = os.path.relpath(file_run, package_base_dir).replace("\\", "/").replace("/", ".")[:-3] rp = os.path.relpath(file_run, package_base_dir).replace("\\", "/").replace("/", ".")[:-3]
cmd = f"cd {package_base_dir} && {python} -m {rp}" cmd = f"cd {package_base_dir} && {python} -m {rp}"
print(cmd) if verbose:
print(cmd)
print("File that will be run contains:", file_run)
with open(file_run, 'r') as f:
print(f.read())
s = subprocess.check_output(cmd, shell=True) s = subprocess.check_output(cmd, shell=True)
if verbose:
print("> After I ran it I got the output")
print(s)
if os.path.isfile(output_file):
print("> Then Lets read the output file", output_file)
with open(output_file, 'r') as f:
print(f.read())
print(">> WAS THAT WHAT YOU EXPECTED???")
else:
print("No output file produced", output_file)
os.remove(file_run) os.remove(file_run)
...@@ -80,16 +99,3 @@ def run_o(lines, file, output,package_base_dir=None): ...@@ -80,16 +99,3 @@ def run_o(lines, file, output,package_base_dir=None):
print("I was cutting the #!o tag") print("I was cutting the #!o tag")
print("\n".join( lines) ) print("\n".join( lines) )
raise(e) raise(e)
# if didfind:
# fp, ex = os.path.splitext(file)
# file_run = fp + "_RUN_OUTPUT_CAPTURE" +ex
# if os.path.exists(file_run):
# print("file found mumble...")
# else:
# with open(file_run, 'w', encoding="utf-8") as f:
# f.write("\n".join(lines2) )
# cmd = "python " + file_run
# import subprocess
# s = subprocess.check_output(cmd, shell=True)
# os.remove(file_run)
\ No newline at end of file
...@@ -17,7 +17,6 @@ def get_s(lines): ...@@ -17,7 +17,6 @@ def get_s(lines):
pass pass
if 'dse' in c['start_tag_args']: if 'dse' in c['start_tag_args']:
print("asdfasdfs") print("asdfasdfs")
# print(c['start_tag_args'])
if 'nodoc' in c['start_tag_args'] and c['start_tag_args']['nodoc']: if 'nodoc' in c['start_tag_args'] and c['start_tag_args']['nodoc']:
c['block'] = rm_docstring(c['block']) c['block'] = rm_docstring(c['block'])
print("No documentation!") print("No documentation!")
...@@ -26,25 +25,6 @@ def get_s(lines): ...@@ -26,25 +25,6 @@ def get_s(lines):
output = {} output = {}
for name, co in blocks.items(): for name, co in blocks.items():
slines = [l for c in co for l in c['block']] slines = [l for c in co for l in c['block']]
# full_strip("")
# c['block']['args']
# slines = slines[ 23]
# co.
# if slines[f.lineno].strip().startswith('"' * 3):
# print("got a docstrnig")
# for k in range(f.lineno, f.end_lineno + 1):
# l = slines[k] if k != f.lineno else slines[k].strip()[3:]
# if l.find('"' * 3) >= 0:
# break
# else:
# k = -1
# if k > 0:
# print("Docstring detected")
# for i in range(f.lineno, k + 1):
# ll2[i] = None
output[name] = slines output[name] = slines
return output return output
...@@ -59,7 +39,8 @@ def rm_docstring(lines): ...@@ -59,7 +39,8 @@ def rm_docstring(lines):
ll2 = slines.copy() ll2 = slines.copy()
def rm_ds(f, ll2): def rm_ds(f, ll2):
if slines[f.lineno].strip().startswith('"' * 3): lstart = slines[f.lineno].strip()
if lstart.startswith('"' * 3) or lstart.startswith('r' + '"' * 3):
# print("got a docstrnig") # print("got a docstrnig")
for k in range(f.lineno-1, f.end_lineno + 1): for k in range(f.lineno-1, f.end_lineno + 1):
l = slines[k] if k != f.lineno else slines[k].strip()[3:] l = slines[k] if k != f.lineno else slines[k].strip()[3:]
......
...@@ -49,9 +49,10 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True, ...@@ -49,9 +49,10 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True,
package_base_dir=None): package_base_dir=None):
if str(file).endswith("rst"): if str(file).endswith("rst"):
assert not run_files and not cut_files and not censor_files assert not run_files and not cut_files and not censor_files
# print(file)
# if str(file).endswith("md"): if str(file).endswith(".md"):
# assert not run_files and not cut_files license_head=None
if references == None: if references == None:
references = {} references = {}
......
<<<<<<< HEAD __version__ = "0.1.18.15"
__version__ = "0.1.18.11"
=======
__version__ = "0.1.18.10"
>>>>>>> 6fce20d6e5d8194b6a072056a9a906939d4ee070
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment