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

Python log.log函数代码示例

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

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



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

示例1: getCorrections

 def getCorrections(self):
   """
   Performs validation on the loaded contents and provides back the
   corrections. If validation is disabled then this won't provide any
   results.
   """
   
   self.valsLock.acquire()
   
   if not self.isLoaded(): returnVal = None
   else:
     torVersion = torTools.getConn().getVersion()
     skipValidation = not CONFIG["features.torrc.validate"]
     skipValidation |= (torVersion is None or not torVersion.meets_requirements(stem.version.Requirement.GETINFO_CONFIG_TEXT))
     
     if skipValidation:
       log.log(log.INFO, "Skipping torrc validation (requires tor 0.2.2.7-alpha)")
       returnVal = {}
     else:
       if self.corrections == None:
         self.corrections = validate(self.contents)
       
       returnVal = list(self.corrections)
   
   self.valsLock.release()
   return returnVal
开发者ID:refnode,项目名称:arm,代码行数:26,代码来源:torConfig.py


示例2: loadConfig

def loadConfig(config):
  config.update(CONFIG)
  
  for configKey in config.getKeys():
    # fetches any port.label.* values
    if configKey.startswith("port.label."):
      portEntry = configKey[11:]
      purpose = config.get(configKey)
      
      divIndex = portEntry.find("-")
      if divIndex == -1:
        # single port
        if portEntry.isdigit():
          PORT_USAGE[portEntry] = purpose
        else:
          msg = "Port value isn't numeric for entry: %s" % configKey
          log.log(CONFIG["log.configEntryTypeError"], msg)
      else:
        try:
          # range of ports (inclusive)
          minPort = int(portEntry[:divIndex])
          maxPort = int(portEntry[divIndex + 1:])
          if minPort > maxPort: raise ValueError()
          
          for port in range(minPort, maxPort + 1):
            PORT_USAGE[str(port)] = purpose
        except ValueError:
          msg = "Unable to parse port range for entry: %s" % configKey
          log.log(CONFIG["log.configEntryTypeError"], msg)
开发者ID:JustMe23,项目名称:arm,代码行数:29,代码来源:connections.py


示例3: _initColors

def _initColors():
  """
  Initializes color mappings usable by curses. This can only be done after
  calling curses.initscr().
  """
  
  global COLOR_ATTR_INITIALIZED, COLOR_IS_SUPPORTED
  if not COLOR_ATTR_INITIALIZED:
    COLOR_ATTR_INITIALIZED = True
    COLOR_IS_SUPPORTED = False
    if not CONFIG["features.colorInterface"]: return
    
    try: COLOR_IS_SUPPORTED = curses.has_colors()
    except curses.error: return # initscr hasn't been called yet
    
    # initializes color mappings if color support is available
    if COLOR_IS_SUPPORTED:
      colorpair = 0
      log.log(CONFIG["log.cursesColorSupport"], "Terminal color support detected and enabled")
      
      for colorName in COLOR_LIST:
        fgColor = COLOR_LIST[colorName]
        bgColor = -1 # allows for default (possibly transparent) background
        colorpair += 1
        curses.init_pair(colorpair, fgColor, bgColor)
        COLOR_ATTR[colorName] = curses.color_pair(colorpair)
    else:
      log.log(CONFIG["log.cursesColorSupport"], "Terminal color support unavailable")
开发者ID:JustMe23,项目名称:arm,代码行数:28,代码来源:uiTools.py


示例4: getValue

 def getValue(self, key, default=None, multiple=False):
   """
   This provides the currently value associated with a given key. If no such
   key exists then this provides the default.
   
   Arguments:
     key      - config setting to be fetched
     default  - value provided if no such key exists
     multiple - provides back a list of all values if true, otherwise this
                returns the last loaded configuration value
   """
   
   self.contentsLock.acquire()
   
   if key in self.contents:
     val = self.contents[key]
     if not multiple: val = val[-1]
     self.requestedKeys.add(key)
   else:
     msg = "config entry '%s' not found, defaulting to '%s'" % (key, str(default))
     log.log(CONFIG["log.configEntryNotFound"], msg)
     val = default
   
   self.contentsLock.release()
   
   return val
开发者ID:JustMe23,项目名称:arm,代码行数:26,代码来源:conf.py


示例5: getStrCSV

 def getStrCSV(self, key, default = None, count = None):
   """
   Fetches the given key as a comma separated value. This provides back a list
   with the stripped values.
   
   Arguments:
     key     - config setting to be fetched
     default - value provided if no such key exists or doesn't match the count
     count   - if set, then a TypeError is logged (and default returned) if
               the number of elements doesn't match the count
   """
   
   confValue = self.getValue(key)
   if confValue == None: return default
   else:
     confComp = [entry.strip() for entry in confValue.split(",")]
     
     # check if the count doesn't match
     if count != None and len(confComp) != count:
       msg = "Config entry '%s' is expected to be %i comma separated values" % (key, count)
       if default != None and (isinstance(default, list) or isinstance(default, tuple)):
         defaultStr = ", ".join([str(i) for i in default])
         msg += ", defaulting to '%s'" % defaultStr
       
       log.log(CONFIG["log.configEntryTypeError"], msg)
       return default
     
     return confComp
开发者ID:JustMe23,项目名称:arm,代码行数:28,代码来源:conf.py


示例6: load

 def load(self, logFailure = False):
   """
   Loads or reloads the torrc contents, raising an IOError if there's a
   problem.
   
   Arguments:
     logFailure - if the torrc fails to load and we've never provided a
                  warning for this before then logs a warning
   """
   
   self.valsLock.acquire()
   
   # clears contents and caches
   self.contents, self.configLocation = None, None
   self.displayableContents = None
   self.strippedContents = None
   self.corrections = None
   
   try:
     self.configLocation = getConfigLocation()
     configFile = open(self.configLocation, "r")
     self.contents = configFile.readlines()
     configFile.close()
   except IOError, exc:
     if logFailure and not self.isLoadFailWarned:
       msg = "Unable to load torrc (%s)" % sysTools.getFileErrorMsg(exc)
       log.log(CONFIG["log.torrc.readFailed"], msg)
       self.isLoadFailWarned = True
     
     self.valsLock.release()
     raise exc
开发者ID:twilde,项目名称:arm,代码行数:31,代码来源:torConfig.py


示例7: __init__

 def __init__(self, stdscr, loggedEvents, config=None):
   panel.Panel.__init__(self, stdscr, "log", 0)
   threading.Thread.__init__(self)
   self.setDaemon(True)
   
   # Make sure that the msg.* messages are loaded. Lazy loading it later is
   # fine, but this way we're sure it happens before warning about unused
   # config options.
   loadLogMessages()
   
   # regex filters the user has defined
   self.filterOptions = []
   
   self._config = dict(DEFAULT_CONFIG)
   
   if config:
     config.update(self._config, {
       "features.log.maxLinesPerEntry": 1,
       "features.log.prepopulateReadLimit": 0,
       "features.log.maxRefreshRate": 10,
       "cache.logPanel.size": 1000})
     
     for filter in self._config["features.log.regex"]:
       # checks if we can't have more filters
       if len(self.filterOptions) >= MAX_REGEX_FILTERS: break
       
       try:
         re.compile(filter)
         self.filterOptions.append(filter)
       except re.error, exc:
         msg = "Invalid regular expression pattern (%s): %s" % (exc, filter)
         log.log(self._config["log.configEntryTypeError"], msg)
开发者ID:JustMe23,项目名称:arm,代码行数:32,代码来源:logPanel.py


示例8: _workerLoop

 def _workerLoop(self):
   """
   Simple producer-consumer loop followed by worker threads. This takes
   addresses from the unresolvedQueue, attempts to look up its hostname, and
   adds its results or the error to the resolved cache. Resolver reference
   provides shared resources used by the thread pool.
   """
   
   while not self.halt:
     # if resolver is paused then put a hold on further resolutions
     if self.isPaused:
       self.cond.acquire()
       if not self.halt: self.cond.wait(1)
       self.cond.release()
       continue
     
     # snags next available ip, timeout is because queue can't be woken up
     # when 'halt' is set
     try: ipAddr = self.unresolvedQueue.get_nowait()
     except Queue.Empty:
       # no elements ready, wait a little while and try again
       self.cond.acquire()
       if not self.halt: self.cond.wait(1)
       self.cond.release()
       continue
     if self.halt: break
     
     try:
       if self.useSocketResolution: result = _resolveViaSocket(ipAddr)
       else: result = _resolveViaHost(ipAddr)
     except IOError, exc: result = exc # lookup failed
     except ValueError, exc: result = exc # dns error
     
     self.resolvedLock.acquire()
     self.resolvedCache[ipAddr] = (result, RESOLVER_COUNTER.next())
     
     # trim cache if excessively large (clearing out oldest entries)
     if len(self.resolvedCache) > CONFIG["cache.hostnames.size"]:
       # Providing for concurrent, non-blocking calls require that entries are
       # never removed from the cache, so this creates a new, trimmed version
       # instead.
       
       # determines minimum age of entries to be kept
       currentCount = RESOLVER_COUNTER.next()
       newCacheSize = CONFIG["cache.hostnames.size"] - CONFIG["cache.hostnames.trimSize"]
       threshold = currentCount - newCacheSize
       newCache = {}
       
       msg = "trimming hostname cache from %i entries to %i" % (len(self.resolvedCache), newCacheSize)
       log.log(CONFIG["log.hostnameCacheTrimmed"], msg)
       
       # checks age of each entry, adding to toDelete if too old
       for ipAddr, entry in self.resolvedCache.iteritems():
         if entry[1] >= threshold: newCache[ipAddr] = entry
       
       self.resolvedCache = newCache
     
     self.resolvedLock.release()
开发者ID:JustMe23,项目名称:arm,代码行数:58,代码来源:hostnames.py


示例9: loadConfig

def loadConfig(config):
  config.update(CONFIG)
  
  CONFIG["features.colorOverride"] = "none"
  colorOverride = config.get("features.colorOverride", "none")
  
  if colorOverride != "none":
    try: setColorOverride(colorOverride)
    except ValueError, exc:
      log.log(CONFIG["log.configEntryTypeError"], exc)
开发者ID:JustMe23,项目名称:arm,代码行数:10,代码来源:uiTools.py


示例10: isExitAllowed

def isExitAllowed(ip, port, exitPolicy, isPrivateRejected):
  """
  Determines if a given connection is a permissable exit with the given 
  policy or not (True if it's allowed to be an exit connection, False 
  otherwise).
  
  NOTE: this is a little tricky and liable to need some tweaks
  """
  
  # might not be set when first starting up
  if not exitPolicy: return True
  
  # TODO: move into a utility and craft some unit tests (this is very error 
  # prone...)
  
  # TODO: currently doesn't consider ExitPolicyRejectPrivate (which prevents 
  # connections to private networks and local ip)
  for entry in exitPolicy.split(","):
    entry = entry.strip()
    
    isAccept = entry.startswith("accept")
    entry = entry[7:] # strips off "accept " or "reject "
    
    # parses ip address (with mask if provided) and port
    if ":" in entry:
      entryIP = entry[:entry.find(":")]
      entryPort = entry[entry.find(":") + 1:]
    else:
      entryIP = entry
      entryPort = "*"
    
    #raise AssertionError(str(exitPolicy) + " - " + entryIP + ":" + entryPort)
    isIPMatch = entryIP == ip or entryIP[0] == "*"
    
    if not "-" in entryPort:
      # single port
      isPortMatch = entryPort == str(port) or entryPort[0] == "*"
    else:
      # port range
      minPort = int(entryPort[:entryPort.find("-")])
      maxPort = int(entryPort[entryPort.find("-") + 1:])
      isPortMatch = port >= minPort and port <= maxPort
    
    # TODO: Currently being lazy and considering subnet masks or 'private' 
    # keyword to be equivilant to wildcard if it would reject, and none 
    # if it would accept (ie, being conservative with acceptance). Would be 
    # nice to fix at some point.
    if not isAccept: isIPMatch |= "/" in entryIP or entryIP == "private"
    
    if isIPMatch and isPortMatch: return isAccept
  
  # we shouldn't ever fall through due to default exit policy
  log.log(log.WARN, "Exit policy left connection uncategorized: %s:%i" % (ip, port))
  return False
开发者ID:katmagic,项目名称:arm,代码行数:54,代码来源:connPanel.py


示例11: eventTick

 def eventTick(self):
   """
   Processes a ps event.
   """
   
   psResults = {} # mapping of stat names to their results
   if self.queryPid and self.queryParam and self.failedCount < FAILURE_THRESHOLD:
     queryCmd = "ps -p %s -o %s" % (self.queryPid, ",".join(self.queryParam))
     psCall = sysTools.call(queryCmd, self.cacheTime, True)
     
     if psCall and len(psCall) == 2:
       # ps provided results (first line is headers, second is stats)
       stats = psCall[1].strip().split()
       
       if len(self.queryParam) == len(stats):
         # we have a result to match each stat - constructs mapping
         psResults = dict([(self.queryParam[i], stats[i]) for i in range(len(stats))])
         self.failedCount = 0 # had a successful call - reset failure count
     
     if not psResults:
       # ps call failed, if we fail too many times sequentially then abandon
       # listing (probably due to invalid ps parameters)
       self.failedCount += 1
       
       if self.failedCount == FAILURE_THRESHOLD:
         msg = "failed several attempts to query '%s', abandoning ps graph" % queryCmd
         log.log(self._config["log.graph.ps.abandon"], msg)
   
   # if something fails (no pid, ps call failed, etc) then uses last results
   primary, secondary = self.lastPrimary, self.lastSecondary
   
   for isPrimary in (True, False):
     if isPrimary: statName = self._config["features.graph.ps.primaryStat"]
     else: statName = self._config["features.graph.ps.secondaryStat"]
     
     if statName in psResults:
       try:
         result = float(psResults[statName])
         
         # The 'rss' and 'size' parameters provide memory usage in KB. This is
         # scaled up to MB so the graph's y-high is a reasonable value.
         if statName in ("rss", "size"): result /= 1024.0
         
         if isPrimary: primary = result
         else: secondary = result
       except ValueError:
         if self.queryParam != HEADER_PS_PARAM:
           # custom stat provides non-numeric results - give a warning and stop querying it
           msg = "unable to use non-numeric ps stat '%s' for graphing" % statName
           log.log(self._config["log.graph.ps.invalidStat"], msg)
           self.queryParam.remove(statName)
   
   self._processEvent(primary, secondary)
开发者ID:katmagic,项目名称:arm,代码行数:53,代码来源:psStats.py


示例12: __init__

 def __init__(self, processName, processPid = "", resolveRate = None, handle = None):
   """
   Initializes a new resolver daemon. When no longer needed it's suggested
   that this is stopped.
   
   Arguments:
     processName - name of the process being resolved
     processPid  - pid of the process being resolved
     resolveRate - time between resolving connections (in seconds, None if
                   chosen dynamically)
     handle      - name used to query this resolver, this is the processName
                   if undefined
   """
   
   threading.Thread.__init__(self)
   self.setDaemon(True)
   
   self.processName = processName
   self.processPid = processPid
   self.resolveRate = resolveRate
   self.handle = handle if handle else processName
   self.defaultRate = CONFIG["queries.connections.minRate"]
   self.lastLookup = -1
   self.overwriteResolver = None
   self.defaultResolver = Resolver.PROC
   
   osType = os.uname()[0]
   self.resolverOptions = getSystemResolvers(osType)
   
   log.log(CONFIG["log.connResolverOptions"], "Operating System: %s, Connection Resolvers: %s" % (osType, ", ".join(self.resolverOptions)))
   
   # sets the default resolver to be the first found in the system's PATH
   # (left as netstat if none are found)
   for resolver in self.resolverOptions:
     # Resolver strings correspond to their command with the exception of bsd
     # resolvers.
     resolverCmd = resolver.replace(" (bsd)", "")
     
     if resolver == Resolver.PROC or sysTools.isAvailable(resolverCmd):
       self.defaultResolver = resolver
       break
   
   self._connections = []        # connection cache (latest results)
   self._resolutionCounter = 0   # number of successful connection resolutions
   self._isPaused = False
   self._halt = False            # terminates thread if true
   self._cond = threading.Condition()  # used for pausing the thread
   self._subsiquentFailures = 0  # number of failed resolutions with the default in a row
   self._resolverBlacklist = []  # resolvers that have failed to resolve
   
   # Number of sequential times the threshold rate's been too low. This is to
   # avoid having stray spikes up the rate.
   self._rateThresholdBroken = 0
开发者ID:JustMe23,项目名称:arm,代码行数:53,代码来源:connections.py


示例13: handleKey

 def handleKey(self, key):
   isKeystrokeConsumed = True
   
   if key in (ord('n'), ord('N')) and torTools.getConn().isNewnymAvailable():
     self.sendNewnym()
   elif key in (ord('r'), ord('R')) and not self._isTorConnected:
     torctlConn = None
     allowPortConnection, allowSocketConnection, _ = starter.allowConnectionTypes()
     
     if os.path.exists(self._config["startup.interface.socket"]) and allowSocketConnection:
       try: torctlConn = torTools.connect_socket(self._config["startup.interface.socket"])
       except IOError, exc:
         if not allowPortConnection:
           cli.popups.showMsg("Unable to reconnect (%s)" % exc, 3)
     elif not allowPortConnection:
       cli.popups.showMsg("Unable to reconnect (socket '%s' doesn't exist)" % self._config["startup.interface.socket"], 3)
     
     if not torctlConn and allowPortConnection:
       # TODO: This has diverged from starter.py's connection, for instance it
       # doesn't account for relative cookie paths or multiple authentication
       # methods. We can't use the starter.py's connection function directly
       # due to password prompts, but we could certainly make this mess more
       # manageable.
       
       try:
         ctlAddr, ctlPort = self._config["startup.interface.ipAddress"], self._config["startup.interface.port"]
         tmpConn, authType, authValue = TorCtl.TorCtl.preauth_connect(ctlAddr, ctlPort)
         
         if authType == TorCtl.TorCtl.AUTH_TYPE.PASSWORD:
           authValue = cli.popups.inputPrompt("Controller Password: ")
           if not authValue: raise IOError() # cancel reconnection
         elif authType == TorCtl.TorCtl.AUTH_TYPE.COOKIE:
           authCookieSize = os.path.getsize(authValue)
           if authCookieSize != 32:
             raise IOError("authentication cookie '%s' is the wrong size (%i bytes instead of 32)" % (authValue, authCookieSize))
         
         tmpConn.authenticate(authValue)
         torctlConn = tmpConn
       except Exception, exc:
         # attempts to use the wizard port too
         try:
           cli.controller.getController().getTorManager().connectManagedInstance()
           log.log(log.NOTICE, "Reconnected to Tor's control port")
           cli.popups.showMsg("Tor reconnected", 1)
         except:
           # displays notice for the first failed connection attempt
           if exc.args: cli.popups.showMsg("Unable to reconnect (%s)" % exc, 3)
开发者ID:twilde,项目名称:arm,代码行数:47,代码来源:headerPanel.py


示例14: __init__

 def __init__(self, processName, processPid = "", resolveRate = None):
   """
   Initializes a new resolver daemon. When no longer needed it's suggested
   that this is stopped.
   
   Arguments:
     processName - name of the process being resolved
     processPid  - pid of the process being resolved
     resolveRate - time between resolving connections (in seconds, None if
                   chosen dynamically)
   """
   
   threading.Thread.__init__(self)
   self.setDaemon(True)
   
   self.processName = processName
   self.processPid = processPid
   self.resolveRate = resolveRate
   self.defaultRate = CONFIG["queries.connections.minRate"]
   self.lastLookup = -1
   self.overwriteResolver = None
   self.defaultResolver = CMD_NETSTAT
   
   osType = os.uname()[0]
   self.resolverOptions = getSystemResolvers(osType)
   
   resolverLabels = ", ".join([CMD_STR[option] for option in self.resolverOptions])
   log.log(CONFIG["log.connResolverOptions"], "Operating System: %s, Connection Resolvers: %s" % (osType, resolverLabels))
   
   # sets the default resolver to be the first found in the system's PATH
   # (left as netstat if none are found)
   for resolver in self.resolverOptions:
     if sysTools.isAvailable(CMD_STR[resolver]):
       self.defaultResolver = resolver
       break
   
   self._connections = []        # connection cache (latest results)
   self._isPaused = False
   self._halt = False            # terminates thread if true
   self._cond = threading.Condition()  # used for pausing the thread
   self._subsiquentFailures = 0  # number of failed resolutions with the default in a row
   self._resolverBlacklist = []  # resolvers that have failed to resolve
   
   # Number of sequential times the threshold rate's been too low. This is to
   # avoid having stray spikes up the rate.
   self._rateThresholdBroken = 0
开发者ID:katmagic,项目名称:arm,代码行数:46,代码来源:connections.py


示例15: _initColors

def _initColors():
  """
  Initializes color mappings usable by curses. This can only be done after
  calling curses.initscr().
  """
  
  global COLOR_ATTR_INITIALIZED, COLOR_IS_SUPPORTED
  if not COLOR_ATTR_INITIALIZED:
    # hack to replace all ACS characters with '+' if ACS support has been
    # manually disabled
    if not CONFIG["features.acsSupport"]:
      for item in curses.__dict__:
        if item.startswith("ACS_"):
          curses.__dict__[item] = ord('+')
      
      # replace a few common border pipes that are better rendered as '|' or
      # '-' instead
      
      curses.ACS_SBSB = ord('|')
      curses.ACS_VLINE = ord('|')
      curses.ACS_BSBS = ord('-')
      curses.ACS_HLINE = ord('-')
    
    COLOR_ATTR_INITIALIZED = True
    COLOR_IS_SUPPORTED = False
    if not CONFIG["features.colorInterface"]: return
    
    try: COLOR_IS_SUPPORTED = curses.has_colors()
    except curses.error: return # initscr hasn't been called yet
    
    # initializes color mappings if color support is available
    if COLOR_IS_SUPPORTED:
      colorpair = 0
      log.log(CONFIG["log.cursesColorSupport"], "Terminal color support detected and enabled")
      
      for colorName in COLOR_LIST:
        fgColor = COLOR_LIST[colorName]
        bgColor = -1 # allows for default (possibly transparent) background
        colorpair += 1
        curses.init_pair(colorpair, fgColor, bgColor)
        COLOR_ATTR[colorName] = curses.color_pair(colorpair)
    else:
      log.log(CONFIG["log.cursesColorSupport"], "Terminal color support unavailable")
开发者ID:refnode,项目名称:arm,代码行数:43,代码来源:uiTools.py


示例16: isTorrcAvailable

 def isTorrcAvailable(self):
   """
   True if a wizard generated torrc exists and the user has permissions to
   run it, false otherwise.
   """
   
   torrcLoc = self.getTorrcPath()
   if os.path.exists(torrcLoc):
     # If we aren't running as root and would be trying to bind to low ports
     # then the startup will fail due to permissons. Attempts to check for
     # this in the torrc. If unable to read the torrc then we probably
     # wouldn't be able to use it anyway with our permissions.
     
     if os.getuid() != 0:
       try:
         return not torConfig.isRootNeeded(torrcLoc)
       except IOError, exc:
         log.log(log.INFO, "Failed to read torrc at '%s': %s" % (torrcLoc, exc))
         return False
     else: return True
开发者ID:JustMe23,项目名称:arm,代码行数:20,代码来源:controller.py


示例17: heartbeatCheck

def heartbeatCheck(isUnresponsive):
  """
  Logs if its been ten seconds since the last BW event.
  
  Arguments:
    isUnresponsive - flag for if we've indicated to be responsive or not
  """
  
  conn = torTools.getConn()
  lastHeartbeat = conn.getHeartbeat()
  if conn.isAlive() and "BW" in conn.getControllerEvents():
    if not isUnresponsive and (time.time() - lastHeartbeat) >= 10:
      isUnresponsive = True
      log.log(log.NOTICE, "Relay unresponsive (last heartbeat: %s)" % time.ctime(lastHeartbeat))
    elif isUnresponsive and (time.time() - lastHeartbeat) < 10:
      # really shouldn't happen (meant Tor froze for a bit)
      isUnresponsive = False
      log.log(log.NOTICE, "Relay resumed")
  
  return isUnresponsive
开发者ID:JustMe23,项目名称:arm,代码行数:20,代码来源:controller.py


示例18: getIntCSV

 def getIntCSV(self, key, default = None, count = None, minValue = None, maxValue = None):
   """
   Fetches the given comma separated value, logging a TypeError (and returning
   the default) if the values arne't ints or aren't constrained to the given
   bounds.
   
   Arguments:
     key      - config setting to be fetched
     default  - value provided if no such key exists, doesn't match the count,
                values aren't all integers, or doesn't match the bounds
     count    - checks that the number of values matches this if set
     minValue - checks that all values are over this if set
     maxValue - checks that all values are less than this if set
   """
   
   confComp = self.getStrCSV(key, default, count)
   if confComp == default: return default
   
   # validates the input, setting the errorMsg if there's a problem
   errorMsg = None
   baseErrorMsg = "Config entry '%s' is expected to %%s" % key
   if default != None and (isinstance(default, list) or isinstance(default, tuple)):
     defaultStr = ", ".join([str(i) for i in default])
     baseErrorMsg += ", defaulting to '%s'" % defaultStr
   
   for val in confComp:
     if not val.isdigit():
       errorMsg = baseErrorMsg % "only have integer values"
       break
     else:
       if minValue != None and int(val) < minValue:
         errorMsg = baseErrorMsg % "only have values over %i" % minValue
         break
       elif maxValue != None and int(val) > maxValue:
         errorMsg = baseErrorMsg % "only have values less than %i" % maxValue
         break
   
   if errorMsg:
     log.log(CONFIG["log.configEntryTypeError"], errorMsg)
     return default
   else: return [int(val) for val in confComp]
开发者ID:JustMe23,项目名称:arm,代码行数:41,代码来源:conf.py


示例19: _resetSubwindow

 def _resetSubwindow(self):
   """
   Create a new subwindow instance for the panel if:
   - Panel currently doesn't have a subwindow (was uninitialized or
     invalidated).
   - There's room for the panel to grow vertically (curses automatically
     lets subwindows regrow horizontally, but not vertically).
   - The subwindow has been displaced. This is a curses display bug that
     manifests if the terminal's shrank then re-expanded. Displaced
     subwindows are never restored to their proper position, resulting in
     graphical glitches if we draw to them.
   - The preferred size is smaller than the actual size (should shrink).
   
   This returns True if a new subwindow instance was created, False otherwise.
   """
   
   newHeight, newWidth = self.getPreferredSize()
   if newHeight == 0: return False # subwindow would be outside its parent
   
   # determines if a new subwindow should be recreated
   recreate = self.win == None
   if self.win:
     subwinMaxY, subwinMaxX = self.win.getmaxyx()
     recreate |= subwinMaxY < newHeight              # check for vertical growth
     recreate |= self.top > self.win.getparyx()[0]   # check for displacement
     recreate |= subwinMaxX > newWidth or subwinMaxY > newHeight # shrinking
   
   # I'm not sure if recreating subwindows is some sort of memory leak but the
   # Python curses bindings seem to lack all of the following:
   # - subwindow deletion (to tell curses to free the memory)
   # - subwindow moving/resizing (to restore the displaced windows)
   # so this is the only option (besides removing subwindows entirely which 
   # would mean far more complicated code and no more selective refreshing)
   
   if recreate:
     self.win = self.parent.subwin(newHeight, newWidth, self.top, 0)
     
     # note: doing this log before setting win produces an infinite loop
     msg = "recreating panel '%s' with the dimensions of %i/%i" % (self.getName(), newHeight, newWidth)
     log.log(CONFIG["log.panelRecreated"], msg)
   return recreate
开发者ID:katmagic,项目名称:arm,代码行数:41,代码来源:panel.py


示例20: registerEvent

 def registerEvent(self, event):
   """
   Notes event and redraws log. If paused it's held in a temporary buffer.
   
   Arguments:
     event - LogEntry for the event that occurred
   """
   
   if not event.type in self.loggedEvents: return
   
   # strips control characters to avoid screwing up the terminal
   event.msg = uiTools.getPrintable(event.msg)
   
   # note event in the log file if we're saving them
   if self.logFile:
     try:
       self.logFile.write(event.getDisplayMessage(True) + "\n")
       self.logFile.flush()
     except IOError, exc:
       log.log(self._config["log.logPanel.logFileWriteFailed"], "Unable to write to log file: %s" % sysTools.getFileErrorMsg(exc))
       self.logFile = None
开发者ID:katmagic,项目名称:arm,代码行数:21,代码来源:logPanel.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python logger.debug函数代码示例发布时间:2022-05-26
下一篇:
Python log.info函数代码示例发布时间: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