• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.sysexit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中molecule.util.sysexit函数的典型用法代码示例。如果您正苦于以下问题:Python sysexit函数的具体用法?Python sysexit怎么用?Python sysexit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sysexit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: idempotence

def idempotence(ctx, platform, provider):  # pragma: no cover
    """ Provisions instances and parses output to determine idempotence. """
    command_args = {"platform": platform, "provider": provider}

    i = Idempotence(ctx.obj.get("args"), command_args)
    i.execute
    util.sysexit(i.execute()[0])
开发者ID:cimarron-pistoncloud,项目名称:molecule,代码行数:7,代码来源:idempotence.py


示例2: execute

    def execute(self, exit=True):
        """
        Execute the actions necessary to perform a `molecule init` and exit.

        :param exit: (Unused) Provided to complete method signature.
        :return: None
        """
        role = self.command_args.get('role')
        role_path = os.getcwd()
        driver = self._get_driver()
        verifier = self._get_verifier()
        if not role:
            role = os.getcwd().split(os.sep)[-1]
            role_path = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
            self._init_existing_role(role, role_path, driver, verifier)
        else:
            if os.path.isdir(role):
                msg = 'The directory {} exists. Cannot create new role.'
                LOG.error(msg.format(role))
                util.sysexit()
            self._init_new_role(role, role_path, driver, verifier)

        msg = 'Successfully initialized new role in {} ...'
        util.print_success(msg.format(os.path.join(role_path, role)))
        util.sysexit(0)
开发者ID:sebinjohn,项目名称:molecule,代码行数:25,代码来源:init.py


示例3: test

def test(ctx, scenario_name, driver_name, __all, destroy):  # pragma: no cover
    """ Test (destroy, create, converge, lint, verify, destroy). """
    args = ctx.obj.get('args')
    subcommand = base._get_subcommand(__name__)
    command_args = {
        'subcommand': subcommand,
        'driver_name': driver_name,
    }

    if __all:
        scenario_name = None

    s = scenarios.Scenarios(
        base.get_configs(args, command_args), scenario_name)
    s.print_matrix()
    for scenario in s:
        try:
            for term in scenario.sequence:
                base.execute_subcommand(scenario.config, term)
        except SystemExit:
            if destroy == 'always':
                msg = ('An error occured during the test sequence.  '
                       'Cleaning up.')
                LOG.warn(msg)
                base.execute_subcommand(scenario.config, 'destroy')
                util.sysexit()
            raise
开发者ID:kireledan,项目名称:molecule,代码行数:27,代码来源:test.py


示例4: execute

    def execute(self, exit=True):
        """
        Execute the actions necessary to perform a `molecule verify` and
        return a tuple.

        :param exit: An optional flag to toggle the exiting of the module
         on command failure.
        :return: Return a tuple of None, otherwise sys.exit on command failure.
        """
        try:
            v = ansible_lint.AnsibleLint(self.molecule)
            v.execute()
        except sh.ErrorReturnCode_2:
            util.sysexit()
        v = trailing.Trailing(self.molecule)
        v.execute()

        self.molecule.write_ssh_config()

        try:
            if self.molecule.verifier == 'serverspec':
                v = serverspec.Serverspec(self.molecule)
            elif self.molecule.verifier == 'goss':
                v = goss.Goss(self.molecule)
            else:
                v = testinfra.Testinfra(self.molecule)

            v.execute()
        except sh.ErrorReturnCode as e:
            LOG.error('ERROR: {}'.format(e))
            if exit:
                util.sysexit(e.exit_code)
            return e.exit_code, e.stdout

        return None, None
开发者ID:cimarron-pistoncloud,项目名称:molecule,代码行数:35,代码来源:verify.py


示例5: verify

def verify(ctx, platform, provider, sudo):  # pragma: no cover
    """ Performs verification steps on running instances. """
    command_args = {'platform': platform, 'provider': provider, 'sudo': sudo}

    v = Verify(ctx.obj.get('args'), command_args)
    v.execute
    util.sysexit(v.execute()[0])
开发者ID:cimarron-pistoncloud,项目名称:molecule,代码行数:7,代码来源:verify.py


示例6: _rake

    def _rake(self,
              rakefile,
              debug=False,
              out=util.callback_info,
              err=util.callback_error):
        """
        Executes rake against specified rakefile and returns a :func:`sh`
        response object.

        :param rakefile: A string containing path to the rakefile.
        :param debug: An optional bool to toggle debug output.
        :param out: An optional function to process STDOUT for underlying
         :func:`sh` call.
        :param err: An optional function to process STDERR for underlying
         :func:`sh` call.
        :return: :func:`sh` response object.
        """
        kwargs = {
            '_out': out,
            '_err': err,
            'trace': debug,
            'rakefile': rakefile
        }

        msg = 'Executing serverspec tests found in {}/...'.format(
            self._serverspec_dir)
        util.print_info(msg)

        try:
            cmd = sh.rake.bake(**kwargs)
        except sh.CommandNotFound:
            msg = 'Verifier missing, gem install rake.'
            util.print_error(msg)
            util.sysexit()
        return util.run_command(cmd, debug=self._debug)
开发者ID:davidfischer-ch,项目名称:molecule,代码行数:35,代码来源:serverspec.py


示例7: list

def list(ctx, porcelain):  # pragma: no cover
    """ Prints a list of currently available platforms. """
    command_args = {'porcelain': porcelain}

    l = List(ctx.obj.get('args'), command_args)
    l.execute
    util.sysexit(l.execute()[0])
开发者ID:davidfischer-ch,项目名称:molecule,代码行数:7,代码来源:list.py


示例8: _rubocop

    def _rubocop(self,
                 serverspec_dir,
                 debug=False,
                 pattern='/**/*.rb',
                 out=util.callback_info,
                 err=util.callback_error):
        """
        Executes rubocop against specified directory/pattern and returns a
        :func:`sh` response object.

        :param serverspec_dir: A string containing the directory with files
        to lint.
        :param debug: An optional bool to toggle debug output.
        :param pattern: A string containing the pattern of files to lint.
        :param out: An optional function to process STDOUT for underlying
         :func:`sh` call.
        :param err: An optional function to process STDERR for underlying
         :func:`sh` call.
        :return: :func:`sh` response object.
        """
        kwargs = {'_out': out, '_err': err, 'debug': debug}

        msg = 'Executing rubocop on *.rb files found in {}/...'.format(
            serverspec_dir)
        util.print_info(msg)
        match = serverspec_dir + pattern

        try:
            cmd = sh.rubocop.bake(match, **kwargs)
        except sh.CommandNotFound:
            msg = 'Verifier missing, gem install rubocop.'
            util.print_error(msg)
            util.sysexit()
        return util.run_command(cmd, debug=self._debug)
开发者ID:davidfischer-ch,项目名称:molecule,代码行数:34,代码来源:serverspec.py


示例9: execute

    def execute(self, exit=True):
        util.print_info(
            'Idempotence test in progress (can take a few minutes)...')

        c = converge.Converge(self.command_args, self.args, self.molecule)
        status, output = c.execute(idempotent=True,
                                   exit=False,
                                   hide_errors=True)
        if status is not None:
            msg = 'Skipping due to errors during converge.'
            util.print_info(msg)
            return status, None

        idempotent, changed_tasks = self.molecule._parse_provisioning_output(
            output)

        if idempotent:
            util.print_success('Idempotence test passed.')
            return None, None

        # Display the details of the idempotence test.
        if changed_tasks:
            LOG.error(
                'Idempotence test failed because of the following tasks:')
            LOG.error('{}'.format('\n'.join(changed_tasks)))
        else:
            # But in case the idempotence callback plugin was not found, we just display an error message.
            LOG.error('Idempotence test failed.')
            warning_msg = "The idempotence plugin was not found or did not provide the required information. " \
                          "Therefore the failure details cannot be displayed."

            LOG.warning(warning_msg)
        if exit:
            util.sysexit()
        return 1, None
开发者ID:russ216,项目名称:molecule,代码行数:35,代码来源:idempotence.py


示例10: execute

    def execute(self):
        if not self.enabled:
            msg = 'Skipping, verifier is disabled.'
            LOG.warn(msg)
            return

        if not len(self._tests) > 0:
            msg = 'Skipping, no tests found.'
            LOG.warn(msg)
            return

        if self._testinfra_command is None:
            self.bake()

        msg = 'Executing Testinfra tests found in {}/...'.format(
            self.directory)
        LOG.info(msg)

        try:
            util.run_command(self._testinfra_command, debug=self._config.debug)
            msg = 'Verifier completed successfully.'
            LOG.success(msg)

        except sh.ErrorReturnCode as e:
            util.sysexit(e.exit_code)
开发者ID:kireledan,项目名称:molecule,代码行数:25,代码来源:testinfra.py


示例11: execute

    def execute(self, exit=True):
        """
        Execute the actions necessary to perform a `molecule create` and
        return a tuple.

        :param exit: An optional flag to toggle the exiting of the module
         on command failure.
        :return: Return a tuple of None, otherwise sys.exit on command failure.
        """
        self.molecule.remove_inventory_file()
        self.molecule.create_templates()
        try:
            util.print_info('Creating instances...')
            self.molecule.driver.up(no_provision=True)
            self.molecule.state.change_state('created', True)
            if self.command_args.get('platform') == 'all':
                self.molecule.state.change_state('multiple_platforms', True)
        except subprocess.CalledProcessError as e:
            util.print_error(str(e))
            if exit:
                util.sysexit(e.returncode)
            return e.returncode, e.message
        self.molecule.create_inventory_file()
        self.molecule.write_instances_state()
        return None, None
开发者ID:davidfischer-ch,项目名称:molecule,代码行数:25,代码来源:create.py


示例12: execute

    def execute(self, exit=True):
        """
        Execute the actions necessary to perform a `molecule check` and
        return a tuple.

        :param exit: (Unused) Provided to complete method signature.
        :return: Return a tuple provided by :meth:`.AnsiblePlaybook.execute`.
        """
        if not self.molecule.state.created:
            msg = ('Instance(s) not created, `check` should be run '
                   'against created instance(s).')
            util.print_error(msg)
            util.sysexit()

        debug = self.args.get('debug')
        ansible = ansible_playbook.AnsiblePlaybook(
            self.molecule.config.config['ansible'],
            self.molecule.driver.ansible_connection_params,
            debug=debug)
        ansible.add_cli_arg('check', True)

        util.print_info("Performing a 'Dry Run' of playbook...")
        return ansible.execute(hide_errors=True)

        return (None, None)
开发者ID:davidfischer-ch,项目名称:molecule,代码行数:25,代码来源:check.py


示例13: execute

    def execute(self, exit=True):  # pragma: no cover
        """
        Executes trailing linters, and returns None, otherwise sys.exit on
        command failure.

        :return: None
        :param ignore_paths: List of paths to ignore during checks.
        :return: None, otherwise sys.exit on command failure.
        """
        filenames = []
        pruned_filenames = []
        found_error = False
        valid_extensions = ['py', 'yml', 'rb']
        for root, dirs, files in os.walk('.'):
            # gets ./subdirectory/filename
            filenames.extend(
                [os.path.join(root, name) for name in files
                 if name.split(os.extsep)[-1] in valid_extensions])
            # gets ./filename
            filenames.extend(
                [os.path.join(root, name) for name in dirs
                 if name.split(os.extsep)[-1] in valid_extensions])

        # only work on files not in our ignore paths
        for f in filenames:
            f_parts = f.split(os.sep)

            try:
                if f_parts[1] in self._ignore_paths:
                    continue
            except IndexError:
                continue

            # don't add directories
            if os.path.isfile(f):
                pruned_filenames.append(f)

        for filename in pruned_filenames:
            # don't process blank files
            if os.path.getsize(filename) < 1:
                continue

            data = [line for line in open(filename, 'r')]
            newline = self._trailing_newline(data)
            whitespace = self._trailing_whitespace(data)

            if newline:
                msg = 'Trailing newline found at the end of {}'
                LOG.error(msg.format(filename))
                found_error = True

            if len(whitespace) > 0:
                msg = 'Trailing whitespace found in {} on lines: {}'
                lines = ', '.join(str(x) for x in whitespace)
                LOG.error(msg.format(filename,
                                     lines, ))
                found_error = True

        if exit and found_error:
            util.sysexit()
开发者ID:cimarron-pistoncloud,项目名称:molecule,代码行数:60,代码来源:trailing.py


示例14: execute

    def execute(self, exit=True):
        """
        Execute the actions necessary to perform a `molecule idempotence` and
        return a tuple.

        :param exit: An optional flag to toggle the exiting of the module
         on command failure.
        :return: Return a tuple of (`exit status`, `command output`), otherwise
         sys.exit on command failure.
        """
        util.print_info("Idempotence test in progress (can take a few minutes) ...")

        c = converge.Converge(self.command_args, self.args, self.molecule)
        status, output = c.execute(idempotent=True, exit=False, hide_errors=True)
        if status is not None:
            msg = "Skipping due to errors during converge."
            util.print_info(msg)
            return status, None

        idempotent = self._is_idempotent(output)
        if idempotent:
            util.print_success("Idempotence test passed.")
            return None, None
        else:
            LOG.error("Idempotence test failed because of the following tasks:")
            LOG.error("\n".join(self._non_idempotent_tasks(output)))
            if exit:
                util.sysexit()

            return 1, None
开发者ID:cimarron-pistoncloud,项目名称:molecule,代码行数:30,代码来源:idempotence.py


示例15: execute

    def execute(self, exit=True):
        """
        Recursively finds all files relative to CWD, and checks them for
        trailing whitespace and newlines.

        :param ignore_paths: list of paths to ignore during checks
        :return: A ``sys.exit`` code if found an error, otherwise None
        """
        filenames = []
        pruned_filenames = []
        found_error = False
        valid_extensions = ['py', 'yml', 'rb']
        for root, dirs, files in os.walk('.'):
            # gets ./subdirectory/filename
            filenames.extend(
                [os.path.join(root, name) for name in files
                 if name.split(os.extsep)[-1] in valid_extensions])
            # gets ./filename
            filenames.extend(
                [os.path.join(root, name) for name in dirs
                 if name.split(os.extsep)[-1] in valid_extensions])

        # only work on files not in our ignore paths
        for f in filenames:
            f_parts = f.split(os.sep)

            try:
                if f_parts[1] in self._ignore_paths:
                    continue
            except IndexError:
                continue

            # don't add directories
            if os.path.isfile(f):
                pruned_filenames.append(f)

        for filename in pruned_filenames:
            # don't process blank files
            if os.path.getsize(filename) < 1:
                continue

            data = [line for line in open(filename, 'r')]
            newline = self._trailing_newline(data)
            whitespace = self._trailing_whitespace(data)

            if newline:
                msg = 'Trailing newline found at the end of {}'
                LOG.error(msg.format(filename))
                found_error = True

            if whitespace:
                msg = 'Trailing whitespace found in {} on lines: {}'
                lines = ', '.join(str(x) for x in whitespace)
                LOG.error(msg.format(filename,
                                     lines, ))
                found_error = True

        if exit and found_error:
            util.sysexit()
开发者ID:russ216,项目名称:molecule,代码行数:59,代码来源:trailing.py


示例16: init

def init(ctx, role, driver, verifier):  # pragma: no cover
    """
    Creates the scaffolding for a new role intended for use with molecule.
    """
    command_args = {'role': role, 'driver': driver, 'verifier': verifier}

    i = Init(ctx.obj.get('args'), command_args)
    i.execute
    util.sysexit(i.execute()[0])
开发者ID:sebinjohn,项目名称:molecule,代码行数:9,代码来源:init.py


示例17: destroy

def destroy(ctx, driver, platform, provider):  # pragma: no cover
    """ Destroys all instances created by molecule. """
    command_args = {'driver': driver,
                    'platform': platform,
                    'provider': provider}

    d = Destroy(ctx.obj.get('args'), command_args)
    d.execute
    util.sysexit(d.execute()[0])
开发者ID:cimarron-pistoncloud,项目名称:molecule,代码行数:9,代码来源:destroy.py


示例18: create

def create(ctx, driver, platform, provider):  # pragma: no cover
    """ Creates all instances defined in molecule.yml. """
    command_args = {'driver': driver,
                    'platform': platform,
                    'provider': provider}

    c = Create(ctx.obj.get('args'), command_args)
    c.execute
    util.sysexit(c.execute()[0])
开发者ID:cimarron-pistoncloud,项目名称:molecule,代码行数:9,代码来源:create.py


示例19: converge

def converge(ctx, driver, platform, provider, tags):  # pragma: no cover
    """ Provisions all instances defined in molecule.yml. """
    command_args = {'driver': driver,
                    'platform': platform,
                    'provider': provider,
                    'tags': tags}

    c = Converge(ctx.obj.get('args'), command_args)
    c.execute
    util.sysexit(c.execute()[0])
开发者ID:cimarron-pistoncloud,项目名称:molecule,代码行数:10,代码来源:converge.py


示例20: execute

    def execute(self):
        """
        Executes Goss integration tests and returns None.

        :return: None
        """
        if self._get_tests():
            status, output = self._goss()
            if status is not None:
                util.sysexit(status)
开发者ID:davidfischer-ch,项目名称:molecule,代码行数:10,代码来源:goss.py



注:本文中的molecule.util.sysexit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utilities.merge_dicts函数代码示例发布时间:2022-05-27
下一篇:
Python util.print_info函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap