本文整理汇总了Python中util.output函数的典型用法代码示例。如果您正苦于以下问题:Python output函数的具体用法?Python output怎么用?Python output使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了output函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.")
示例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
示例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.")
示例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
示例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
示例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
示例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("")
示例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.")
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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")