Example #1
0
def execute(cmd, timeout=60, **kwargs):
    """
    Executes the given shell command

    Args:
        cmd: List of command arguments
        timeout: maximum alloted time for the command
        **kwargs: passes to LocalShell.spawn
    Returns:
        An execution result.
    Raises:
        NoSuchCommandError, RunProcessError, FileNotFoundError
    """

    shell = LocalShell()

    #It is unlikely that someone actually intends to supply
    #a string based on how spur works.
    if type(cmd) == str:
        cmd = ["bash", "-c"] + [cmd]

    process = shell.spawn(cmd, store_pid=True, **kwargs)
    start_time = time()

    while process.is_running():
        delta_time = time() - start_time
        if delta_time > timeout:
            process.send_signal(SIGKILL)
            raise TimeoutError(cmd, timeout)

    return process.wait_for_result()
Example #2
0
def execute(cmd, timeout=60, **kwargs):
    """
    Executes the given shell command

    Args:
        cmd: List of command arguments
        timeout: maximum allotted time for the command
        **kwargs: passes to LocalShell.spawn
    Returns:
        An execution result.
    Raises:
        NoSuchCommandError, RunProcessError, FileNotFoundError
    """

    shell = LocalShell()

    # It is unlikely that someone actually intends to supply
    # a string based on how spur works.
    if type(cmd) == str:
        cmd = ["bash", "-c"] + [cmd]

    process = shell.spawn(cmd, store_pid=True, **kwargs)
    start_time = time()

    while process.is_running():
        delta_time = time() - start_time
        if delta_time > timeout:
            process.send_signal(SIGKILL)
            raise TimeoutError(cmd, timeout)

    return process.wait_for_result()
Example #3
0
import sys
import os
import shutil
import contextlib
import io

from nose.tools import istest, assert_equal
from spur import LocalShell
import tempman

_local = LocalShell()


@istest
def vendorizing_single_module_with_no_dependencies_grabs_one_module_file():
    with _vendorize_example("isolated-module") as project_path:
        result = _local.run(["python", os.path.join(project_path, "main.py")])
        assert_equal(b"('one', 1)", result.output.strip())


@istest
def can_vendorize_local_modules_from_relative_paths():
    with _vendorize_example("local-module") as project_path:
        result = _local.run(["python", os.path.join(project_path, "main.py")])
        assert_equal(b"hello\n", result.output)


@istest
def absolute_paths_in_same_distribution_are_rewritten_to_be_relative():
    with _vendorize_example("absolute-import-rewrite") as project_path:
        result = _local.run(["python", os.path.join(project_path, "main.py")])