本文整理汇总了Python中spacewalk.common.rhnLog.initLOG函数的典型用法代码示例。如果您正苦于以下问题:Python initLOG函数的具体用法?Python initLOG怎么用?Python initLOG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了initLOG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: headerParserHandler
def headerParserHandler(self, req):
log_setreq(req)
# init configuration options with proper component
options = req.get_options()
# if we are initializing out of a <Location> handler don't
# freak out
if not options.has_key("RHNComponentType"):
# clearly nothing to do
return apache.OK
initCFG(options["RHNComponentType"])
initLOG(CFG.LOG_FILE, CFG.DEBUG)
if req.method == 'GET':
# This is the ping method
return apache.OK
self.servers = rhnImport.load("upload_server/handlers",
interface_signature='upload_class')
if not options.has_key('SERVER'):
log_error("SERVER not set in the apache config files!")
return apache.HTTP_INTERNAL_SERVER_ERROR
server_name = options['SERVER']
if not self.servers.has_key(server_name):
log_error("Unable to load server %s from available servers %s" %
(server_name, self.servers))
return apache.HTTP_INTERNAL_SERVER_ERROR
server_class = self.servers[server_name]
self.server = server_class(req)
return self._wrapper(req, "headerParserHandler")
示例2: sync
def sync(self, channels=None):
# If no channels specified, sync already synced channels
if not channels:
channels = self.synced_channels
# Check channel availability before doing anything
not_available = []
for channel in channels:
if any(channel not in d for d in
[self.channel_metadata, self.channel_to_family, self.content_source_mapping]):
not_available.append(channel)
if not_available:
raise ChannelNotFoundError(" " + "\n ".join(not_available))
# Need to update channel metadata
self._update_channels_metadata(channels)
# Finally, sync channel content
total_time = datetime.timedelta()
for channel in channels:
cur_time = self._sync_channel(channel)
total_time += cur_time
# Switch back to cdnsync log
rhnLog.initLOG(self.log_path, self.log_level)
log2disk(0, "Sync of channel completed.")
log(0, "Total time: %s" % str(total_time).split('.')[0])
示例3: setup_config
def setup_config(self, config, force=0):
# Figure out the log level
debug_level = self.options.verbose
if debug_level is None:
debug_level = CFG.debug
self.debug_level = debug_level
logfile = self.options.logfile
if logfile is None or logfile == '':
logfile = CFG.log_file
initLOG(level=debug_level, log_file=logfile)
# Get the ssl cert
ssl_cert = CFG.osa_ssl_cert
try:
self.check_cert(ssl_cert)
except jabber_lib.InvalidCertError:
e = sys.exc_info()[1]
log_error("Invalid SSL certificate:", e)
return 1
self.ssl_cert = ssl_cert
rhnSQL.initDB()
self._username = 'rhn-dispatcher-sat'
self._password = self.get_dispatcher_password(self._username)
if not self._password:
self._password = self.create_dispatcher_password(32)
self._resource = 'superclient'
js = config.get('jabber_server')
self._jabber_servers = [ idn_ascii_to_puny(js) ]
示例4: main
def main():
global debug, verbose
parser = OptionParser(option_list=options_table)
(options, args) = parser.parse_args()
if args:
for arg in args:
sys.stderr.write("Not a valid option ('%s'), try --help\n" % arg)
sys.exit(-1)
if options.verbose:
initLOG("stdout", options.verbose or 0)
verbose = 1
if options.debug:
initLOG(CFG.LOG_FILE, options.debug or 0)
debug = 1
rhnSQL.initDB()
if options.update_filer:
process_package_data()
if options.update_sha256:
process_sha256_packages()
if options.update_kstrees:
process_kickstart_trees()
if options.update_package_files:
process_package_files()
if options.update_changelog:
process_changelog()
示例5: cleanupHandler
def cleanupHandler(self, req):
self._timer()
retval = self._wrapper(req, self._cleanupHandler)
self._cleanup()
# Reset the logger to stderr
initLOG()
return retval
示例6: sync
def sync(self, channels=None):
# If no channels specified, sync already synced channels
if not channels:
channels = self.synced_channels
# Check channel availability before doing anything
not_available = []
for channel in channels:
if any(channel not in d for d in
[self.channel_metadata, self.channel_to_family]) or (
not self.cdn_repository_manager.check_channel_availability(channel, self.no_kickstarts)):
not_available.append(channel)
if not_available:
raise ChannelNotFoundError(" " + "\n ".join(not_available))
# Need to update channel metadata
self._update_channels_metadata(channels)
# Finally, sync channel content
error_messages = []
total_time = datetime.timedelta()
for channel in channels:
cur_time, ret_code = self._sync_channel(channel)
if ret_code != 0:
error_messages.append("Problems occurred during syncing channel %s. Please check "
"/var/log/rhn/cdnsync/%s.log for the details\n" % (channel, channel))
total_time += cur_time
# Switch back to cdnsync log
rhnLog.initLOG(self.log_path, self.log_level)
log2disk(0, "Sync of channel completed.")
log(0, "Total time: %s" % str(total_time).split('.')[0])
return error_messages
示例7: sync
def sync(self, channels=None):
# If no channels specified, sync already synced channels
if not channels:
channels = list(self.synced_channels)
# Check channel availability before doing anything
not_available = []
available = []
for channel in channels:
if not self._is_channel_available(channel):
not_available.append(channel)
else:
available.append(channel)
channels = available
error_messages = []
# if we have not_available channels log the error immediately
if not_available:
msg = "ERROR: these channels either do not exist or are not available:\n " + "\n ".join(not_available)
error_messages.append(msg)
# BZ 1434913 - let user know satellite may not be activated if all channels are in not_available
if not available:
msg = "WARNING: Is your Red Hat Satellite activated for CDN?\n"
msg += "(to see details about currently used SSL certificates for accessing CDN:"
msg += " /usr/bin/cdn-sync --cdn-certs)"
error_messages.append(msg)
# Need to update channel metadata
self._update_channels_metadata([ch for ch in channels if ch in self.channel_metadata])
# Make sure custom channels are properly connected with repos
for channel in channels:
if channel in self.synced_channels and self.synced_channels[channel]:
self.cdn_repository_manager.assign_repositories_to_channel(channel)
reposync.clear_ssl_cache()
# Finally, sync channel content
total_time = timedelta()
for channel in channels:
cur_time, failed_packages = self._sync_channel(channel)
if failed_packages < 0:
error_messages.append("Problems occurred during syncing channel %s. Please check "
"/var/log/rhn/cdnsync/%s.log for the details\n" % (channel, channel))
if failed_packages > 0:
error_messages.append("%d packages in channel %s failed to sync. Please check "
"/var/log/rhn/cdnsync/%s.log for the details\n" % (failed_packages, channel,
channel))
total_time += cur_time
# Switch back to cdnsync log
rhnLog.initLOG(self.log_path, self.log_level)
log2disk(0, "Sync of channel completed.")
log(0, "Total time: %s" % str(total_time).split('.')[0])
return error_messages
示例8: __init__
def __init__(
self,
channel_label,
repo_type,
url=None,
fail=False,
quiet=False,
filters=None,
no_errata=False,
sync_kickstart=False,
latest=False,
):
self.regen = False
self.fail = fail
self.quiet = quiet
self.filters = filters or []
self.no_errata = no_errata
self.sync_kickstart = sync_kickstart
self.latest = latest
initCFG("server")
rhnSQL.initDB()
# setup logging
log_filename = channel_label + ".log"
rhnLog.initLOG(default_log_location + log_filename)
# os.fchown isn't in 2.4 :/
os.system("chgrp apache " + default_log_location + log_filename)
self.log_msg("\nSync started: %s" % (time.asctime(time.localtime())))
self.log_msg(str(sys.argv))
self.channel_label = channel_label
self.channel = self.load_channel()
if not self.channel or not rhnChannel.isCustomChannel(self.channel["id"]):
self.print_msg("Channel does not exist or is not custom.")
sys.exit(1)
if not url:
# TODO:need to look at user security across orgs
h = rhnSQL.prepare(
"""select s.id, s.source_url, s.label
from rhnContentSource s,
rhnChannelContentSource cs
where s.id = cs.source_id
and cs.channel_id = :channel_id"""
)
h.execute(channel_id=int(self.channel["id"]))
source_data = h.fetchall_dict()
if source_data:
self.urls = [(row["id"], row["source_url"], row["label"]) for row in source_data]
else:
self.error_msg("Channel has no URL associated")
sys.exit(1)
else:
self.urls = [(None, u, None) for u in url]
self.repo_plugin = self.load_plugin(repo_type)
示例9: cleanupHandler
def cleanupHandler(self, req):
if req.method == 'GET':
# This is the ping method
return apache.OK
retval = self._wrapper(req, "cleanupHandler")
# Reset the logger to stderr
initLOG()
self.server = None
return retval
示例10: __init__
def __init__(self, channel_label, repo_type, url=None, fail=False,
quiet=False, filters=None, no_errata=False, sync_kickstart=False, latest=False,
strict=0):
self.regen = False
self.fail = fail
self.quiet = quiet
self.filters = filters or []
self.no_errata = no_errata
self.sync_kickstart = sync_kickstart
self.latest = latest
initCFG('server.satellite')
rhnSQL.initDB()
# setup logging
log_filename = channel_label + '.log'
if CFG.DEBUG is not None:
log_level = CFG.DEBUG
rhnLog.initLOG(default_log_location + log_filename, log_level)
# os.fchown isn't in 2.4 :/
if isSUSE():
os.system("chgrp www " + default_log_location + log_filename)
else:
os.system("chgrp apache " + default_log_location + log_filename)
self.log_msg("\nSync started: %s" % (time.asctime(time.localtime())))
self.log_msg(str(sys.argv))
self.channel_label = channel_label
self.channel = self.load_channel()
if not self.channel:
self.print_msg("Channel does not exist.")
sys.exit(1)
if not url:
# TODO:need to look at user security across orgs
h = rhnSQL.prepare("""select s.id, s.source_url, s.label, fm.channel_family_id
from rhnContentSource s,
rhnChannelContentSource cs,
rhnChannelFamilyMembers fm
where s.id = cs.source_id
and cs.channel_id = fm.channel_id
and cs.channel_id = :channel_id""")
h.execute(channel_id=int(self.channel['id']))
source_data = h.fetchall_dict()
if source_data:
self.urls = [(row['id'], row['source_url'], row['label'],
row['channel_family_id']) for row in source_data]
else:
self.error_msg("Channel has no URL associated")
sys.exit(1)
else:
self.urls = [(None, u, None, None) for u in url]
self.repo_plugin = self.load_plugin(repo_type)
self.strict = strict
示例11: setup_config
def setup_config(self, config):
# Figure out the log level
debug_level = self.options.verbose
if debug_level is None:
debug_level = CFG.debug
self.debug_level = debug_level
initLOG(level=debug_level, log_file=CFG.log_file)
# Get the ssl cert
ssl_cert = CFG.osa_ssl_cert
try:
self.check_cert(ssl_cert)
except jabber_lib.InvalidCertError, e:
log_error("Invalid SSL certificate:", e)
return 1
示例12: headerParserHandler
def headerParserHandler(self, req):
log_setreq(req)
# We need to init CFG and Logging
options = req.get_options()
# if we are initializing out of a <Location> handler don't
# freak out
if not options.has_key("RHNComponentType"):
# clearly nothing to do
return apache.OK
initCFG(options["RHNComponentType"])
initLOG(CFG.LOG_FILE, CFG.DEBUG)
""" parse the request, init database and figure out what can we call """
log_debug(2, req.the_request)
# call method from inherited class
ret = apacheSession.headerParserHandler(self, req)
if ret != apache.OK:
return ret
# make sure we have DB connection
if not CFG.SEND_MESSAGE_TO_ALL:
try:
rhnSQL.initDB()
except rhnSQL.SQLConnectError:
rhnTB.Traceback(mail=1, req=req, severity="schema")
return apache.HTTP_INTERNAL_SERVER_ERROR
else:
# If in outage mode, close the DB connections
rhnSQL.closeDB()
# Store client capabilities
client_cap_header = 'X-RHN-Client-Capability'
if req.headers_in.has_key(client_cap_header):
client_caps = req.headers_in[client_cap_header]
client_caps = filter(None,
map(string.strip, string.split(client_caps, ","))
)
rhnCapability.set_client_capabilities(client_caps)
# Enabling the input header flags associated with the redirects/newer clients
redirect_support_flags = ['X-RHN-Redirect', 'X-RHN-Transport-Capability']
for flag in redirect_support_flags:
if req.headers_in.has_key(flag):
rhnFlags.set(flag, str(req.headers_in[flag]))
return apache.OK
示例13: headerParserHandler
def headerParserHandler(self, req):
# pylint: disable=W0201
log_setreq(req)
self.start_time = time.time()
# init configuration options with proper component
options = req.get_options()
# if we are initializing out of a <Location> handler don't
# freak out
if "RHNComponentType" not in options:
# clearly nothing to do
return apache.OK
initCFG(options["RHNComponentType"])
initLOG(CFG.LOG_FILE, CFG.DEBUG)
# short-circuit everything if sending a system-wide message.
if CFG.SEND_MESSAGE_TO_ALL:
# Drop the database connection
# pylint: disable=W0702
try:
rhnSQL.closeDB()
except:
pass
# Fetch global message being sent to clients if applicable.
msg = open(CFG.MESSAGE_TO_ALL).read()
log_debug(3, "Sending message to all clients: %s" % msg)
return self._send_xmlrpc(req, rhnFault(-1,
_("IMPORTANT MESSAGE FOLLOWS:\n%s") % msg, explain=0))
rhnSQL.initDB()
self.server = options['SERVER']
self.server_classes = rhnImport.load("satellite_exporter/handlers")
if self.server not in self.server_classes:
# XXX do something interesting here
log_error("Missing server", self.server)
return apache.HTTP_NOT_FOUND
return self._wrapper(req, self._headerParserHandler)
示例14: __call__
def __call__(self, req):
# NOTE: all imports done here due to required initialization of
# of the configuration module before all others.
# Initialization is dependent on RHNComponentType in the
# req object.
if self.__init:
from apacheHandler import getComponentType
# We cannot trust the config files to tell us if we are in the
# broker or in the redirect because we try to always pass
# upstream all requests
componentType = getComponentType(req)
initCFG(componentType)
initLOG(CFG.LOG_FILE, CFG.DEBUG)
log_debug(1, 'New request, component %s' % (componentType, ))
# Instantiate the handlers
if HandlerWrap.svrHandlers is None:
HandlerWrap.svrHandlers = self.get_handler_factory(req)()
if self.__init:
# Set the component type
HandlerWrap.svrHandlers.set_component(componentType)
try:
log_setreq(req)
if hasattr(HandlerWrap.svrHandlers, self.__name):
f = getattr(HandlerWrap.svrHandlers, self.__name)
ret = f(req)
else:
raise Exception("Class has no attribute %s" % self.__name)
# pylint: disable=W0702
except:
Traceback(self.__name, req, extra="Unhandled exception type",
severity="unhandled")
return apache.HTTP_INTERNAL_SERVER_ERROR
else:
return ret
示例15: main
def main(options):
xmlrpc = RemoteApi(options.server, options.username, options.password)
db = DBApi()
initCFG('server')
rhnLog.initLOG(LOG_LOCATION)
cleansed = vars(options)
cleansed["password"] = "*****"
log_clean(0, "")
log_debug(0, "Started spacewalk-clone-by-date")
log_clean(0, pprint.pformat(cleansed))
print "Reading repository information."
if options.use_update_date:
options.use_update_date = 'update_date'
else:
options.use_update_date = 'issue_date'
print "Using %s." % options.use_update_date
cloners = []
needed_channels = []
errata = None
if options.errata:
errata = set(options.errata)
for channel_list in options.channels:
parents = None
if options.parents:
# if only the dest parent is specified, look up the src parent
if len(options.parents) == 1:
src_parent = xmlrpc.get_original(options.parents[0])
if not src_parent:
print ("Channel %s is not a cloned channel." % options.parents[0])
sys.exit(1)
print "Looking up the original channel for %s, %s found" % (
options.parents[0], src_parent)
options.parents = [src_parent] + options.parents
# options.parents is only set by command line, this must be the
# only channel tree
parents = options.parents
# Handle the new-style channel specification that uses
# key value pairs. Transform into channel / parent setup that
# ChannelTreeCloner expects. This code has to be here now that you can
# specify parents for multiple trees.
# TODO: the channel / parents structure needs to be cleaned up throught
# clone-by-date. Probably best thing would to make everywhere use the
# dict structure instead of the list structure.
for src_channel in channel_list.keys():
dest_channel = channel_list[src_channel]
# new-style config file channel specification
if type(dest_channel) == dict:
if 'label' not in dest_channel:
raise UserError("You must specify a label for the clone of %s" % src_channel)
label = dest_channel['label']
if 'name' in dest_channel:
name = dest_channel['name']
else:
name = label
if 'summary' in dest_channel:
summary = dest_channel['summary']
else:
summary = label
if 'description' in dest_channel:
description = dest_channel['description']
else:
description = label
# This is the options.parents equivalent for config files.
# Add channels to parents option and remove from channels.
if ('existing-parent-do-not-modify' in dest_channel
and dest_channel['existing-parent-do-not-modify']):
parents = [src_channel, label]
del channel_list[src_channel]
else: # else tranform channel_list entry to the list format
channel_list[src_channel] = [label, name, summary,
description]
# before we start make sure we can get repodata for all channels
# involved.
channel_labels = channel_list.keys()
for label in channel_labels:
if not os.path.exists(repodata(label)):
raise UserRepoError(label)
# ensure the parent's channel metadata is available
if parents:
for label in parents:
if not os.path.exists(repodata(label)):
raise UserRepoError(label)
# if cloning specific errata validate that they actually exist
# in the original channels
if options.errata:
for channel in channel_labels:
channel_errata = set(xmlrpc.list_errata(channel))
if len(errata - channel_errata) != 0:
print ("Error: all errata specified with --errata must "
+ "exist in every original channel cloned in "
+ "this operation.")
print ("Channel %s does not contain these errata: %s" %
(channel, errata - channel_errata))
sys.exit(1)
#.........这里部分代码省略.........