Skip to content
Snippets Groups Projects
Commit b05e99ae authored by Henke's avatar Henke
Browse files

fix issue #40

Now there is a compile command for the cli
parent 8dd96e15
No related branches found
No related tags found
No related merge requests found
Pipeline #
import os
import shutil
import click
def _GetBuildFolder(bus):
......@@ -121,3 +122,52 @@ def Init(bus):
bus.provide('kattcmd:compile:python', CompilePython)
bus.provide('kattcmd:compile:cpp-command', FindCppCompileCommand)
def CLI(bus, parent):
def OnCppCompiled(binary):
click.echo('Placed binary at {}'.format(binary))
def OnCppCompileFailed(compile_command):
click.secho('Could not compile with "{}"'.format(compile_command), fg='red')
def OnPythonCompiled(paths):
paths = list(map(os.path.relpath, paths))
click.echo('Copied to following paths {}'.format(paths))
def OnNoFiles(problemname):
click.secho('Could not find any "compilable" items for "{}"'.format(problemname), fg='red')
click.echo('Exiting')
exit(1)
@parent.command()
@click.argument('name')
def compile(name):
'''Compile your solution to a problem.
Will compile your solution and put it inside the build
folder. If you use an interpreted language then it will copy
it instead.
This command is useful if you want to run the code yourself
against some specific input.
'''
bus.listen('kattcmd:compile:cpp-compiled', OnCppCompiled)
bus.listen('kattcmd:compile:cpp-compile-failed', OnCppCompileFailed)
bus.listen('kattcmd:compile:python-compiled', OnPythonCompiled)
bus.listen('kattcmd:latest:no-files', OnNoFiles)
value = bus.call('kattcmd:latest', bus, name)
if not value:
click.secho('Could not determine what you worked on previously', fg='red')
click.echo('Exiting')
return None
type, _ = value
if type == 'python':
bus.call('kattcmd:compile:python', bus, name)
elif type == 'cpp':
bus.call('kattcmd:compile:cpp', bus, name)
else:
raise ValueError('{} is not an implemented type'.format(type))
......@@ -32,6 +32,10 @@ and the associated files.'''
home = bus.call('kattcmd:find-root', bus)
problempath = os.path.join(home, 'kattis', problemname)
if not os.path.exists(problempath):
bus.call('kattcmd:latest:no-files', problemname)
return None
items = [os.path.join(problempath, item) for item in os.listdir(problempath)]
with_date = [(os.path.getmtime(fpath), fpath) for fpath in items]
latest_first = reversed(sorted(with_date))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment