Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions problemtools/problem2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import logging
import subprocess

import plasTeX.TeX
import plasTeX.Logging
def convert(problem, options=None):
import plasTeX.TeX
import plasTeX.Logging

from .ProblemPlasTeX import ProblemRenderer
from .ProblemPlasTeX import ProblemsetMacros
from . import template
from .ProblemPlasTeX import ProblemRenderer
from .ProblemPlasTeX import ProblemsetMacros
from . import template


def convert(problem, options=None):
problem = os.path.realpath(problem)

problembase = os.path.splitext(os.path.basename(problem))[0]
Expand Down
11 changes: 8 additions & 3 deletions problemtools/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,18 @@ def get_program(path, language_config=None, work_dir=None, include_dir=None,
files = [path]
else:
build = os.path.join(path, 'build')
if os.path.isfile(build) and os.access(path, os.X_OK):
if os.path.isfile(build) and os.access(build, os.X_OK):
return BuildRun(path, work_dir)
files = rutil.list_files_recursive(path)

if language_config is not None:
lang = language_config.detect_language(files)
if lang is not None:
return SourceCode(path, lang,
work_dir=work_dir, include_dir=include_dir)
if include_dir is not None:
lang_dir = os.path.join(include_dir, lang.lang_id)
build = os.path.join(lang_dir, 'build')
if os.path.isfile(build) and os.access(build, os.X_OK):
return BuildRun(path, work_dir=work_dir, include_dir=lang_dir)

return SourceCode(path, lang, work_dir=work_dir, include_dir=include_dir)
return None
19 changes: 11 additions & 8 deletions problemtools/run/buildrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
from .program import Program
from . import rutil

log = logging.getLogger(__file__)


class BuildRun(Program):
"""Class for build/run-script program.
"""

def __init__(self, path, work_dir=None):
def __init__(self, path, work_dir=None, include_dir=None):
"""Instantiate BuildRun object.

Args:
Expand All @@ -28,12 +30,6 @@ def __init__(self, path, work_dir=None):
if not os.path.isdir(path):
raise ProgramError('%s is not a directory' % path)

build = os.path.join(path, 'build')
if not os.path.isfile(build):
raise ProgramError('%s does not have a build script' % path)
if not os.access(build, os.X_OK):
raise ProgramError('%s/build is not executable' % path)

if work_dir is None:
work_dir = tempfile.mkdtemp()

Expand All @@ -47,7 +43,14 @@ def __init__(self, path, work_dir=None):
os.makedirs(self.path)

rutil.add_files(path, self.path)
if include_dir is not None and os.path.isdir(include_dir):
rutil.add_files(include_dir, self.path)

build = os.path.join(self.path, 'build')
if not os.path.isfile(build):
raise ProgramError('%s does not have a build script' % path)
if not os.access(build, os.X_OK):
raise ProgramError('%s/build is not executable' % path)

def __str__(self):
"""String representation"""
Expand All @@ -65,7 +68,7 @@ def compile(self):
run = os.path.join(self.path, 'run')

if status:
logging.debug('Build script failed (status %d) when compiling %s\n Command used:\n%s', status, self.name, command)
log.debug('Build script failed (status %d) when compiling %s\n Command used:\n%s', status, self.name, command)
self._compile_result = (False, 'build script failed with exit code %d' % (status))
elif not os.path.isfile(run) or not os.access(run, os.X_OK):
self._compile_result = (False, 'build script did not produce an executable called "run"')
Expand Down
9 changes: 6 additions & 3 deletions problemtools/run/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

from .errors import ProgramError

log = logging.getLogger(__name__)


class Program(object):
"""Abstract base class for programs.
"""
Expand Down Expand Up @@ -70,8 +73,8 @@ def should_skip_memory_rlimit(self):

@staticmethod
def __run_wait(argv, infile, outfile, errfile, timelim, memlim):
logging.debug('run "%s < %s > %s 2> %s"',
' '.join(argv), infile, outfile, errfile)
log.debug('run "%s < %s > %s 2> %s"',
' '.join(argv), infile, outfile, errfile)
pid = os.fork()
if pid == 0: # child
try:
Expand Down Expand Up @@ -110,7 +113,7 @@ def __run_wait(argv, infile, outfile, errfile, timelim, memlim):
print(exc)
os.kill(os.getpid(), signal.SIGTERM)
# Unreachable
logging.error("Unreachable part of run_wait reached")
log.error("Unreachable part of run_wait reached")
os.kill(os.getpid(), signal.SIGTERM)
(pid, status, rusage) = os.wait4(pid, 0)
return status, rusage.ru_utime + rusage.ru_stime
Expand Down
5 changes: 4 additions & 1 deletion problemtools/run/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from .program import Program
from . import rutil

log = logging.getLogger(__name__)


class SourceCode(Program):
"""Class representing a program provided by source code.
"""
Expand Down Expand Up @@ -103,7 +106,7 @@ def compile(self):
if not os.path.isfile(compiler) or not os.access(compiler, os.X_OK):
return (False, '%s does not seem to be installed, expected to find compiler at %s' % (self.language.name, compiler))

logging.debug('compile command: %s', command)
log.debug('compile command: %s', command)

try:
subprocess.check_output(command, stderr=subprocess.STDOUT)
Expand Down
Loading