def workCommand(data): print('Running the Kat work REPL. Run command "help" for more info.') problems = [x[0] for x in collectProblems(data)] currentIndex = 0 previousProblem = None currentProblem = getProblem(currentIndex, data, problems) while True: if previousProblem != currentProblem: print('Problem:', currentProblem) previousProblem = currentProblem try: command = input('> ') if command == "exit": break if command == "read": readCommand({'problem': [currentProblem], 'open': True}) elif command == "test": testCommand({'problem': currentProblem}) elif command == "submit": response = False response = submitCommand({**data, 'problem': currentProblem}) if response == Response.Success: currentIndex += 1 currentProblem = getProblem(currentIndex, data, problems) elif command == "skip": archive(currentProblem) currentIndex += 1 currentProblem = getProblem(currentIndex, data, problems) elif command == "help": print(_HELP_TEXT) except KeyboardInterrupt: print('Shutdown by keyboard interrupt') return
def submitCommand(data): problemName: str = data["problem"] checkCorrectDomain(problemName, "submit") if not os.path.exists(problemName): promptToFetch(problemName) return Response.Error # if programFile is not given, we will attempt to guess it programFile = (formatProgramFile(data.get("file")) if data.get("file") else selectProgramFile(problemName)) if programFile == None: raise Exception("Could not guess programFile") if "force" not in data or not data.get('force'): response = confirm(problemName, programFile) if not response: return Response.Aborted try: session = requests.Session() print("📨 Submitting " + problemName + "...") id = postSubmission(session, problemName, programFile) print( f"📬 Submission Successful (url {getConfigUrl('submissionsurl', 'submissions')}/{id})" ) if id == None: return False response = Response.Failure try: response = printUntilDone(id, problemName, session) except: pass if data.get('sound'): if response == Response.Success: winsound() elif response == Response.Failure: losesound() if response == Response.Success: if data.get('archive'): archive(problemName, ".solved/") return response except requests.exceptions.ConnectionError: print("Connection error: Please check your connection") return Response.Error
def submitCommand(data): problemName = data["problem"] if not os.path.exists(problemName): promptToFetch(problemName) return Response.Error # if programFile is not given, we will attempt to guess it programFile = (formatProgramFile(data.get("file")) if data.get("file") else selectProgramFile(problemName)) if programFile == -1: raise Exception("Could not guess programFile") if "force" not in data or not data.get('force'): response = confirm(problemName, programFile) if not response: return Response.Aborted session = requests.Session() print("📨 Submitting " + problemName + "...") id = postSubmission(session, problemName, programFile) print("📬 Submission Successful (url " + getConfigUrl("submissionsurl", "submissions") + "/" + id + ")") if id == -1: return False response = Response.Failure try: response = printUntilDone(id, problemName, session) except: pass if data.get('sound'): if response == Response.Success: winsound() elif response == Response.Failure: losesound() if response == Response.Success: if data.get('archive'): archive(problemName, ".solved/") return response
def workCommand(data): print('Running the Kat work REPL. Run command "help" for more info.') if data["problem"] is not None: problems = [data["problem"]] else: problems = [x[0] for x in collectProblems(data)] currentIndex = 0 previousProblem = None try: currentProblem = getProblem(currentIndex, data, problems) except InvalidProblemException: print("") print(f"Error: Specified problem does not exist") print("") return while True: if previousProblem != currentProblem: print('Problem:', currentProblem) previousProblem = currentProblem try: command = input('> ') if command == "exit" or command == "quit": break if command == "read": readCommand({'problem': [currentProblem], 'open': True}) elif command == "test": testCommand({'problem': currentProblem}) elif command.startswith("debug"): args = command.split() if len(args) == 1: print( "Please add additional debug subcommand. Either init, rte or wa" ) if args[1] not in debugChoices: print("Invalid subcommand for debug") else: debugdata = { 'problem': currentProblem, 'subcommand': args[1], 'iterations': None } if len(args) == 3: debugdata['iterations'] = int(args[2]) debugCommand(debugdata) elif command == "submit": response = submitCommand({**data, 'problem': currentProblem}) if response == Response.Success: currentIndex += 1 currentProblem = getProblem(currentIndex, data, problems) if currentProblem is None: break elif command == "skip": archive(currentProblem) currentIndex += 1 currentProblem = getProblem(currentIndex, data, problems) if currentProblem is None: break elif command == "help": print(_HELP_TEXT) else: print('Unrecognized command. For help, write "help"') except KeyboardInterrupt: print('Shutdown by keyboard interrupt') return
def testCommand(data: dict): problemName = data['problem'] directory = os.path.join(os.getcwd(), problemName) if not os.path.exists(problemName): promptToFetch(problemName) return # if programFile is not given, we will attempt to guess it programFile = (formatProgramFile(data["file"]) if data.get('file') else selectProgramFile(problemName)) if not programFile: return print("🔎 Running tests on " + programFile["name"]) if shouldCompile(programFile): if compile(programFile, directory) == -1: return inFiles, ansFiles = getTestFiles(problemName) command = getRunCommand(programFile) if command == -1: return testsToRun = data.get('interval') passed = True times = [] for i, (inF, ansF) in enumerate(zip(inFiles, ansFiles)): if testsToRun and i not in testsToRun: continue result, time = runSingleTest(command, directory, inF, ansF) if not result: passed = False else: times.append(time) times.sort() if passed: if len(times) == 1: print(f"🕑 Test took {times[0]:0.2f} seconds") else: print( f"🕑 Tests took from {times[0]:0.2f} to {times[-1]:0.2f} seconds" ) shouldEnd = None if passed: if data.get('submit'): submitCommand({ "problem": problemName, "file": programFile['relativePath'] }) shouldEnd = True if data.get('archive'): archive(problemName) shouldEnd = True if shouldEnd: return shouldEnd
from sys import argv from commands.create import create from commands.archive import archive if len(argv) == 1: print("jacrepo help:") print("jacrepo create [package name] - create a package in this folder") print("jacrepo archive [version] - update current package to version and archive package") exit(0) if argv[1] == "create": if len(argv) == 2: print("Name a package!") exit(1) create(argv[2]) elif argv[1] == "archive": if len(argv) == 2: print("Name a version") exit(1) archive(argv[2]) else: print(f"Unknown argument: {argv[1]}") exit(1)
def testCommand(data: dict): problemName = data['problem'] directory = os.path.join(os.getcwd(), problemName) if not os.path.exists(problemName): promptToFetch(problemName) return # if programFile is not given, we will attempt to guess it programFile = (formatProgramFile(data["file"]) if data.get('file') else selectProgramFile(problemName)) if not programFile: return command = getAndPrepareRunCommand(programFile) if command == None: return print("🔎 Running tests on " + programFile["name"]) inFiles, ansFiles = getTestFiles(problemName) if not inFiles and not ansFiles: print("This problem doesn't seem to have any tests...") print("Will not test.") return testsToRun = data.get('interval') passed = True times = [] try: for i, (inF, ansF) in enumerate(zip(inFiles, ansFiles)): if testsToRun and i not in testsToRun: continue result, time = runSingleTest(command, directory, inF, ansF) if not result: passed = False else: times.append(time) except KeyboardInterrupt: print('Ending tests due to keyboard interrupt...') return times.sort() if passed: if len(times) == 1: print(f"🕑 Test took {times[0]:0.2f} seconds") else: print( f"🕑 Tests took from {times[0]:0.2f} to {times[-1]:0.2f} seconds" ) shouldEnd = None if passed: if data.get('submit'): submitCommand({ "problem": problemName, "file": programFile['relativePath'], "archive": data.get('archive') }) shouldEnd = True elif data.get('archive'): archive(problemName) shouldEnd = True if shouldEnd: return shouldEnd