コード例 #1
0
ファイル: log.py プロジェクト: fcwu/lp-fish-init
    def set(cls, log_level, log_filename, append):
        """ Configure a rotating file logging
        """
        logger = logging.getLogger()
        logger.setLevel(logging.DEBUG)

        # Log to sys.stderr using log level passed through command line
        if log_level != logging.NOTSET:
            log_handler = logging.StreamHandler(sys.stdout)
            if sys.platform.find('linux') >= 0:
                formatter = ColoredFormatter(cls.COLOR_FORMAT)
            else:
                formatter = ColoredFormatter(cls.NO_COLOR_FORMAT, False)
            log_handler.setFormatter(formatter)
            log_handler.setLevel(log_level)
            logger.addHandler(log_handler)
            getDefaultLogger(log_handler)

        # Log to rotating file using DEBUG log level
        log_handler = logging.handlers.RotatingFileHandler(log_filename,
                                                           mode='a+',
                                                           backupCount=3)
        formatter = logging.Formatter('%(asctime)s %(levelname)-8s '
                                      '%(message)s')
        log_handler.setFormatter(formatter)
        log_handler.setLevel(logging.DEBUG)
        logger.addHandler(log_handler)

        if not append:
            # Create a new log file on every new
            # (i.e. not scheduled) invocation
            log_handler.doRollover()
コード例 #2
0
ファイル: Connection.py プロジェクト: etradewind/Tundra2
 def __init__(self, *args, **kwArgs):
     DAV.__init__(self, *args, **kwArgs)
     self.__authorizationInfo = None
     self.logger = getDefaultLogger()
     self.isConnectedToCatacomb = True
     self.serverTypeChecked = False
     self.lock = RLock()
コード例 #3
0
ファイル: Connection.py プロジェクト: khertan/KhtNotes
 def __init__(self, *args, **kwArgs):
     DAV.__init__(self, *args, **kwArgs)
     self.__authorizationInfo = None
     self.logger = getDefaultLogger()
     self.isConnectedToCatacomb = True
     self.serverTypeChecked = False
     self._lock = RLock()
コード例 #4
0
def getDefaultLogger():
    """ 
    Returns a configured logger object.
    
    @return: Logger instance.
    @rtype: C{logging.Logger}
    """
    
    myLogger = logging.getLogger(None)
    if len(myLogger.handlers) == 0:
        from webdav import logger 
        webdavLogger = logger.getDefaultLogger(_getFileHandler(_webdavLogFileName))
        webdavLogger.level = logging.INFO
        myLogger.level = logging.INFO
        myLogger.addHandler(_getFileHandler(_logFileName))
    return myLogger
コード例 #5
0
class LiveProperties(object):
    """
    This class provides convenient access to the WebDAV 'live' properties of a resource.
    WebDav 'live' properties are defined in RFC 4918, Section 15. 
    Each property is converted from string to its natural data type.
    
    @version: $Revision$
    @author: Roland Betz
    """

    # restrict instance variables
    __slots__ = ('properties')

    NAMES = (Constants.PROP_CREATION_DATE, Constants.PROP_DISPLAY_NAME,
             Constants.PROP_CONTENT_LENGTH, Constants.PROP_CONTENT_TYPE,
             Constants.PROP_ETAG, Constants.PROP_LAST_MODIFIED,
             Constants.PROP_OWNER, Constants.PROP_LOCK_DISCOVERY,
             Constants.PROP_RESOURCE_TYPE, Constants.PROP_SUPPORTED_LOCK)
    _logger = logger.getDefaultLogger()

    def __init__(self, properties=None, propElement=None):
        """
        Construct C{LiveProperties} from a dictionary of properties containing
        live properties or from a XML 'prop' element.
        
        @param properties: map as implemented by class L{PropertyResponse}
        @param propElement: C{Element} value
        """

        assert isinstance(properties, PropertyResponse) or \
               isinstance(propElement, qp_xml._element), \
                "Argument properties has type %s" % str(type(properties))
        self.properties = dict()
        for name, value in properties.items():
            if name[0] == Constants.NS_DAV and name[1] in self.NAMES:
                self.properties[name[1]] = value

    def getContentLanguage(self):
        """
        Return the language of a resource's textual content or C{None}.
        
        @rtype: C{string}
        """

        xml = self.properties.get(Constants.PROP_CONTENT_LANGUAGE)
        if xml:
            return xml.textof()

    def getContentLength(self):
        """
        Returns the length of the resource's content in bytes or C{None}.
        
        @rtype: C{int}
        """

        xml = self.properties.get(Constants.PROP_CONTENT_LENGTH)
        if xml:
            try:
                return int(xml.textof())
            except (ValueError, TypeError):
                self._logger.debug(
                    "Cannot convert content length to a numeric value.",
                    exc_info=True)

    def getContentType(self):
        """
        Return the resource's content MIME type or C{None}.
        
        @rtype: C{string}
        """

        xml = self.properties.get(Constants.PROP_CONTENT_TYPE)
        if xml:
            return xml.textof()

    def getCreationDate(self):
        """
        Return the creation date as time tuple or C{None}.
                
        @rtype: C{time.struct_time}
        """

        datetimeString = None
        xml = self.properties.get(Constants.PROP_CREATION_DATE)
        if xml:
            datetimeString = xml.textof()

        if datetimeString:
            try:
                return _parseIso8601String(datetimeString)
            except ValueError:
                self._logger.debug(
                    "Invalid date format: The server must provide an ISO8601 formatted date string.",
                    exc_info=True)

    def getEntityTag(self):
        """
        Return a entity tag which is unique for a particular version of a resource or C{None}.
        Different resources or one resource before and after modification have different etags. 
        
        @rtype: C{string}
        """

        xml = self.properties.get(Constants.PROP_ETAG)
        if xml:
            return xml.textof()

    def getDisplayName(self):
        """
        Returns a resource's display name or C{None}.
        
        @rtype: C{string}
        """

        xml = self.properties.get(Constants.PROP_DISPLAY_NAME)
        if xml:
            return xml.textof()

    def getLastModified(self):
        """
        Return last modification of a resource as time tuple or C{None}.
        
        @rtype: C{time.struct_time}
        """

        datetimeString = None
        xml = self.properties.get(Constants.PROP_LAST_MODIFIED)
        if xml:
            datetimeString = xml.textof()

        if datetimeString:
            try:
                result = rfc822.parsedate(datetimeString)
                if result is None:
                    result = _parseIso8601String(
                        datetimeString
                    )  # Some servers like Tamino use ISO 8601
                return time.struct_time(result)
            except ValueError:
                self._logger.debug(
                    "Invalid date format: "
                    "The server must provide a RFC822 or ISO8601 formatted date string.",
                    exc_info=True)

    def getLockDiscovery(self):
        """
        Return all current locks applied to a resource or C{None} if it is not locked. The lock is represented by 
        a C{lockdiscovery} DOM element according to RFC 4918, Section 15.8.1.
        
        @rtype: C{string}
        """

        xml = self.properties.get(Constants.PROP_LOCK_DISCOVERY)
        if xml:
            return _scanLockDiscovery(xml)

    def getResourceType(self):
        """
        Return a resource's WebDAV type:
         * 'collection' => WebDAV Collection
         * 'resource' => WebDAV resource
        @rtype: C{string}
        """

        xml = self.properties.get(Constants.PROP_RESOURCE_TYPE)
        if xml and xml.children:
            return xml.children[0].name
        return "resource"

    def getSupportedLock(self):
        """
        Return a DOM element describing all supported lock options for a resource.
        Shared and exclusive write locks are usually supported. The supported locks are represented by       
        a C{supportedlock} DOM element according to RFC 4918, Section 15.10.1.
        
        rtype: C{string}
        """

        return self.properties.get(Constants.PROP_SUPPORTED_LOCK)

    def getOwnerAsUrl(self):
        """
        Return a resource's owner represented as URL or C{None}.
        
        @rtype: C{string}
        """

        xml = self.properties.get(Constants.PROP_OWNER)
        if xml and xml.children:
            return xml.children[0].textof()

    def __str__(self):
        result = ""
        result += " Name=%s" % self.getDisplayName()
        result += "\n Type=%s" % self.getResourceType()
        result += "\n Length=%s" % self.getContentLength()
        result += "\n Content Type=%s" % self.getContentType()
        result += "\n ETag=%s" % self.getEntityTag()
        result += "\n Created="
        if self.getCreationDate():
            result += time.strftime("%c GMT", self.getCreationDate())
        else:
            result += "None"
        result += "\n Modified="
        if self.getLastModified():
            result += time.strftime("%c GMT", self.getLastModified())
        else:
            result += "None"
        return result