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

Python util.output函数代码示例

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

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



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

示例1: makeLocalNetworks

def makeLocalNetworks(path, silent=False):

    netcfg = config.Config.localnetscfg

    if not os.path.exists(netcfg):
        util.warn("list of local networks does not exist in %s" % netcfg)
        return

    if ( not silent ):
        util.output("generating local-networks.bro ...", False)

    out = open(os.path.join(path, "local-networks.bro"), "w")
    print >>out, "# Automatically generated. Do not edit.\n"

    netcfg = config.Config.localnetscfg

    if os.path.exists(netcfg):
        nets = readNetworks(netcfg)

        print >>out, "redef Site::local_nets = {"
        for (cidr, tag) in nets:
            print >>out, "\t%s," % cidr,
            if tag != "":
                print >>out, "\t# %s" % tag,
            print >>out
        print >>out, "};\n"

    if ( not silent ):
        util.output(" done.")
开发者ID:aming2007,项目名称:dpi-test-suite,代码行数:29,代码来源:install.py


示例2: cleanup

def cleanup(nodes, cleantmp=False):
    hadError = False
    util.output("cleaning up nodes ...")
    result = isRunning(nodes)
    running = [node for (node, on) in result if on]
    notrunning = [node for (node, on) in result if not on]

    results1 = execute.rmdirs([(n, n.cwd()) for n in notrunning])
    results2 = execute.mkdirs([(n, n.cwd()) for n in notrunning])
    if nodeFailed(results1) or nodeFailed(results2):
        hadError = True

    for node in notrunning:
        node.clearCrashed()

    for node in running:
        util.output("   %s is still running, not cleaning work directory" % node.name)

    if cleantmp:
        results3 = execute.rmdirs([(n, config.Config.tmpdir) for n in running + notrunning])
        results4 = execute.mkdirs([(n, config.Config.tmpdir) for n in running + notrunning])
        if nodeFailed(results3) or nodeFailed(results4):
            hadError = True

    return not hadError
开发者ID:pombredanne,项目名称:broctl,代码行数:25,代码来源:control.py


示例3: makeLocalNetworks

def makeLocalNetworks():

    netcfg = config.Config.localnetscfg

    if not os.path.exists(netcfg):
        if not config.Installing:
            util.warn("list of local networks does not exist in %s" % netcfg)
        return

    util.output("generating local-networks.bro ...", False)

    out = open(os.path.join(config.Config.policydirsiteinstallauto, "local-networks.bro"), "w")
    print >>out, "# Automatically generated. Do not edit.\n"

    netcfg = config.Config.localnetscfg

    if os.path.exists(netcfg):
        nets = readNetworks(netcfg)

        print >>out, "redef local_nets = {"
        for (cidr, tag) in nets:
            print >>out, "\t%s," % cidr,
            if tag != "":
                print >>out, "\t# %s" % tag,
            print >>out
        print >>out, "};\n"

    util.output(" done.")
开发者ID:ewust,项目名称:telex,代码行数:28,代码来源:install.py


示例4: _checkDiskSpace

def _checkDiskSpace():

    minspace = float(config.Config.mindiskspace)
    if minspace == 0.0:
        return

    for (node, dfs) in control.getDf(config.Config.nodes()).items():
        for df in dfs:
            fs = df[0]
            total = float(df[1])
            used = float(df[2])
            avail = float(df[3])
            perc = used * 100.0 / (used + avail)
            key = ("disk-space-%s%s" % (node, fs.replace("/", "-"))).lower()

            if perc > 100 - minspace:
                try:
                    if float(config.Config.state[key]) > 100 - minspace:
                        # Already reported.
                        continue
                except KeyError:
                    pass

                util.output("Disk space low on %s:%s - %.1f%% used." % (node, fs, perc))

            config.Config.state[key] = "%.1f" % perc
开发者ID:aming2007,项目名称:dpi-test-suite,代码行数:26,代码来源:cron.py


示例5: install

def install(host, src, dst):
    if isLocal(host):
        if not exists(host, src):
            util.output("file does not exist: %s" % src)
            return False

        if os.path.isfile(dst):
            try:
                os.remove(dst)
            except OSError, e:
                print 'install: os.remove(%s): %s' % (dst, e.strerror)
                sys.exit(1)

        util.debug(1, "cp %s %s" % (src, dst))

        try:
            if os.path.isfile(src):
                shutil.copy2(src, dst)
            elif os.path.isdir(src):
                shutil.copytree(src, dst)
        except OSError:
            # Python 2.6 has a bug where this may fail on NFS. So we just
            # ignore errors.
            pass

        return True
开发者ID:decanio,项目名称:broctl,代码行数:26,代码来源:execute.py


示例6: _checkDiskSpace

def _checkDiskSpace():

    minspace = float(config.Config.mindiskspace)
    if minspace == 0.0:
        return

    results = control.getDf(config.Config.hosts())
    for (nodehost, dfs) in results:
        host = nodehost.split("/")[1]

        for df in dfs:
            if df[0] == "FAIL":
                # A failure here is normally caused by a host that is down, so
                # we don't need to output the error message.
                continue

            fs = df[0]
            perc = df[4]
            key = ("disk-space-%s%s" % (host, fs.replace("/", "-"))).lower()

            if perc > 100 - minspace:
                if key in config.Config.state:
                    if float(config.Config.state[key]) > 100 - minspace:
                        # Already reported.
                        continue

                util.output("Disk space low on %s:%s - %.1f%% used." % (host, fs, perc))

            config.Config.state[key] = "%.1f" % perc
开发者ID:noah-de,项目名称:broctl,代码行数:29,代码来源:cron.py


示例7: output

    def output(tag, data):

        def outputOne(tag, vals):
            util.output("%-20s " % tag, nl=False)

            if not error:
                util.output("%-10s " % vals["kpps"], nl=False)
                if "mbps" in vals:
                    util.output("%-10s " % vals["mbps"], nl=False)
                util.output()
            else:
                util.output("<%s> " % error)

        util.output("\n%-20s %-10s %-10s (%ds average)" % (tag, "kpps", "mbps", interval))
        util.output("-" * 30)

        totals = None

        for (port, error, vals) in sorted(data):

            if error:
                util.output(error)
                continue

            if str(port) != "$total":
                outputOne(port, vals)
            else:
                totals = vals

        if totals:
            util.output("")
            outputOne("Total", totals)
            util.output("")
开发者ID:aming2007,项目名称:dpi-test-suite,代码行数:33,代码来源:control.py


示例8: makeConfig

def makeConfig(path, silent=False):
    manager = config.Config.manager()

    if not manager:
        return

    if ( not silent ):
        util.output("generating broctl-config.bro ...", False)

    filename = os.path.join(path, "broctl-config.bro")
    out = open(filename, "w")
    print >>out, "# Automatically generated. Do not edit."
    print >>out, "redef Notice::mail_dest = \"%s\";" % config.Config.mailto
    print >>out, "redef Notice::mail_dest_pretty_printed = \"%s\";" % config.Config.mailalarmsto
    print >>out, "redef Notice::sendmail  = \"%s\";" % config.Config.sendmail;
    print >>out, "redef Notice::mail_subject_prefix  = \"%s\";" % config.Config.mailsubjectprefix;
    if manager.type != "standalone":
        print >>out, "@if ( Cluster::local_node_type() == Cluster::MANAGER )"
    print >>out, "redef Log::default_rotation_interval = %s secs;" % config.Config.logrotationinterval
    if manager.type != "standalone":
        print >>out, "@endif"
    if config.Config.ipv6comm:
        print >>out, "redef Communication::listen_ipv6 = T ;"
    else:
        print >>out, "redef Communication::listen_ipv6 = F ;"

    out.close()

    if ( not silent ):
        util.output(" done.")
开发者ID:aming2007,项目名称:dpi-test-suite,代码行数:30,代码来源:install.py


示例9: install

def install(host, src, dstdir):
    if isLocal(host):
        if not exists(host, src):
            util.output("file does not exist: %s" % src)
            return False

        dst = os.path.join(dstdir, os.path.basename(src))
        if exists(host, dst):
            # Do not clobber existing files/dirs (this is not an error)
            return True

        util.debug(1, "cp %s %s" % (src, dstdir))

        try:
            if os.path.isfile(src):
                shutil.copy2(src, dstdir)
            elif os.path.isdir(src):
                shutil.copytree(src, dst)
        except OSError:
            # Python 2.6 has a bug where this may fail on NFS. So we just
            # ignore errors.
            pass

    else:
        util.error("install() not yet supported for remote hosts")

    return True
开发者ID:cubic1271,项目名称:broctl,代码行数:27,代码来源:execute.py


示例10: executeCmd

def executeCmd(nodes, cmd):
    hadError = False
    for (node, success, output) in execute.executeCmdsParallel([(n, cmd) for n in nodes]):
        out = output and "\n> ".join(output) or ""
        util.output("[%s] %s\n> %s" % (node.name, (success and " " or "error"), out))
        if not success:
            hadError = True
    return not hadError
开发者ID:pombredanne,项目名称:broctl,代码行数:8,代码来源:control.py


示例11: getDf

def getDf(nodes):
    hadError = False
    dirs = (
        "logdir",
        "bindir",
        "helperdir",
        "cfgdir",
        "spooldir",
        "policydir",
        "libdir",
        "tmpdir",
        "staticdir",
        "scriptsdir",
    )

    df = {}
    for node in nodes:
        df[node.name] = {}

    for dir in dirs:
        path = config.Config.config[dir]

        cmds = []
        for node in nodes:
            if dir == "logdir" and node.type != "manager":
                # Don't need this on the workers/proxies.
                continue

            cmds += [(node, "df", [path])]

        results = execute.runHelperParallel(cmds)

        for (node, success, output) in results:
            if success:
                if output:
                    fields = output[0].split()

                    # Ignore NFS mounted volumes.
                    if fields[0].find(":") < 0:
                        df[node.name][fields[0]] = fields
                else:
                    util.output("error checking disk space on node '%s': no df output" % node)
                    hadError = True
            else:
                if output:
                    msg = output[0]
                else:
                    msg = "unknown failure"
                util.output("error checking disk space on node '%s': %s" % (node, msg))
                hadError = True

    result = {}
    for node in df:
        result[node] = df[node].values()

    return (hadError, result)
开发者ID:pombredanne,项目名称:broctl,代码行数:56,代码来源:control.py


示例12: _updateHTTPStats

def _updateHTTPStats():
    # Create meta file.
    if not os.path.exists(config.Config.statsdir):
        try:
            os.makedirs(config.Config.statsdir)
        except OSError, err:
            util.output("error creating directory: %s" % err)
            return

        util.warn("creating directory for stats file: %s" % config.Config.statsdir)
开发者ID:noah-de,项目名称:broctl,代码行数:10,代码来源:cron.py


示例13: outputOne

        def outputOne(tag, vals):
            util.output("%-20s " % tag, nl=False)

            if not error:
                util.output("%-10s " % vals["kpps"], nl=False)
                if "mbps" in vals:
                    util.output("%-10s " % vals["mbps"], nl=False)
                util.output()
            else:
                util.output("<%s> " % error)
开发者ID:aming2007,项目名称:dpi-test-suite,代码行数:10,代码来源:control.py


示例14: _expireLogs

def _expireLogs():

    i = int(config.Config.logexpireinterval)

    if not i:
        return

    (success, output) = execute.runLocalCmd(os.path.join(config.Config.scriptsdir, "expire-logs"))

    if not success:
        util.output("error running expire-logs\n\n")
        util.output(output)
开发者ID:aming2007,项目名称:dpi-test-suite,代码行数:12,代码来源:cron.py


示例15: doCron

def doCron(watch):

    if config.Config.cronenabled == "0":
        return

    if not os.path.exists(os.path.join(config.Config.scriptsdir, "broctl-config.sh")):
        util.output("error: broctl-config.sh not found (try 'broctl install')") 
        return

    config.Config.config["cron"] = "1"  # Flag to indicate that we're running from cron.

    if not util.lock():
        return

    util.bufferOutput()

    if watch:
        # Check whether nodes are still running an restart if neccessary.
        for (node, isrunning) in control.isRunning(config.Config.nodes()):
            if not isrunning and node.hasCrashed():
                control.start([node])

    # Check for dead hosts.
    _checkHosts()

    # Generate statistics.
    _logStats(5)

    # Check available disk space.
    _checkDiskSpace()

    # Expire old log files.
    _expireLogs()

    # Update the HTTP stats directory.
    _updateHTTPStats()

    # Run external command if we have one.
    if config.Config.croncmd:
        (success, output) = execute.runLocalCmd(config.Config.croncmd)
        if not success:
            util.output("error running croncmd: %s" % config.Config.croncmd)

    # Mail potential output.
    output = util.getBufferedOutput()
    if output:
        util.sendMail("cron: " + output.split("\n")[0], output)

    util.unlock()

    config.Config.config["cron"] = "0"
    util.debug(1, "cron done")
开发者ID:noah-de,项目名称:broctl,代码行数:52,代码来源:cron.py


示例16: _getProfLogs

def _getProfLogs():
    cmds = []

    for node in config.Config.hosts():
        if not execute.isAlive(node.addr):
            continue

        cmd = os.path.join(config.Config.scriptsdir, "get-prof-log") + " %s %s %s/prof.log" % (node.name, node.host, node.cwd())
        cmds += [(node, cmd, [], None)]

    for (node, success, output) in execute.runLocalCmdsParallel(cmds):
        if not success:
            util.output("cannot get prof.log from %s" % node.name)
开发者ID:aming2007,项目名称:dpi-test-suite,代码行数:13,代码来源:cron.py


示例17: attachGdb

def attachGdb(nodes):
    running = isRunning(nodes)

    cmds = []
    for (node, isrunning) in running:
        if isrunning:
            cmds += [(node, "gdb-attach", ["gdb-%s" % node.name, config.Config.bro, str(node.getPID())])]

    results = execute.runHelperParallel(cmds)
    for (node, success, output) in results:
        if success:
            util.output("gdb attached on %s" % node.name)
        else:
            util.output("cannot attach gdb on %s: %s" % node.name, output)
开发者ID:aming2007,项目名称:dpi-test-suite,代码行数:14,代码来源:control.py


示例18: df

def df(nodes):

    util.output("%10s  %15s  %-5s  %-5s  %-5s" % ("", "", "total", "avail", "capacity"))

    for (node, dfs) in getDf(nodes).items():
        for df in dfs:
            total = float(df[1])
            used = float(df[2])
            avail = float(df[3])
            perc = used * 100.0 / (used + avail)

            util.output("%10s  %15s  %-5s  %-5s  %-5.1f%%" % (node, df[0],
                prettyPrintVal(total),
                prettyPrintVal(avail), perc))
开发者ID:aming2007,项目名称:dpi-test-suite,代码行数:14,代码来源:control.py


示例19: _checkHosts

def _checkHosts():

    for node in config.Config.hosts():

        tag = "alive-%s" % node.host
        alive = execute.isAlive(node.addr) and "1" or "0"

        if tag in config.Config.state:
            previous = config.Config.state[tag]

            if alive != previous:
                util.output("host %s %s" % (node.host, alive == "1" and "up" or "down"))

        config.Config._setState(tag, alive)
开发者ID:ewust,项目名称:telex,代码行数:14,代码来源:cron.py


示例20: install

def install(host, src, dst):
    if isLocal(host):
        if not exists(host, src):
            util.output("file does not exist: %s" % src)
            return False

        if os.path.isfile(dst):
            os.remove(dst)

        util.debug(1, "cp %s %s" % (src, dst))
        shutil.copy2(src, dst)
        return True
    else:
        util.error("install() not yet supported for remote hosts")
        return False
开发者ID:ewust,项目名称:telex,代码行数:15,代码来源:execute.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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