当前位置: 首页>>代码示例>>Python>>正文


Python utils.LOG类代码示例

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


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

示例1: diff

def diff(content_old, content_new, filename, encoding_hint=None):
    output = ""
    LOG.debug("diffing {filename}: {len_before} B before, {len_after} B after".format(
        filename=filename,
        len_before=len(content_old),
        len_after=len(content_new),
    ))
    content_old = force_text(content_old)
    content_new = force_text(content_new)
    start = datetime.now()
    for line in unified_diff(
        content_old.splitlines(True),
        content_new.splitlines(True),
        fromfile=filename,
        tofile=_("<bundlewrap content>"),
    ):
        suffix = ""
        line = force_text(line).rstrip("\n")
        if len(line) > DIFF_MAX_LINE_LENGTH:
            line = line[:DIFF_MAX_LINE_LENGTH]
            suffix += _(" (line truncated after {} characters)").format(DIFF_MAX_LINE_LENGTH)
        if line.startswith("+"):
            line = green(line)
        elif line.startswith("-"):
            line = red(line)
        output += line + suffix + "\n"
    duration = datetime.now() - start
    LOG.debug("diffing {file}: complete after {time}s".format(
        file=filename,
        time=duration.total_seconds(),
    ))
    return output
开发者ID:jrragan,项目名称:bundlewrap,代码行数:32,代码来源:files.py

示例2: node_apply_end

def node_apply_end(repo, node, duration=None, interactive=None, result=None, **kwargs):
    if environ.get('TERM_PROGRAM', None) != "iTerm.app" or not interactive:
        LOG.debug("skipping iTerm stats (wrong terminal)")
        return

    if not IMPORTS:
        LOG.error("failed to import dependencies of itermstats plugin")
        return

    css_file = NamedTemporaryFile(delete=False)
    css_file.write(".text-overlay { display: none; }")
    css_file.close()

    config = Config(
        height=150,
        style=STYLE,
        width=350,
    )
    config.css.append(css_file.name)

    chart = Pie(config)
    chart.add('correct', result.correct)
    chart.add('fixed', result.fixed)
    chart.add('skipped', result.skipped)
    chart.add('failed', result.failed)

    png_data = cairosvg.svg2png(bytestring=chart.render())
    png_data_b64 = b64encode(png_data)

    remove(css_file.name)

    print("\033]1337;File=inline=1:{}\007".format(png_data_b64))
开发者ID:bundlewrap,项目名称:plugins,代码行数:32,代码来源:itermstats.py

示例3: _write_local_file

    def _write_local_file(self):
        """
        Makes the file contents available at the returned temporary path
        and performs local verification if necessary or requested.

        The calling method is responsible for cleaning up the file at
        the returned path (only if not a binary).
        """
        if self.attributes['content_type'] == 'binary':
            local_path = self.template
        else:
            handle, local_path = mkstemp()
            with open(local_path, 'wb') as f:
                f.write(self.content)

        if self.attributes['verify_with']:
            cmd = self.attributes['verify_with'].format(quote(local_path))
            LOG.debug("calling local verify command for {i}: {c}".format(c=cmd, i=self.id))
            if call(cmd, shell=True) == 0:
                LOG.debug("{i} passed local validation".format(i=self.id))
            else:
                raise BundleError(_(
                    "{i} failed local validation using: {c}"
                ).format(c=cmd, i=self.id))

        return local_path
开发者ID:jrragan,项目名称:bundlewrap,代码行数:26,代码来源:files.py

示例4: apply

    def apply(self, interactive=False, interactive_default=True):
        self.node.repo.hooks.item_apply_start(
            self.node.repo,
            self.node,
            self,
        )
        status_code = None
        status_before = None
        status_after = None
        start_time = datetime.now()

        if self.triggered and not self.has_been_triggered:
            LOG.debug(_("skipping {} because it wasn't triggered").format(self.id))
            status_code = self.STATUS_SKIPPED

        if status_code is None and self.cached_unless_result:
            LOG.debug(_("'unless' for {} succeeded, not fixing").format(self.id))
            status_code = self.STATUS_SKIPPED

        if status_code is None:
            status_before = self.cached_status
            if status_before.correct:
                status_code = self.STATUS_OK

        if status_code is None:
            if not interactive:
                self.fix(status_before)
                status_after = self.get_status()
            else:
                question = wrap_question(
                    self.id,
                    self.ask(status_before),
                    _("Fix {}?").format(bold(self.id)),
                )
                if ask_interactively(question,
                                     interactive_default):
                    self.fix(status_before)
                    status_after = self.get_status()
                else:
                    status_code = self.STATUS_SKIPPED

        if status_code is None:
            if status_after.correct:
                status_code = self.STATUS_FIXED
            else:
                status_code = self.STATUS_FAILED

        self.node.repo.hooks.item_apply_end(
            self.node.repo,
            self.node,
            self,
            duration=datetime.now() - start_time,
            status_code=status_code,
            status_before=status_before,
            status_after=status_after,
        )

        return status_code
开发者ID:bkendinibilir,项目名称:bundlewrap,代码行数:58,代码来源:__init__.py

示例5: fix

 def fix(self, status):
     if self.attributes['running'] is False:
         LOG.info(_("{node}:{bundle}:{item}: stopping...").format(
             bundle=self.bundle.name,
             item=self.id,
             node=self.node.name,
         ))
         svc_stop(self.node, self.name)
     else:
         LOG.info(_("{node}:{bundle}:{item}: starting...").format(
             bundle=self.bundle.name,
             item=self.id,
             node=self.node.name,
         ))
         svc_start(self.node, self.name)
开发者ID:mfriedenhagen,项目名称:bundlewrap,代码行数:15,代码来源:svc_systemv.py

示例6: _create_config

def _create_config(path):
    LOG.debug("writing initial config for Slack notifications to .slack.cfg")
    config = SafeConfigParser()
    config.add_section("configuration")
    config.set("configuration", "enabled", "unconfigured")
    config.set("configuration", "username", "your-slack-username")
    config.add_section("connection")
    config.set("connection", "url",
               "<insert URL from https://my.slack.com/services/new/incoming-webhook>")
    config.add_section("apply_notifications")
    config.set("apply_notifications", "enabled", "yes")
    config.set("apply_notifications", "allow_groups", "all")
    config.set("apply_notifications", "deny_groups", "local")
    with open(path, 'wb') as f:
        config.write(f)
开发者ID:rhazdon,项目名称:plugins,代码行数:15,代码来源:notify_slack.py

示例7: fix

 def fix(self, status):
     if self.attributes['installed'] is False:
         LOG.info(_("{node}:{bundle}:{item}: removing...").format(
             bundle=self.bundle.name,
             item=self.id,
             node=self.node.name,
         ))
         pkg_remove(self.node, self.name)
     else:
         LOG.info(_("{node}:{bundle}:{item}: installing...").format(
             bundle=self.bundle.name,
             item=self.id,
             node=self.node.name,
         ))
         pkg_install(self.node, self.name)
开发者ID:mfriedenhagen,项目名称:bundlewrap,代码行数:15,代码来源:pkg_apt.py

示例8: _create_config

def _create_config(path):
    LOG.debug("writing initial config for HipChat notifications to .hipchat_secrets.cfg")
    config = SafeConfigParser()
    config.add_section("configuration")
    config.set("configuration", "enabled", "unconfigured")
    config.add_section("connection")
    config.set("connection", "server", "api.hipchat.com")
    config.set("connection", "token", "<insert token from https://www.hipchat.com/account/api>")
    config.add_section("apply_notifications")
    config.set("apply_notifications", "enabled", "yes")
    config.set("apply_notifications", "rooms", "name_or_id_of_room1,name_or_id_of_room2")
    config.add_section("item_notifications")
    config.set("item_notifications", "enabled", "no")
    config.set("item_notifications", "rooms", "name_or_id_of_room1,name_or_id_of_room2")
    with open(path, 'wb') as f:
        config.write(f)
开发者ID:bundlewrap,项目名称:plugins,代码行数:16,代码来源:notify_hipchat.py

示例9: apply_end

def apply_end(repo, target, nodes, duration=None, **kwargs):
    config = _get_config(repo.path)
    if config is None or \
            not config.has_section("apply_notifications") or \
            not config.getboolean("apply_notifications", "enabled"):
        return
    for room in config.get("apply_notifications", "rooms").split(","):
        LOG.debug("posting apply end notification to HipChat room {room}@{server}".format(
            room=room,
            server=config.get("connection", "server"),
        ))
        _notify(
            config.get("connection", "server"),
            room.strip(),
            config.get("connection", "token"),
            "Finished bw apply on <b>{target}</b>.".format(target=target),
            "html",
        )
开发者ID:bundlewrap,项目名称:plugins,代码行数:18,代码来源:notify_hipchat.py

示例10: diff

def diff(content_old, content_new, filename, encoding_hint=None):
    output = ""
    LOG.debug("diffing {filename}: {len_before} B before, {len_after} B after".format(
        filename=filename,
        len_before=len(content_old),
        len_after=len(content_new),
    ))
    start = datetime.now()
    for line in unified_diff(
        content_old.splitlines(True),
        content_new.splitlines(True),
        fromfile=filename,
        tofile=_("<bundlewrap content>"),
    ):
        suffix = ""
        try:
            line = line.decode('utf-8')
        except UnicodeDecodeError:
            if encoding_hint and encoding_hint.lower() != "utf-8":
                try:
                    line = line.decode(encoding_hint)
                    suffix += _(" (line encoded in {})").format(encoding_hint)
                except UnicodeDecodeError:
                    line = line[0]
                    suffix += _(" (line not encoded in UTF-8 or {})").format(encoding_hint)
            else:
                line = line[0]
                suffix += _(" (line not encoded in UTF-8)")

        line = line.rstrip("\n")
        if len(line) > DIFF_MAX_LINE_LENGTH:
            line = line[:DIFF_MAX_LINE_LENGTH]
            suffix += _(" (line truncated after {} characters)").format(DIFF_MAX_LINE_LENGTH)
        if line.startswith("+"):
            line = green(line)
        elif line.startswith("-"):
            line = red(line)
        output += line + suffix + "\n"
    duration = datetime.now() - start
    LOG.debug("diffing {file}: complete after {time}s".format(
        file=filename,
        time=duration.total_seconds(),
    ))
    return output
开发者ID:mfriedenhagen,项目名称:bundlewrap,代码行数:44,代码来源:files.py

示例11: apply_end

def apply_end(repo, target, nodes, duration=None, **kwargs):
    config = _get_config(repo.path)
    if config is None or \
            not config.has_section("apply_notifications") or \
            not config.getboolean("apply_notifications", "enabled") or \
            not _check_allowed_groups(config, nodes):
        return
    LOG.debug("posting apply end notification to Slack")
    _notify(
        config.get("connection", "url"),
        color="good",
        fallback="Finished bw apply to {target} as {user} after {duration}s.".format(
            duration=duration.total_seconds(),
            target=target,
            user=config.get("configuration", "username"),
        ),
        target=target,
        title="Finished bw apply after {}s.".format(duration.total_seconds()),
        user=config.get("configuration", "username"),
    )
开发者ID:rhazdon,项目名称:plugins,代码行数:20,代码来源:notify_slack.py

示例12: _notify

def _notify(server, room, token, message, message_format, color="gray"):
    try:
        post(
            "https://{server}/v2/room/{room}/notification?auth_token={token}".format(
                token=token,
                room=room,
                server=server,
            ),
            headers={
                'content-type': 'application/json',
            },
            data=dumps({
                'color': color,
                'message': message,
                'message_format': message_format,
                'notify': True,
            }),
        )
    except ConnectionError as e:
        LOG.error("Failed to submit HipChat notification: {}".format(e))
开发者ID:bundlewrap,项目名称:plugins,代码行数:20,代码来源:notify_hipchat.py

示例13: apply_start

def apply_start(repo, target, nodes, interactive=False, **kwargs):
    config = _get_config(repo.path)
    if config is None or \
            not config.has_section("apply_notifications") or \
            not config.getboolean("apply_notifications", "enabled") or \
            not _check_allowed_groups(config, nodes):
        return
    LOG.debug("posting apply start notification to Slack")
    _notify(
        config.get("connection", "url"),
        fallback="Starting bw apply to {target} as {user}".format(
            target=target,
            user=config.get("configuration", "username"),
        ),
        target=target,
        title=(
            "Starting {interactive}interactive bw apply..."
        ).format(interactive="non-" if not interactive else ""),
        user=config.get("configuration", "username"),
    )
开发者ID:rhazdon,项目名称:plugins,代码行数:20,代码来源:notify_slack.py

示例14: _get_result

    def _get_result(self, interactive=False, interactive_default=True):
        if interactive is False and self.attributes['interactive'] is True:
            return self.STATUS_SKIPPED

        if self.triggered and not self.has_been_triggered:
            LOG.debug(_("skipping {} because it wasn't triggered").format(self.id))
            return self.STATUS_SKIPPED

        if self.unless:
            unless_result = self.bundle.node.run(
                self.unless,
                may_fail=True,
            )
            if unless_result.return_code == 0:
                LOG.debug(_("{node}:{bundle}:action:{name}: failed 'unless', not running").format(
                    bundle=self.bundle.name,
                    name=self.name,
                    node=self.bundle.node.name,
                ))
                return self.STATUS_SKIPPED

        if (
            interactive and
            self.attributes['interactive'] is not False
            and not ask_interactively(
                wrap_question(
                    self.id,
                    self.attributes['command'],
                    _("Run action {}?").format(
                        bold(self.name),
                    ),
                ),
                interactive_default,
            )
        ):
            return self.STATUS_SKIPPED
        try:
            self.run(interactive=interactive)
            return self.STATUS_ACTION_SUCCEEDED
        except ActionFailure:
            return self.STATUS_FAILED
开发者ID:mfriedenhagen,项目名称:bundlewrap,代码行数:41,代码来源:actions.py

示例15: item_apply_end

def item_apply_end(
    repo, node, item, duration=None, status_before=None, status_after=None, **kwargs
):
    config = _get_config(repo.path)
    if config is None or \
            not config.has_section("item_notifications") or \
            not config.getboolean("item_notifications", "enabled"):
        return

    color = "gray"
    if status_before.correct:
        return
    elif status_after is None:
        color = "purple"
        status_string = "(unknown)"
    elif status_after.correct:
        color = "green"
        status_string = "(successful)"
    else:
        color = "red"
        status_string = "(failed)"

    for room in config.get("item_notifications", "rooms").split(","):
        LOG.debug("posting item apply end notification to HipChat room {room}@{server}".format(
            room=room,
            server=config.get("connection", "server"),
        ))
        _notify(
            config.get("connection", "server"),
            room.strip(),
            config.get("connection", "token"),
            "{status_string} {node}:{bundle}:{item}".format(
                bundle=item.bundle.name,
                item=item,
                node=node.name,
                status_string=status_string,
            ),
            "text",
            color=color,
        )
开发者ID:bundlewrap,项目名称:plugins,代码行数:40,代码来源:notify_hipchat.py


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