Python os.execvp() Examples

The following are code examples for showing how to use os.execvp(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: jack   Author: jack-cli-cd-ripper   File: workers.py    GNU General Public License v2.0 7 votes vote down vote up
def start_new_process(args, nice_value=0):
    "start a new process in a pty and renice it"
    data = {}
    data['start_time'] = time.time()
    pid, master_fd = pty.fork()
    if pid == CHILD:
        default_signals()
        if nice_value:
            os.nice(nice_value)
        os.execvp(args[0], [a.encode(cf['_charset'], "replace") for a in args])
    else:
        data['pid'] = pid
        if os.uname()[0] == "Linux":
            fcntl.fcntl(master_fd, F_SETFL, O_NONBLOCK)
        data['fd'] = master_fd
        data['file'] = os.fdopen(master_fd)
        data['cmd'] = args
        data['buf'] = ""
        data['otf'] = 0
        data['percent'] = 0
        data['elapsed'] = 0
        return data 
Example 2
Project: flasky   Author: RoseOu   File: manage.py    MIT License 6 votes vote down vote up
def test(coverage=False):
    """Run the unit tests."""
    if coverage and not os.environ.get('FLASK_COVERAGE'):
        import sys
        os.environ['FLASK_COVERAGE'] = '1'
        os.execvp(sys.executable, [sys.executable] + sys.argv)
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)
    if COV:
        COV.stop()
        COV.save()
        print('Coverage Summary:')
        COV.report()
        basedir = os.path.abspath(os.path.dirname(__file__))
        covdir = os.path.join(basedir, 'tmp/coverage')
        COV.html_report(directory=covdir)
        print('HTML version: file://%s/index.html' % covdir)
        COV.erase() 
Example 3
Project: circleci-demo-python-flask   Author: CircleCI-Public   File: manage.py    MIT License 6 votes vote down vote up
def test(coverage=False):
    """Run the unit tests."""
    if coverage and not os.environ.get('FLASK_COVERAGE'):
        import sys
        os.environ['FLASK_COVERAGE'] = '1'
        os.execvp(sys.executable, [sys.executable] + sys.argv)
    import unittest
    import xmlrunner
    tests = unittest.TestLoader().discover('tests')
    # run tests with unittest-xml-reporting and output to $CIRCLE_TEST_REPORTS on CircleCI or test-reports locally
    xmlrunner.XMLTestRunner(output=os.environ.get('CIRCLE_TEST_REPORTS','test-reports')).run(tests)
    if COV:
        COV.stop()
        COV.save()
        print('Coverage Summary:')
        COV.report()
        basedir = os.path.abspath(os.path.dirname(__file__))
        covdir = os.path.join(basedir, 'tmp/coverage')
        COV.html_report(directory=covdir)
        print('HTML version: file://%s/index.html' % covdir)
        COV.erase() 
Example 4
Project: talks   Author: theycallmemac   File: 3.py    GNU General Public License v3.0 6 votes vote down vote up
def launch(args):
    # time to execute your input
    # use os.fork to get the process ID
    pid = os.fork()

    # if pid > 0 -> Parent process control
    # else -> Child process control
    if pid > 0:
        wpid = os.waitpid(pid, 0)
    else:
        # try to execeute in the form (command, command_args)
        # generate exception if command does not exist
        try:
            os.execvp(args[0], args)
        except Exception as e:
            print("sesh: command not found: " + args[0]) 
Example 5
Project: talks   Author: theycallmemac   File: 2.py    GNU General Public License v3.0 6 votes vote down vote up
def execute(args):
    # time to execute your input
    # use os.fork to get the process ID
    pid = os.fork()

    # if pid > 0 -> Parent process control
    # else -> Child process control
    if pid > 0:
        wpid = os.waitpid(pid, 0)
    else:
        # try to execeute in the form (command, command_args)
        # generate exception if command does not exist
        try:
            os.execvp(args[0], args)
        except Exception as e:
            print("sesh: command not found: " + args[0]) 
Example 6
Project: talks   Author: theycallmemac   File: 5.py    GNU General Public License v3.0 6 votes vote down vote up
def launch(args):
    # time to execute your input
    # use os.fork to get the process ID
    pid = os.fork()

    # if pid > 0 -> Parent process control
    # else -> Child process control
    if pid > 0:
        wpid = os.waitpid(pid, 0)
    else:
        # try to execeute in the form (command, command_args)
        # generate exception if command does not exist
        try:
            os.execvp(args[0], args)
        except Exception as e:
            print("sesh: command not found: " + args[0]) 
Example 7
Project: Arjun   Author: s0md3v   File: prompt.py    GNU General Public License v3.0 6 votes vote down vote up
def prompt(default=None):
    editor = 'nano'
    with tempfile.NamedTemporaryFile(mode='r+') as tmpfile:
        if default:
            tmpfile.write(default)
            tmpfile.flush()

        child_pid = os.fork()
        is_child = child_pid == 0

        if is_child:
            os.execvp(editor, [editor, tmpfile.name])
        else:
            os.waitpid(child_pid, 0)
            tmpfile.seek(0)
            return tmpfile.read().strip() 
Example 8
Project: clusterfuzz   Author: google   File: stack_symbolizer.py    Apache License 2.0 6 votes vote down vote up
def __init__(self, args, close_stderr=False):
    pid, fd = pty.fork()
    if pid == 0:
      # We're the child. Transfer control to command.
      if close_stderr:
        dev_null = os.open('/dev/null', 0)
        os.dup2(dev_null, 2)
      os.execvp(args[0], args)
    else:
      # Disable echoing.
      attr = termios.tcgetattr(fd)
      attr[3] = attr[3] & ~termios.ECHO
      termios.tcsetattr(fd, termios.TCSANOW, attr)
      # Set up a file()-like interface to the child process
      self.r = os.fdopen(fd, 'r', 1)
      self.w = os.fdopen(os.dup(fd), 'w', 1) 
Example 9
Project: IronHydra   Author: microdee   File: spawn.py    MIT License 6 votes vote down vote up
def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
    log.info(' '.join(cmd))
    if dry_run:
        return
    exec_fn = search_path and os.execvp or os.execv
    pid = os.fork()

    if pid == 0:  # in the child
        try:
            exec_fn(cmd[0], cmd)
        except OSError, e:
            sys.stderr.write("unable to execute %s: %s\n" %
                             (cmd[0], e.strerror))
            os._exit(1)

        sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0])
        os._exit(1) 
Example 10
Project: Computable   Author: ktraunmueller   File: spawn.py    MIT License 6 votes vote down vote up
def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
    log.info(' '.join(cmd))
    if dry_run:
        return
    exec_fn = search_path and os.execvp or os.execv
    pid = os.fork()

    if pid == 0:  # in the child
        try:
            exec_fn(cmd[0], cmd)
        except OSError, e:
            sys.stderr.write("unable to execute %s: %s\n" %
                             (cmd[0], e.strerror))
            os._exit(1)

        sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0])
        os._exit(1) 
Example 11
Project: witchcraft   Author: llllllllll   File: play.py    GNU General Public License v3.0 6 votes vote down vote up
def play(music_home, conn, query):
    """Launch mpv with the results of the query.

    Parameters
    ----------
    music_home : str
        The root directory for witchcraft music.
    conn : sa.engine.Connection
        The connection to the metadata database.
    query : string
        The witchcraft ql query to run against the database.

    Notes
    -----
    This function never returns.
    """
    paths = list(_select_with_args(music_home, conn, query))

    if not paths:
        # nothing to play, mpv doesn't want an empty path list
        return

    os.execvp('mpv', ['mpv', '--no-video'] + paths) 
Example 12
Project: django-docker-helpers   Author: night-crawler   File: test_cli.py    MIT License 6 votes vote down vote up
def test_command_output(self, store_redis_config):
        with mock.patch(
                'django_docker_helpers.cli.django.management.commands.run_configured_uwsgi.os.execvp'
        ) as mocked__os_execvp:
            os.environ.setdefault('CONFIG__PARSERS', 'EnvironmentParser,RedisParser')
            os.environ.setdefault('REDISPARSER__ENDPOINT', ENDPOINT)

            out = StringIO()
            call_command('run_configured_uwsgi', '--print', '-f', '/tmp/__uwsgi.ini', stdout=out)

            # check output (lazy checking =)
            assert EXPECTED_FILE_CONTENT in out.getvalue()

            # check config file
            assert os.path.exists('/tmp/__uwsgi.ini')
            assert os.path.isfile('/tmp/__uwsgi.ini')
            with open('/tmp/__uwsgi.ini', 'r') as f:
                assert EXPECTED_FILE_CONTENT == f.read()

            # check os.execvp arguments
            mocked__os_execvp.assert_called_once()
            mocked__os_execvp.assert_called_once_with('uwsgi', ('--ini', '/tmp/__uwsgi.ini'))

            # NOTE: it's necessary to make environ clean
            os.environ.clear() 
Example 13
Project: django-docker-helpers   Author: night-crawler   File: run_configured_uwsgi.py    MIT License 6 votes vote down vote up
def handle(self, **options):
        key = options['key']

        configure = ConfigLoader.from_env(suppress_logs=True, silent=True)
        uwsgi_cfg = configure.get(key)

        if not uwsgi_cfg:
            self.stderr.write(f'Parsing error: uWSGI config was not found by the key "{key}"')
            return

        if options['print']:
            self.stdout.write('*' * 80 + '\n')
            self.stdout.write('uWSGI CONFIG'.center(80))
            self.stdout.write('*' * 80 + '\n')

            write_uwsgi_ini_cfg(self.stdout, uwsgi_cfg)

            self.stdout.write('*' * 80 + '\n')
            self.stdout.flush()

        cfg_file = options['file']
        with open(cfg_file, 'w') as file:
            write_uwsgi_ini_cfg(file, uwsgi_cfg)

        os.execvp('uwsgi', ('--ini', cfg_file)) 
Example 14
Project: fireh_runner   Author: dozymoe   File: odoo_test.py    MIT License 6 votes vote down vote up
def odoo_test(loader, project=None, variant='testing', *args): #pylint:disable=keyword-arg-before-vararg
    project, variant = loader.setup_project_env(project, variant)
    loader.setup_virtualenv()
    loader.setup_shell_env()
    config = loader.get_project_config()
    python_bin = loader.get_python_bin()

    config_file = config.get('config_file')
    config_file = os.path.join(loader.config['work_dir'],
            config_file)

    work_dir = config.get('work_dir', project)
    work_dir = loader.expand_path(work_dir)

    # bugfix, command like `odoo.py shell`, the word 'shell'  must be mentioned
    # before we define --config, weird
    binargs = [python_bin, __file__, 'server'] + list(args)
    if config_file:
        binargs.append('--config=' + config_file)

    os.chdir(work_dir)
    os.execvp(binargs[0], binargs) 
Example 15
Project: fireh_runner   Author: dozymoe   File: odoo_test.py    MIT License 6 votes vote down vote up
def odoo_test_cleardb(loader, project=None, variant='testing', *args): #pylint:disable=keyword-arg-before-vararg
    project, variant = loader.setup_project_env(project, variant)
    loader.setup_virtualenv()
    loader.setup_shell_env()
    config = loader.get_project_config()
    python_bin = loader.get_python_bin()

    config_file = config.get('config_file')
    config_file = os.path.join(loader.config['work_dir'],
            config_file)

    work_dir = config.get('work_dir', project)
    work_dir = loader.expand_path(work_dir)

    # bugfix, command like `odoo.py shell`, the word 'shell'  must be mentioned
    # before we define --config, weird
    binargs = [python_bin, __file__, 'cleardb'] + list(args)
    if config_file:
        binargs.append('--config=' + config_file)

    os.chdir(work_dir)
    os.execvp(binargs[0], binargs) 
Example 16
Project: fireh_runner   Author: dozymoe   File: odoo_test.py    MIT License 6 votes vote down vote up
def odoo_test_install(loader, project=None, variant='testing', *args): #pylint:disable=keyword-arg-before-vararg
    project, variant = loader.setup_project_env(project, variant)
    loader.setup_virtualenv()
    loader.setup_shell_env()
    config = loader.get_project_config()
    python_bin = loader.get_python_bin()

    config_file = config.get('config_file')
    config_file = os.path.join(loader.config['work_dir'],
            config_file)

    work_dir = config.get('work_dir', project)
    work_dir = loader.expand_path(work_dir)

    # bugfix, command like `odoo.py shell`, the word 'shell'  must be mentioned
    # before we define --config, weird
    binargs = [python_bin, __file__, 'install'] + list(args)
    if config_file:
        binargs.append('--config=' + config_file)

    os.chdir(work_dir)
    os.execvp(binargs[0], binargs) 
Example 17
Project: fireh_runner   Author: dozymoe   File: odoo_test.py    MIT License 6 votes vote down vote up
def odoo_test_uninstall(loader, project=None, variant='testing', *args): #pylint:disable=keyword-arg-before-vararg
    project, variant = loader.setup_project_env(project, variant)
    loader.setup_virtualenv()
    loader.setup_shell_env()
    config = loader.get_project_config()
    python_bin = loader.get_python_bin()

    config_file = config.get('config_file')
    config_file = os.path.join(loader.config['work_dir'],
            config_file)

    work_dir = config.get('work_dir', project)
    work_dir = loader.expand_path(work_dir)

    # bugfix, command like `odoo.py shell`, the word 'shell'  must be mentioned
    # before we define --config, weird
    binargs = [python_bin, __file__, 'uninstall'] + list(args)
    if config_file:
        binargs.append('--config=' + config_file)

    os.chdir(work_dir)
    os.execvp(binargs[0], binargs) 
Example 18
Project: pyblish-win   Author: pyblish   File: popen2.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _run_child(self, cmd):
        if isinstance(cmd, basestring):
            cmd = ['/bin/sh', '-c', cmd]
        os.closerange(3, MAXFD)
        try:
            os.execvp(cmd[0], cmd)
        finally:
            os._exit(1) 
Example 19
Project: Splunk_CBER_App   Author: MHaggis   File: external_search_command.py    MIT License 5 votes vote down vote up
def _execute(path, argv, environ):
            if environ is None:
                os.execvp(path, argv)
            else:
                os.execvpe(path, argv, environ)
            return

    # endregion 
Example 20
Project: pyrex   Author: garmin   File: podman-helper.py    Apache License 2.0 5 votes vote down vote up
def forward():
    os.execvp("podman", ["podman"] + sys.argv[1:])
    sys.exit(1) 
Example 21
Project: wok   Author: bbglab   File: monproc.py    GNU General Public License v3.0 5 votes vote down vote up
def __run_child(cmd, env, stdout, stderr):
	args = shlex.split(cmd)

	os.dup2(stdout.fileno(), sys.stdout.fileno())
	os.dup2(stderr.fileno(), sys.stderr.fileno())

	if env is None:
		os.execvp(args[0], args)
	else:
		os.execvpe(args[0], args, env) 
Example 22
Project: vscode-mayapy   Author: FXTD-ODYSSEY   File: pydev_monkey.py    MIT License 5 votes vote down vote up
def create_execv(original_name):

    def new_execv(path, args):
        """
        os.execv(path, args)
        os.execvp(file, args)
        """
        import os
        send_process_created_message()
        return getattr(os, original_name)(path, patch_args(args))

    return new_execv 
Example 23
Project: vscode-mayapy   Author: FXTD-ODYSSEY   File: pydev_monkey.py    MIT License 5 votes vote down vote up
def patch_new_process_functions_with_warning():
    monkey_patch_os('execl', create_warn_multiproc)
    monkey_patch_os('execle', create_warn_multiproc)
    monkey_patch_os('execlp', create_warn_multiproc)
    monkey_patch_os('execlpe', create_warn_multiproc)
    monkey_patch_os('execv', create_warn_multiproc)
    monkey_patch_os('execve', create_warn_multiproc)
    monkey_patch_os('execvp', create_warn_multiproc)
    monkey_patch_os('execvpe', create_warn_multiproc)
    monkey_patch_os('spawnl', create_warn_multiproc)
    monkey_patch_os('spawnle', create_warn_multiproc)
    monkey_patch_os('spawnlp', create_warn_multiproc)
    monkey_patch_os('spawnlpe', create_warn_multiproc)
    monkey_patch_os('spawnv', create_warn_multiproc)
    monkey_patch_os('spawnve', create_warn_multiproc)
    monkey_patch_os('spawnvp', create_warn_multiproc)
    monkey_patch_os('spawnvpe', create_warn_multiproc)

    if not IS_JYTHON:
        if not IS_WINDOWS:
            monkey_patch_os('fork', create_warn_multiproc)
            try:
                import _posixsubprocess
                monkey_patch_module(_posixsubprocess, 'fork_exec', create_warn_fork_exec)
            except ImportError:
                pass
        else:
            # Windows
            try:
                import _subprocess
            except ImportError:
                import _winapi as _subprocess
            monkey_patch_module(_subprocess, 'CreateProcess', create_CreateProcessWarnMultiproc) 
Example 24
Project: misp42splunk   Author: remg427   File: external_search_command.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _execute(path, argv, environ):
            if environ is None:
                os.execvp(path, argv)
            else:
                os.execvpe(path, argv, environ)
            return

    # endregion 
Example 25
Project: misp42splunk   Author: remg427   File: external_search_command.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _execute(path, argv, environ):
            if environ is None:
                os.execvp(path, argv)
            else:
                os.execvpe(path, argv, environ)
            return

    # endregion 
Example 26
Project: misp42splunk   Author: remg427   File: external_search_command.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _execute(path, argv, environ):
            if environ is None:
                os.execvp(path, argv)
            else:
                os.execvpe(path, argv, environ)
            return

    # endregion 
Example 27
Project: restrain-jit   Author: thautwarm   File: utils.py    MIT License 5 votes vote down vote up
def exec_cc(cmd, args):
    """
    Execute with current context.
    Yes, you're right -- I'm naming it after call/cc.

    Return a generator.
        The first yielded one is the status of
        the execution of subprocess command.

        The following ones are the the buffer batches of stderr,
        each of which is a Python 'bytes' object
    """
    file = cmd
    err_in, err_out = os.pipe()
    out_in, out_out = os.pipe()
    if os.fork():
        _, status = os.wait()
        os.close(err_out)
        os.close(out_out)
        yield status
        while True:
            load = os.read(err_in, 1024)
            if not load:
                break
            yield load
    else:
        # for child process
        os.close(err_in)
        os.close(out_in)
        os.dup2(err_out, sys.stderr.fileno())
        os.dup2(out_out, sys.stdout.fileno())

        os.execvpe(file, [cmd, *args], dict(os.environ))
        # in case that os.execvp fails
        sys.exit(127) 
Example 28
Project: grip   Author: Eugeny   File: app.py    MIT License 5 votes vote down vote up
def perform_run(self, binary, args):
        if not self.virtualenv:
            ui.error('No virtualenv available')
            sys.exit(1)
        path = os.path.join(self.virtualenv, 'bin', binary)
        if not os.path.exists(path):
            ui.error(path, 'does not exist')
            sys.exit(1)
        os.execvp(path, [binary] + list(args)) 
Example 29
Project: SplunkVersionControl   Author: gjanders   File: external_search_command.py    Apache License 2.0 5 votes vote down vote up
def _execute(path, argv, environ):
            if environ is None:
                os.execvp(path, argv)
            else:
                os.execvpe(path, argv, environ)
            return

    # endregion 
Example 30
Project: lando-api   Author: mozilla-conduit   File: cli.py    Mozilla Public License 2.0 5 votes vote down vote up
def uwsgi():
    """Run the service in production mode with uwsgi."""
    from landoapi.app import SUBSYSTEMS

    for system in SUBSYSTEMS:
        system.ensure_ready()

    logging.shutdown()
    os.execvp("uwsgi", ["uwsgi"]) 
Example 31
Project: lando-api   Author: mozilla-conduit   File: cli.py    Mozilla Public License 2.0 5 votes vote down vote up
def format_code(in_place):
    """Format python code"""
    cmd = ("black",)
    if not in_place:
        cmd = cmd + ("--diff",)
    os.execvp("black", cmd + LINT_PATHS) 
Example 32
Project: lando-api   Author: mozilla-conduit   File: cli.py    Mozilla Public License 2.0 5 votes vote down vote up
def lint():
    """Lint python code with flake8"""
    os.execvp("flake8", ("flake8",) + LINT_PATHS) 
Example 33
Project: lando-api   Author: mozilla-conduit   File: cli.py    Mozilla Public License 2.0 5 votes vote down vote up
def test(pytest_arguments):
    """Run the tests."""
    os.execvp("pytest", ("pytest",) + pytest_arguments) 
Example 34
Project: talks   Author: theycallmemac   File: sesh.py    GNU General Public License v3.0 5 votes vote down vote up
def launch(args): 
    pid = os.fork()
    if pid > 0:
        wpid = os.waitpid(pid, 0)
    else:
        try:
            os.execvp(args[0], args)
        except Exception as e:
            print("sesh: command not found: " + args[0]) 
Example 35
Project: talks   Author: theycallmemac   File: 1.py    GNU General Public License v3.0 5 votes vote down vote up
def main():
    # get the user's login name, the name of the machine they are on and their current working directory 
    USER = getpass.getuser()
    HOST = socket.gethostname()
    PWD = os.getcwd()

    # read a single line of input to be tokenized. 
    # place your custom prompt in the input parenthesis
    line = input("\n" + USER + " in " + HOST + " at " + PWD + " --> ").strip()

    # tokenize input by using split
    args = line.split()

    # time to execute your input
    # use os.fork to get the process ID
    pid = os.fork()

    # if pid > 0 -> Parent process control
    # else -> Child process control
    if pid > 0:
        wpid = os.waitpid(pid, 0)
    else:
        # try to execeute in the form (command, command_args)
        # generate exception if command does not exist
        try:
            os.execvp(args[0], args)
        except Exception as e:
            print("sesh: command not found: " + args[0]) 
Example 36
Project: bobbit-ng   Author: pbui   File: restart.py    MIT License 5 votes vote down vote up
def restart_command(bot, nick, message, channel, question=None):
    if hasattr(nick, 'prefix') or nick not in bot.owners:
        return

    bot.logger.debug('Restart initiated by %s', nick)
    bot.tcp_stream.close()
    time.sleep(RESTART_TIMEOUT)
    os.execvp(sys.argv[0], sys.argv)

# Register 
Example 37
Project: grand_central   Author: amiracle   File: external_search_command.py    MIT License 5 votes vote down vote up
def _execute(path, argv, environ):
            if environ is None:
                os.execvp(path, argv)
            else:
                os.execvpe(path, argv, environ)
            return

    # endregion 
Example 38
Project: SplunkForPCAP   Author: DanielSchwartz1   File: external_search_command.py    MIT License 5 votes vote down vote up
def _execute(path, argv, environ):
            if environ is None:
                os.execvp(path, argv)
            else:
                os.execvpe(path, argv, environ)
            return

    # endregion 
Example 39
Project: TESTGIT   Author: B-ROY   File: client.py    Apache License 2.0 5 votes vote down vote up
def runshell(self):
        settings_dict = self.connection.settings_dict
        args = [self.executable_name]
        if settings_dict['USER']:
            args += ["-U", settings_dict['USER']]
        if settings_dict['HOST']:
            args.extend(["-h", settings_dict['HOST']])
        if settings_dict['PORT']:
            args.extend(["-p", str(settings_dict['PORT'])])
        args += [settings_dict['NAME']]
        if os.name == 'nt':
            sys.exit(os.system(" ".join(args)))
        else:
            os.execvp(self.executable_name, args) 
Example 40
Project: TESTGIT   Author: B-ROY   File: client.py    Apache License 2.0 5 votes vote down vote up
def runshell(self):
        args = [self.executable_name,
                self.connection.settings_dict['NAME']]
        if os.name == 'nt':
            sys.exit(os.system(" ".join(args)))
        else:
            os.execvp(self.executable_name, args) 
Example 41
Project: TESTGIT   Author: B-ROY   File: client.py    Apache License 2.0 5 votes vote down vote up
def runshell(self):
        conn_string = self.connection._connect_string()
        args = [self.executable_name, "-L", conn_string]
        if os.name == 'nt':
            sys.exit(os.system(" ".join(args)))
        else:
            os.execvp(self.executable_name, args) 
Example 42
Project: TESTGIT   Author: B-ROY   File: client.py    Apache License 2.0 5 votes vote down vote up
def runshell(self):
        settings_dict = self.connection.settings_dict
        args = [self.executable_name]
        db = settings_dict['OPTIONS'].get('db', settings_dict['NAME'])
        user = settings_dict['OPTIONS'].get('user', settings_dict['USER'])
        passwd = settings_dict['OPTIONS'].get('passwd', settings_dict['PASSWORD'])
        host = settings_dict['OPTIONS'].get('host', settings_dict['HOST'])
        port = settings_dict['OPTIONS'].get('port', settings_dict['PORT'])
        defaults_file = settings_dict['OPTIONS'].get('read_default_file')
        # Seems to be no good way to set sql_mode with CLI.

        if defaults_file:
            args += ["--defaults-file=%s" % defaults_file]
        if user:
            args += ["--user=%s" % user]
        if passwd:
            args += ["--password=%s" % passwd]
        if host:
            if '/' in host:
                args += ["--socket=%s" % host]
            else:
                args += ["--host=%s" % host]
        if port:
            args += ["--port=%s" % port]
        if db:
            args += [db]

        if os.name == 'nt':
            sys.exit(os.system(" ".join(args)))
        else:
            os.execvp(self.executable_name, args) 
Example 43
Project: AneMo   Author: jspargo   File: client.py    GNU General Public License v2.0 5 votes vote down vote up
def runshell(self):
        settings_dict = self.connection.settings_dict
        args = [self.executable_name]
        if settings_dict['USER']:
            args += ["-U", settings_dict['USER']]
        if settings_dict['HOST']:
            args.extend(["-h", settings_dict['HOST']])
        if settings_dict['PORT']:
            args.extend(["-p", str(settings_dict['PORT'])])
        args += [settings_dict['NAME']]
        if os.name == 'nt':
            sys.exit(os.system(" ".join(args)))
        else:
            os.execvp(self.executable_name, args) 
Example 44
Project: AneMo   Author: jspargo   File: client.py    GNU General Public License v2.0 5 votes vote down vote up
def runshell(self):
        args = [self.executable_name,
                self.connection.settings_dict['NAME']]
        if os.name == 'nt':
            sys.exit(os.system(" ".join(args)))
        else:
            os.execvp(self.executable_name, args) 
Example 45
Project: AneMo   Author: jspargo   File: client.py    GNU General Public License v2.0 5 votes vote down vote up
def runshell(self):
        conn_string = self.connection._connect_string()
        args = [self.executable_name, "-L", conn_string]
        if os.name == 'nt':
            sys.exit(os.system(" ".join(args)))
        else:
            os.execvp(self.executable_name, args) 
Example 46
Project: AneMo   Author: jspargo   File: client.py    GNU General Public License v2.0 5 votes vote down vote up
def runshell(self):
        settings_dict = self.connection.settings_dict
        args = [self.executable_name]
        db = settings_dict['OPTIONS'].get('db', settings_dict['NAME'])
        user = settings_dict['OPTIONS'].get('user', settings_dict['USER'])
        passwd = settings_dict['OPTIONS'].get('passwd', settings_dict['PASSWORD'])
        host = settings_dict['OPTIONS'].get('host', settings_dict['HOST'])
        port = settings_dict['OPTIONS'].get('port', settings_dict['PORT'])
        defaults_file = settings_dict['OPTIONS'].get('read_default_file')
        # Seems to be no good way to set sql_mode with CLI.

        if defaults_file:
            args += ["--defaults-file=%s" % defaults_file]
        if user:
            args += ["--user=%s" % user]
        if passwd:
            args += ["--password=%s" % passwd]
        if host:
            if '/' in host:
                args += ["--socket=%s" % host]
            else:
                args += ["--host=%s" % host]
        if port:
            args += ["--port=%s" % port]
        if db:
            args += [db]

        if os.name == 'nt':
            sys.exit(os.system(" ".join(args)))
        else:
            os.execvp(self.executable_name, args) 
Example 47
Project: aws-roleshell   Author: hashbrowncipher   File: aws_roleshell.py    MIT License 5 votes vote down vote up
def run_command(environment_overrides, command):
    for var, value in environment_overrides.items():
        if value is not None:
            os.environ[var] = environment_overrides[var]
        elif var in os.environ:
            del os.environ[var]

    # TODO: use a copy of the environment with variables deleted, to support
    # platforms without unsetenv() support.
    os.execvp(command[0], command) 
Example 48
Project: dockerizeme   Author: dockerizeme   File: snippet.py    Apache License 2.0 5 votes vote down vote up
def dbshell():
    db = DATABASES['mydb']
    args = ["psql", "--host=%s" % db['HOST'], "--user=%s" % db['USER'],
            "--dbname=%s" % db['NAME']]
    os.execvp("psql", args) 
Example 49
Project: dockerizeme   Author: dockerizeme   File: snippet.py    Apache License 2.0 5 votes vote down vote up
def run(self, *args, **kwargs):
        run_args = sys.argv[2:]
        run_args.append('manage:app')
        os.execvp('gunicorn', [''] + run_args) 
Example 50
Project: poetry   Author: python-poetry   File: env.py    MIT License 5 votes vote down vote up
def execute(self, bin, *args, **kwargs):
        bin = self._bin(bin)

        if not self._is_windows:
            args = [bin] + list(args)
            if "env" in kwargs:
                return os.execvpe(bin, args, kwargs["env"])
            else:
                return os.execvp(bin, args)
        else:
            exe = subprocess.Popen([bin] + list(args), **kwargs)
            exe.communicate()
            return exe.returncode