def runJplag(opts, args, fileGlob=None): jarName = 'jplag-3.0.0-jar-with-dependencies.jar' jarFile = shell.pjoin(shell.dirname(__file__), '..', 'resources', jarName) print('Running jplag, this might take a while ...') res = shell.run(['java', '-jar', jarFile] + opts, captureStdout=True, stderrToStdout=True) haveMinScore = False for l in res.stdout.split('\n'): if 'no viable alternative at input' in l: pass elif 'nothing to parse for submission' in l: pass elif l.startswith('Comparing '): i = -1 try: i = l.rindex(':') except ValueError: verbose(l) if i >= 0: score = float(l[i + 1:].strip()) if score >= args.minScore: haveMinScore = True print(ansi.red(l)) if args.printDiff and score >= 99.99999999999999999: printDiffForJplag(l, fileGlob) elif 'Writing results to' in l: print(ansi.blue(l + "/index.html")) else: verbose(l) if not haveMinScore: print(f'No submissions detected with similaries >= {args.minScore}')
def moveToBackup(path): if not shell.exists(path): return for i in range(1000): backupName = shell.pjoin(shell.dirname(path), '.' + shell.basename(path) + ".bak") if i > 0: backupName = backupName + "." + str(i) if not shell.exists(backupName): shell.mv(path, backupName) return raise ValueError(f"too many backups for {path}")
def copyFileIfNotExists(srcDir, path, targetDir): srcPath = shell.pjoin(srcDir, path) if not shell.isFile(srcPath): raise IOError(f'{srcPath} must be a file') tgtPath = shell.pjoin(targetDir, path) if shell.isDir(tgtPath): raise IOError(f'{tgtPath} must not be a directory') shell.mkdir(shell.dirname(tgtPath), createParents=True) if shell.isFile(tgtPath): if not hasSameContent(srcPath, tgtPath): raise IOError(f'Target file {tgtPath} already exists with content different than in {srcPath}') else: shell.cp(srcPath, tgtPath)
def assertExists(path): if not shell.isFile(path): d = shell.dirname(path) files = shell.ls(d, '*') abort(f'File {path} does not exist, existing files: {files}')