How to use the honcho.compat.ON_WINDOWS function in honcho

To help you get started, we’ve selected a few honcho examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nickstenning / honcho / test / integration / test_run.py View on Github external
def test_run_captures_all_arguments_windows():
    # note: this is not the same exact test as on Posix
    # but this captures the gist of the intention
    if not compat.ON_WINDOWS:
        return
    command = ['run', 'cmd', '/a', '/e:on', '/c', 'cd', '&', 'set']
    ret, out, err = get_honcho_output(command)
    assert_equal(ret, 0)
    assert_true("honcho" in out)
    assert_true("HOMEDRIVE" in out)
github nickstenning / honcho / test / integration / test_start.py View on Github external
def test_start_with_arg_returncode():
    procfile = 'Procfile.returncodewin' if compat.ON_WINDOWS else 'Procfile.returncode'
    ret, out, err = get_honcho_output(['-f', procfile, 'start', 'bar'])

    assert_equal(ret, 42)
github nickstenning / honcho / test / integration / test_simple.py View on Github external
def test_start_with_arg_returncode():
    procfile = 'Procfile.returncodewin' if compat.ON_WINDOWS else 'Procfile.returncode'
    ret, out, err = get_honcho_output(['-f', procfile, 'start', 'bar'])

    assert_equal(ret, 42)
github nickstenning / honcho / test / integration / test_ports.py View on Github external
def test_get_port_from_env():
    os.environ['PORT'] = '3000'
    procfile = 'Procfile.portswin' if compat.ON_WINDOWS else 'Procfile.ports'
    ret, out, err = get_honcho_output(['-f', procfile, 'start'])

    assert_equal(ret, 0)

    assert_regexp_matches(out, r'web\.1    \| (....)?PORT=3000')
github nickstenning / honcho / honcho / printer.py View on Github external
time_formatted = message.time.strftime(self.time_format)
            prefix = '{time} {name}| '.format(time=time_formatted, name=name)
            if self._colours_supported and message.colour:
                prefix = _colour_string(message.colour, prefix)
            self.output.write(prefix + line + "\n")


def _ansi(code):
    return '\033[{0}m'.format(code)


def _colour_string(colour, s):
    return '{0}{1}{2}{3}'.format(_ansi(0), _ansi(colour), s, _ansi(0))


if ON_WINDOWS:
    # The colorama package provides transparent support for ANSI colour codes
    # on Win32 platforms. We try and import and configure that, but fall back
    # to no colour if we fail.
    try:
        import colorama
    except ImportError:
        def _colour_string(colour, s):  # noqa
            return s
    else:
        colorama.init()
github nickstenning / honcho / honcho / command.py View on Github external
def command_run(args):
    os.environ.update(_read_env(args.app_root, args.env))

    argv = args.argv

    # If the first of the remaining args is '--', skip it.
    if argv and argv[0] == '--':
        argv = argv[1:]

    if compat.ON_WINDOWS:
        # do not quote on Windows, subprocess will handle it for us
        # using the MSFT quoting rules
        cmd = argv
    else:
        cmd = ' '.join(compat.shellquote(arg) for arg in argv)

    p = Popen(cmd, stdout=sys.stdout, stderr=sys.stderr,
              start_new_session=False)
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    p.wait()
    sys.exit(p.returncode)
github nickstenning / honcho / honcho / process.py View on Github external
def __init__(self, cmd, **kwargs):
        start_new_session = kwargs.pop('start_new_session', True)
        options = {
            'stdout': subprocess.PIPE,
            'stderr': subprocess.STDOUT,
            'shell': True,
            'bufsize': 1,
            'close_fds': not ON_WINDOWS,
        }
        options.update(**kwargs)

        if ON_WINDOWS:
            # MSDN reference:
            #   http://msdn.microsoft.com/en-us/library/windows/desktop/ms684863%28v=vs.85%29.aspx
            create_new_process_group = 0x00000200
            detached_process = 0x00000008
            options.update(creationflags=detached_process | create_new_process_group)
        elif start_new_session:
            if sys.version_info < (3, 2):
                options.update(preexec_fn=os.setsid)
            else:
                options.update(start_new_session=True)

        super(Popen, self).__init__(cmd, **options)
github nickstenning / honcho / honcho / environ.py View on Github external
from . import compat

if compat.ON_WINDOWS:
    import ctypes


PROCFILE_LINE = re.compile(r'^([A-Za-z0-9_]+):\s*(.+)$')


class Env(object):

    def now(self):
        return datetime.datetime.now()

    if compat.ON_WINDOWS:
        def terminate(self, pid):
            # The first argument to OpenProcess represents the desired access
            # to the process. 1 represents the PROCESS_TERMINATE access right.
            handle = ctypes.windll.kernel32.OpenProcess(1, False, pid)
            ctypes.windll.kernel32.TerminateProcess(handle, -1)
            ctypes.windll.kernel32.CloseHandle(handle)
    else:
        def terminate(self, pid):
            try:
                os.killpg(pid, signal.SIGTERM)
            except OSError as e:
                if e.errno not in [errno.EPERM, errno.ESRCH]:
                    raise

    if compat.ON_WINDOWS:
        def kill(self, pid):
github deeplearninc / relaax / relaax / cmdl / commands / cmd_run.py View on Github external
def __init__(self, cmd, **kwargs):
        start_new_session = kwargs.pop('start_new_session', True)
        options = {
            'stdout': subprocess.PIPE,
            'stderr': subprocess.STDOUT,
            'shell': True,
            'bufsize': 1,
            'close_fds': not ON_WINDOWS,
        }
        options.update(**kwargs)

        if ON_WINDOWS:
            # MSDN reference:
            #   http://msdn.microsoft.com/en-us/library/windows/desktop/ms684863%28v=vs.85%29.aspx
            create_new_process_group = 0x00000200
            detached_process = 0x00000008
            #options.update(creationflags=detached_process | create_new_process_group)
            os.environ["COMSPEC"]= "powershell.exe"
        elif start_new_session:
            if sys.version_info < (3, 2):
                options.update(preexec_fn=os.setsid)
            else:
                options.update(start_new_session=True)