本文整理汇总了Python中logger.Log类的典型用法代码示例。如果您正苦于以下问题:Python Log类的具体用法?Python Log怎么用?Python Log使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Log类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check
def _check(self, pkg, context, pkgQueue, depth):
Log.cout(Log.DEBUG, self._outputTrace(depth, 'check(%s)' % pkg))
ts, excludes = context.ts, context.excludes
ret = error.ERROR_NONE
context.checkedPkgs.add(pkg)
requireDict = ResolverHelper.getAndMergeRequires(pkg)
#May be need sort this require.
items = self._sortRequireByName(requireDict)
for name, requires in items:
prvpkgs = self._getByProvides(requires, context)
if pkg in prvpkgs:
continue
prvpkgs = ResolverHelper.filterPkgByRequires(prvpkgs, requireDict)
prvpkg = self._getBestInstalledProvide(pkg, prvpkgs, context)
if prvpkg is not None:
ret = self._doCheck(prvpkg, context, pkgQueue, depth)
if ret != error.ERROR_NONE:
return ret
if self._needUpgradeLocalProvide(pkg, name, prvpkg, context):
self._upgradeLocalProvide(pkg, requires, prvpkgs, context, pkgQueue)
continue
if context.initOperation == CHECK:
return error.ERROR_CHECK
prvpkgs = self._filterAndSortPackages(prvpkgs, pkg)
pkgQueue.append((INSTALL, pkg, requires, prvpkgs))
return error.ERROR_NONE
示例2: _doFetch
def _doFetch(self, url):
socket.setdefaulttimeout(self.timeout)
try:
request = urllib2.Request(url)
response = urllib2.urlopen(request)
chunked = self._isChunked(response)
content = ''
if not chunked:
length = int(response.info().getheader('Content-Length'))
if length > self.maxFileLength:
return FetchError.FETCH_TOO_LARGE, None
content = response.read()
else:
length = 0
while True:
line = response.readline(self.lineLength)
if not line:
break
content += line
length += len(line)
if length > self.maxFileLength:
return FetchError.FETCH_TOO_LARGE, None
response.close()
return FetchError.FETCH_SUCCESS, content
except Exception, e:
Log.cout(Log.ERROR, 'Fetch failed: %s' % e)
if hasattr(e, 'reason'):
if str(e.reason) == 'timed out':
return FetchError.FETCH_TIMEOUT, None
return FetchError.FETCH_OTHER_ERROR, None
示例3: _getMetaFile
def _getMetaFile(self, repoMdObj, metaName, fileName):
if not repoMdObj.repoMdDatas.has_key(metaName):
return False
metaObj = repoMdObj.repoMdDatas[metaName]
destTmpFile = self._getRepoDataDir() + '/' + \
metaObj.locationHref.split('/')[-1]
metaUrl = self.repoConfig.baseurl + '/' + metaObj.locationHref
# uncompressTmpFile = '.'.join(destTmpFile.split('.')[:-1]) + '.tmp'
uncompressTmpFile = self._getRepoDataDir() + '/' + \
fileName + '.tmp'
if not file_util.remove(destTmpFile) or\
not file_util.remove(uncompressTmpFile):
return False
if not self.fileFetcher.fetch(metaUrl, destTmpFile) or\
not file_util.chmod(destTmpFile, 0666):
return False
try:
if destTmpFile.split('.')[-1] == 'bz2':
f = bz2.BZ2File(destTmpFile)
else:
f = gzip.open(destTmpFile)
if not file_util.writeToFile(uncompressTmpFile, f.read()) or\
not file_util.chmod(uncompressTmpFile, 0666):
f.close()
return False
f.close()
except Exception:
Log.cout(Log.ERROR, 'decompress %s failed' % destTmpFile)
return False
return self._checkSumValid(metaObj, uncompressTmpFile)
示例4: _checkInstall
def _checkInstall(self, pkg, context, pkgQueue, depth):
Log.cout(Log.DEBUG, self._outputTrace(depth, "checkInstall(%s)" % pkg))
if depth > self.MAX_DEPTH:
return error.ERROR_INSTALL
context.ts.setOperation(pkg, INSTALL)
context.excludes.exclude(pkg)
if not pkg.installed():
ret = self._checkConflictAndProvide(pkg, context, pkgQueue, depth)
if ret != error.ERROR_NONE:
return ret
requireDict = ResolverHelper.getAndMergeRequires(pkg)
for name, requires in requireDict.items():
prvpkgs = self._getByProvides(requires, context)
prvpkg = self._getBestInstalledProvide(pkg, prvpkgs, context)
if not prvpkg:
return error.ERROR_NONE
if prvpkg is pkg:
continue
if context.excludes.excluded(prvpkg):
self._addDependency(pkg, prvpkg, context, 'install')
continue
if self.getInstallDir(prvpkg) == self.installRoot:
ret = self._checkInstall(prvpkg, context, pkgQueue, depth + 1)
if ret != error.ERROR_NONE:
Log.cout(Log.ERROR, 'Check install package %s failed' % prvpkg)
return ret
self._addDependency(pkg, prvpkg, context, 'install')
return error.ERROR_NONE
示例5: _doHandleSameProvidePkg
def _doHandleSameProvidePkg(self, pkg, context, pkgQueue, depth):
"""
If installed package with same name and can not coexist,
we need to remove old package.
"""
ts, excludes = context.ts, context.excludes
for provide in pkg.provides:
providers = self._getByProvide(Provide(name=provide.name), context)
installedPkgs = []
for package in providers:
if package is pkg:
continue
if not ts.installed(package):
excludes.exclude(package)
else:
installedPkgs.append(package)
for package in installedPkgs:
coexists, notSatisfiedPkgs = self.coexists(pkg, provide, package, context)
if coexists:
continue
if not self._checkSamePkgWithOption(pkg, package, context, depth):
return error.ERROR_INSTALL, None
ret = self._remove(package, context, pkgQueue, depth + 1)
if ret != error.ERROR_NONE:
logInfo = self._outputTrace(depth, 'Handle same provide between %s and %s failed' % (pkg, package))
Log.cout(Log.ERROR, logInfo)
return ret, notSatisfiedPkgs
self._addDependency(pkg, package, context, 'remove')
return error.ERROR_NONE, None
示例6: send
def send(self, data):
header = Header()
header.size = len(data)
header.sequence_number = self.send_sequence
data = header.to_bytes() + data
while True:
#TODO: this could be done more elegantly
if(len(self.workers) == 0):
Log.log("Shutdown multiplexer. No workers found")
self.cleanup()
sys.exit(0)
worker = self.workers[self.send_index][0]
#Increment the sequence number and the send_index to send along another worker
self.send_index = (1 + self.send_index) % len(self.workers)
try:
worker.write(data)
worker.flush()
break
except IOError as e:
if e.errno == 11:
#TODO: whut. Why did I do this?
pass
else:
raise e
self.send_sequence = self.send_sequence + 1
示例7: iterate
def iterate(self):
outdegrees, depDict = dict(), dict()
for package in self.preDict:
prerequisites = self.preDict[package]
if package not in outdegrees:
outdegrees[package] = 0
for prerequisite in prerequisites:
if prerequisite is not None:
outdegrees[package] += 1
if prerequisite not in outdegrees:
outdegrees[prerequisite] = 0
depDict.setdefault(prerequisite, set()).add(package)
stack = [x for x in outdegrees if outdegrees[x] == 0]
count = 0
while len(stack) > 0:
package = stack.pop(0)
count = count + 1
yield package
for dependent in depDict.get(package, []):
outdegrees[dependent] -= 1
if outdegrees[dependent] <= 0:
stack.append(dependent)
if count != len(outdegrees):
printDegreees = dict()
for pkg in outdegrees:
if outdegrees[pkg] != 0:
printDegreees[pkg] = outdegrees[pkg]
Log.cout(Log.DEBUG, printDegreees)
raise DependencyGraph.CycleDependencyException, "cycle dependent"
示例8: writeToFp
def writeToFp(fp, content):
try:
fp.write(content)
fp.flush()
except Exception, e:
Log.cout(Log.DEBUG, 'Write to fp failed: %s' % e)
return False
示例9: readLink
def readLink(path):
try:
if isLink(path):
return os.readlink(path)
except Exception, e:
Log.cout(Log.DEBUG, 'readlink %s failed: %s' % (path, e))
return None
示例10: _killRemoteCmd
def _killRemoteCmd(self, host, executorPath, cmdStr, remoteUser, remoteSudo):
pathIndex = cmdStr.find(executorPath)
if pathIndex == -1:
return False
rawCmd = cmdStr[pathIndex:]
rawCmd = ' '.join(rawCmd.split())
Log.cout(Log.INFO, 'kill ainst2 process on the remote host %s ...' % host)
cmd = 'ssh %[email protected]%s ps -efw | grep \'%s\' | grep -v \'ssh %s@%s\' | grep -v grep'\
% (remoteUser, host, rawCmd, remoteUser, host)
out, err, code = process.runRedirected(cmd, self._killTimeout)
if code != 0:
Log.cout(Log.ERROR, 'get remote pid failed')
return False
pidList = []
contentList = out.split('\n')
for content in contentList:
if not content or not content.strip():
continue
items = content.split()
pidList.append(items[1])
if not pidList:
return True
pidSet = set(pidList)
index = 0
while index < len(pidList):
subPidList = self._getSubPidList(remoteUser, host, pidList[index])
for subPid in subPidList:
if subPid not in pidSet:
pidList.append(subPid)
pidSet.add(subPid)
index += 1
return self._killRemotePid(pidList, remoteUser, host, remoteSudo)
示例11: _doParallelOperate
def _doParallelOperate(self, hostSet, cmd, parallel, remoteTimeout, retryTime,
retryInterval, user, remoteSudo, errorContinue):
successList = []
failedList = []
if not hostSet:
return successList, failedList
count = 0
hostLen = len(hostSet)
threaderList = []
for host in hostSet:
Log.coutLabel(Log.INFO, 'Process Remote host:%s' % host)
remoteCmd = 'ssh %[email protected]%s %s' % (user, host, cmd)
threader = RemoteOperatorThread(host, self._ainstBinPath, remoteCmd,
remoteTimeout, retryTime,
retryInterval, user, remoteSudo)
threader.setDaemon(True)
threaderList.append(threader)
threader.start()
count += 1
if count % parallel != 0 and count < hostLen:
continue
for threader in threaderList:
threader.join()
for threader in threaderList:
if not threader.returnValue:
failedList.append(threader.host)
else:
successList.append(threader.host)
if not errorContinue and len(failedList) > 0:
break
threaderList = []
return successList, failedList
示例12: __init__
def __init__(self, message, status_code=None, payload=None):
Exception.__init__(self)
Log.exception(message)
self.message = message
if status_code is not None:
self.status_code = status_code
self.payload = payload
示例13: _generateConfigToRoot
def _generateConfigToRoot(self, ainstPkgDir, aicfInfo, settingMap, confDict):
if aicfInfo:
for path, configInfo in aicfInfo.configs.iteritems():
srcConfigPath = ainstPkgDir + '/' + path
destConfigPath = self._ainstRoot.getRoot() + '/' + path
if not file_util.isFile(srcConfigPath):
Log.cout(Log.ERROR, 'Config file %s is not exists' % srcConfigPath)
return False
if not file_util.exists(destConfigPath):
Log.cout(Log.ERROR, 'Dest config file %s is not exists' % destConfigPath)
return False
tmpDirName = self._ainstRoot.getRootVarAinstDir('tmp')
tmpPath = tmpDirName + '/' + os.path.basename(destConfigPath) + '.tmp.set'
if not file_util.move(destConfigPath, tmpPath):
Log.cout(Log.ERROR, 'Backup config file %s failed' % destConfigPath)
return False
confDict[path] = (tmpPath, destConfigPath)
configGenerator = ConfigGenerator()
if not configGenerator.generateConfig(srcConfigPath,
destConfigPath,
configInfo.mode,
configInfo.noReplace,
settingMap):
Log.cout(Log.ERROR, 'Generate Config file %s failed' % path)
return False
else:
Log.cout(Log.DEBUG, 'No aicf file, so no config will be changed')
return True
示例14: _queue
def _queue(self, pkgQueue, context, depth):
if len(pkgQueue) == 0:
return error.ERROR_NONE
Log.cout(Log.DEBUG, self._outputTrace(depth, "queue"))
ret = error.ERROR_NONE
while True:
tmpQueue, hasSuccess = list(), False
while len(pkgQueue) > 0:
item = pkgQueue.pop(0)
if item[0] == INSTALL:
ret = self._handleInstallItem(pkgQueue, item, context, depth)
elif item[0] == REMOVE:
ret = self._handleRemoveItem(pkgQueue,item, context, depth)
if ret == error.ERROR_NONE:
hasSuccess = True
elif ret == error.ERROR_EXCLUSIVE_DEPS:
tmpQueue.append(item)
else:
opt = 'Handle'
if item[0] == INSTALL:
opt = 'Install'
elif item[0] == REMOVE:
opt = 'Remove'
content = self._outputTrace(depth, '%s pkg %s failed' % (opt, item[1]))
Log.cout(Log.ERROR, content)
return ret
if len(tmpQueue) == 0:
return error.ERROR_NONE
if not hasSuccess:
return error.ERROR_EXCLUSIVE_DEPS
pkgQueue.extend(tmpQueue)
return ret
示例15: fetch
def fetch(self, data=None, headers=None):
"""Fetch http file from network.
Args:
headers: {str:str} of additional request HTTP headers
data: {str:*} of data to be sent via HTTP
Returns:
[*str] of file pointer-like HTTP stream.
"""
# Fetch request.
if self.type == "http":
rsp = self._fetch_http(data, headers)
elif self.type == "ftp":
rsp = self._fetch_ftp()
else:
Log.warning("Unknown type, cannot fetch %s for %s." % self.url, self)
return None
self.status = 200
# Convert header keys into all lower case.
self.headers = {}
for key, value in dict(rsp.info()).items():
self.headers[key.lower()] = value
self.url_rsp = rsp.geturl()
return rsp