コード例 #1
0
def copyXAttrs(from_fp, to_fp):    
    # Create xattr stores for each file and copy over all xattrs.
    xfrom = xattrPropertyStore(FakeXAttrResource(from_fp))
    xto = xattrPropertyStore(FakeXAttrResource(to_fp))

    for item in xfrom.list():
        xto.set(xfrom.get(item))
コード例 #2
0
def putWithXAttrs(stream, filepath):
    """
    Write a file to a possibly existing path and preserve any xattrs at that path.
    
    @param stream: the stream to write to the destination.
    @type stream: C{file}
    @param filepath: the destination file.
    @type filepath: L{FilePath}
    """
    
    # Preserve existings xattrs
    props = []
    if filepath.exists():
        xold = xattrPropertyStore(FakeXAttrResource(filepath))
        for item in xold.list():
            props.append((xold.get(item)))
        xold = None
    
    # First do the actual file copy
    def _gotResponse(response):
    
        # Restore original xattrs.
        if props:
            xnew = xattrPropertyStore(FakeXAttrResource(filepath))
            for prop in props:
                xnew.set(prop)
            xnew = None
    
        return response

    d = put(stream, filepath)
    d.addCallback(_gotResponse)
    return d
コード例 #3
0
 def setUp(self):
     """
     Create a resource and a xattr property store for it.
     """
     self.resourcePath = FilePath(self.mktemp())
     self.resourcePath.setContent("")
     self.attrs = xattr(self.resourcePath.path)
     self.resource = DAVFile(self.resourcePath.path)
     self.propertyStore = xattrPropertyStore(self.resource)
コード例 #4
0
 def _gotResponse(response):
 
     # Restore original xattrs.
     if props:
         xnew = xattrPropertyStore(FakeXAttrResource(filepath))
         for prop in props:
             xnew.set(prop)
         xnew = None
 
     return response
コード例 #5
0
    def test_listMissing(self):
        """
        Test missing file.
        """

        resourcePath = FilePath(self.mktemp())
        resource = DAVFile(resourcePath.path)
        propertyStore = xattrPropertyStore(resource)

        # Try to get a property from it - and fail.
        self.assertEqual(propertyStore.list(), [])
コード例 #6
0
    def test_containsMissing(self):
        """
        Test missing file.
        """

        resourcePath = FilePath(self.mktemp())
        resource = DAVFile(resourcePath.path)
        propertyStore = xattrPropertyStore(resource)

        # Try to get a property from it - and fail.
        document = self._makeValue()
        self.assertFalse(propertyStore.contains(document.root_element.qname()))
コード例 #7
0
ファイル: test_xattrprops.py プロジェクト: jrossi/twext
    def test_getMissing(self):
        """
        Test missing file.
        """

        resourcePath = FilePath(self.mktemp())
        resource = DAVFile(resourcePath.path)
        propertyStore = xattrPropertyStore(resource)

        # Try to get a property from it - and fail.
        document = self._makeValue()
        error = self.assertRaises(HTTPError, propertyStore.get, document.root_element.qname())

        # Make sure that the status is NOT FOUND.
        self.assertEquals(error.response.code, NOT_FOUND)