diff --git a/beat/web/backend/tests.py b/beat/web/backend/tests.py old mode 100644 new mode 100755 index 977a2384276731419b4e2343b3fc4575142f1d0b..cebfc4368efe380fc1cdd26676b3afe23edacc75 --- a/beat/web/backend/tests.py +++ b/beat/web/backend/tests.py @@ -2093,10 +2093,8 @@ class Working(BaseBackendTestCase): def setUp(self): - from beat.core.async import resolve_cpulimit_path - self.cpulimit = resolve_cpulimit_path(None) - from . import utils + self.cpulimit = utils.resolve_cpulimit_path(None) self.process = utils.resolve_process_path() self.environments = utils.find_environments(None) self.env1_execute = self.environments['environment (1)']['execute'] @@ -2548,10 +2546,8 @@ class WorkingExternally(TransactionTestCase): def setUp(self): - from beat.core.async import resolve_cpulimit_path - self.cpulimit = resolve_cpulimit_path(None) - from . import utils + self.cpulimit = utils.resolve_cpulimit_path(None) self.process = utils.resolve_process_path() self.environments = utils.find_environments(None) diff --git a/beat/web/backend/utils.py b/beat/web/backend/utils.py old mode 100644 new mode 100755 index bda58d941fe8662d8012e03e03f3f9588bcf0f43..209cd9bdfec8e3fe7f9ba1c7f6598daec00a2bd1 --- a/beat/web/backend/utils.py +++ b/beat/web/backend/utils.py @@ -32,6 +32,7 @@ import sys import fnmatch import glob import time +import distutils.spawn import logging logger = logging.getLogger(__name__) @@ -409,3 +410,37 @@ def pick_execute(split, environments): # Check we have a compatible environment to execute the user algorithm envinfo = environments.get(split.job.block.environment.fullname()) return envinfo['execute'] if envinfo else None + + +def resolve_cpulimit_path(exe): + '''Returns the path to cpulimit''' + FIXED_LOCATIONS = [ + '/usr/local/bin/cpulimit', + '/opt/local/bin/cpulimit', + '/usr/bin/cpulimit', + ] + default = os.path.join( + os.path.dirname(os.path.realpath(sys.argv[0])), + 'cpulimit', + ) + retval = exe or default + # See if we find it in parallel, installed with our interpreter + if not os.path.exists(retval): + cand = os.path.join(os.path.dirname(sys.executable), 'cpulimit') + if os.path.exists(cand): retval = cand + # Try to see if the PATH variable is set + if not os.path.exists(retval): + try: + retval = distutils.spawn.find_executable('cpulimit') + except KeyError: #missing PATH variable + retval = None + # Try fixed locations + if not retval: + for k in FIXED_LOCATIONS: + if os.path.exists(k): + retval = k + if not retval: + raise IOError("I cannot the find a `cpulimit' binary on your system or " \ + "the value you provided is not valid (%s) or the symbolic link " \ + "(%s) is not properly set" % (exe, default)) + return retval diff --git a/beat/web/backend/views.py b/beat/web/backend/views.py old mode 100644 new mode 100755 index e954598b6b5fc2e962ac70a0db862681ceab4c26..c86e05641484d9ef175794e53d41461ea57c817a --- a/beat/web/backend/views.py +++ b/beat/web/backend/views.py @@ -42,7 +42,7 @@ from django.contrib.auth.decorators import login_required from django.http import HttpResponseForbidden from django.contrib import messages -from beat.core.async import resolve_cpulimit_path +from .utils import resolve_cpulimit_path from ..experiments.models import Experiment diff --git a/beat/web/scripts/worker.py b/beat/web/scripts/worker.py old mode 100644 new mode 100755 index c4a257ce3a27493011249caa961c7cdfd5f8f047..a78c66c4fdce872a8accf6de2d88003cba19cbfc --- a/beat/web/scripts/worker.py +++ b/beat/web/scripts/worker.py @@ -126,7 +126,7 @@ def main(user_input=None): arguments['--name']) # figure out paths to programs I need to use - from beat.core.async import resolve_cpulimit_path + from ..backend.utils import resolve_cpulimit_path cpulimit = resolve_cpulimit_path(arguments['--cpulimit']) logger.debug("(path) cpulimit: `%s'", cpulimit) process = utils.resolve_process_path() diff --git a/buildout.cfg b/buildout.cfg index ba44f3b0f292912f1e40918c6e5be1f80b0c599d..50747a188742553ffd69310d74e3fc66a732be40 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -15,7 +15,7 @@ develop = . versions = versions [versions] -django = >=1.8,<1.9 +django = >=1.9,<1.10 django-rest-swagger = >=0.3.2,<0.3.3 django-guardian = >=1.3 djangorestframework = >=3.2,<3.3 @@ -85,7 +85,7 @@ eggs = alabaster wsgiref [sources] -beat.core = git git@gitlab.idiap.ch:beat/beat.core +beat.core = git git@gitlab.idiap.ch:beat/beat.core branch=docker beat.cmdline = git git@gitlab.idiap.ch:beat/beat.cmdline beat.backend.python = git git@gitlab.idiap.ch:beat/beat.backend.python beat.examples = git git@gitlab.idiap.ch:beat/beat.examples egg=false