def moveProperties(self, srcurl, desturl, withChildren, environ=None): _logger.debug("moveProperties(%s, %s, %s)" % (srcurl, desturl, withChildren)) self._lock.acquireWrite() try: if __debug__ and self._verbose >= 2: self._check() if not self._loaded: self._lazyOpen() if withChildren: # Move srcurl\* for url in self._dict.keys(): if util.isEqualOrChildUri(srcurl, url): d = url.replace(srcurl, desturl) self._dict[d] = self._dict[url] del self._dict[url] # print "moveProperties:", url, d elif srcurl in self._dict: # Move srcurl only self._dict[desturl] = self._dict[srcurl] del self._dict[srcurl] self._sync() if __debug__ and self._verbose >= 2: self._check("after move") finally: self._lock.release()
def moveProperties(self, srcurl, desturl, withChildren): _logger.debug("moveProperties(%s, %s, %s)" % (srcurl, desturl, withChildren)) self._lock.acquireWrite() try: if __debug__ and self._verbose >= 2: self._check() if not self._loaded: self._lazyOpen() if withChildren: # Move srcurl\* for url in self._dict.keys(): if util.isEqualOrChildUri(srcurl, url): d = url.replace(srcurl, desturl) self._dict[d] = self._dict[url] del self._dict[url] # print "moveProperties:", url, d elif srcurl in self._dict: # Move srcurl only self._dict[desturl] = self._dict[srcurl] del self._dict[srcurl] self._sync() if __debug__ and self._verbose >= 2: self._check("after move") finally: self._lock.release()
def copyMoveSingle(self, destPath, isMove): """See DAVResource.copyMoveSingle() """ if self.provider.readonly: raise DAVError(HTTP_FORBIDDEN) fpDest = self.provider._locToFilePath(destPath, self.environ) assert not util.isEqualOrChildUri(self.path, destPath) # Create destination collection, if not exists if not os.path.exists(fpDest): os.mkdir(fpDest) try: # may raise: [Error 5] Permission denied: # u'C:\\temp\\litmus\\ccdest' shutil.copystat(self._filePath, fpDest) except Exception as e: _logger.debug("Could not copy folder stats: %s" % e) # (Live properties are copied by copy2 or copystat) # Copy dead properties propMan = self.provider.propManager if propMan: destRes = self.provider.getResourceInst(destPath, self.environ) if isMove: propMan.moveProperties(self.getRefUrl(), destRes.getRefUrl(), withChildren=False) else: propMan.copyProperties(self.getRefUrl(), destRes.getRefUrl())
def moveRecursive(self, destPath): """See DAVResource.moveRecursive() """ if self.provider.readonly: raise DAVError(HTTP_FORBIDDEN) assert not util.isEqualOrChildUri(self.path, destPath) self.nibbler.move(self.path.rstrip('/'), destPath.rstrip('/'))
def moveRecursive(self, destPath): """See DAVResource.moveRecursive() """ if self.provider.readonly: raise DAVError(HTTP_FORBIDDEN) assert not util.isEqualOrChildUri(self.path, destPath) self.nibbler.move(self.path.rstrip('/').decode('utf8'), destPath.rstrip('/').decode('utf8'))
def copyMoveSingle(self, destPath, isMove): """See DAVResource.copyMoveSingle() """ if self.provider.readonly: raise DAVError(HTTP_FORBIDDEN) assert not util.isEqualOrChildUri(self.path, destPath) if isMove: self.nibbler.move(self.path.rstrip('/'), destPath.rstrip('/')) else: self.nibbler.copy(self.path.rstrip('/'), destPath.rstrip('/'))
def copyMoveSingle(self, destPath, isMove): """See DAVResource.copyMoveSingle() """ if self.provider.readonly: raise DAVError(HTTP_FORBIDDEN) assert not util.isEqualOrChildUri(self.path, destPath) if isMove: self.nibbler.move(self.path.rstrip('/').decode('utf8'), destPath.rstrip('/').decode('utf8')) else: self.nibbler.copy(self.path.rstrip('/').decode('utf8'), destPath.rstrip('/').decode('utf8'))
def moveRecursive(self, destPath): """See DAVResource.moveRecursive() """ if self.provider.readonly: raise DAVError(HTTP_FORBIDDEN) assert not util.isEqualOrChildUri(self.path, destPath) try: self.nibbler.move(self.path.rstrip('/'), destPath.rstrip('/')) except Exception, err: logger.error('copyMoveSingle %s %s : %s'%(self.path, destPath, err))
def moveRecursive(self, destPath): """See DAVResource.moveRecursive() """ if self.provider.readonly: raise DAVError(HTTP_FORBIDDEN) assert not util.isEqualOrChildUri(self.path, destPath) try: self.nibbler.move(self.path.rstrip('/'), destPath.rstrip('/')) except Exception, err: logger.error('copyMoveSingle %s %s : %s' % (self.path, destPath, err))
def moveRecursive(self, destPath): """See DAVResource.moveRecursive() """ if self.provider.readonly: raise DAVError(HTTP_FORBIDDEN) fpDest = self.provider._locToFilePath(destPath, self.environ) assert not util.isEqualOrChildUri(self.path, destPath) assert not os.path.exists(fpDest) _logger.debug("moveRecursive(%s, %s)" % (self._filePath, fpDest)) shutil.move(self._filePath, fpDest) # (Live properties are copied by copy2 or copystat) # Move dead properties if self.provider.propManager: destRes = self.provider.getResourceInst(destPath, self.environ) self.provider.propManager.moveProperties(self.getRefUrl(), destRes.getRefUrl(), withChildren=True)
def copyMoveSingle(self, destPath, isMove): """See DAVResource.copyMoveSingle() """ if self.provider.readonly: raise DAVError(HTTP_FORBIDDEN) fpDest = self.provider._locToFilePath(destPath, self.environ) assert not util.isEqualOrChildUri(self.path, destPath) # Copy file (overwrite, if exists) shutil.copy2(self._filePath, fpDest) # (Live properties are copied by copy2 or copystat) # Copy dead properties propMan = self.provider.propManager if propMan: destRes = self.provider.getResourceInst(destPath, self.environ) if isMove: propMan.moveProperties(self.getRefUrl(), destRes.getRefUrl(), withChildren=False) else: propMan.copyProperties(self.getRefUrl(), destRes.getRefUrl())
def testBasics(self): """Test basic tool functions.""" assert joinUri("/a/b", "c") == "/a/b/c" assert joinUri("/a/b/", "c") == "/a/b/c" assert joinUri("/a/b", "c", "d") == "/a/b/c/d" assert joinUri("a/b", "c", "d") == "a/b/c/d" assert joinUri("/", "c") == "/c" assert joinUri("", "c") == "/c" assert not isChildUri("/a/b", "/a/") assert not isChildUri("/a/b", "/a/b") assert not isChildUri("/a/b", "/a/b/") assert not isChildUri("/a/b", "/a/bc") assert not isChildUri("/a/b", "/a/bc/") assert isChildUri("/a/b", "/a/b/c") assert isChildUri("/a/b", "/a/b/c") assert not isEqualOrChildUri("/a/b", "/a/") assert isEqualOrChildUri("/a/b", "/a/b") assert isEqualOrChildUri("/a/b", "/a/b/") assert not isEqualOrChildUri("/a/b", "/a/bc") assert not isEqualOrChildUri("/a/b", "/a/bc/") assert isEqualOrChildUri("/a/b", "/a/b/c") assert isEqualOrChildUri("/a/b", "/a/b/c") assert lstripstr("/dav/a/b", "/dav") == "/a/b" assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b" assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b" assert popPath("/a/b/c") == ("a", "/b/c") assert popPath("/a/b/") == ("a", "/b/") assert popPath("/a/") == ("a", "/") assert popPath("/a") == ("a", "/") assert popPath("/") == ("", "") assert popPath("") == ("", "") self.assertEqual(shiftPath("", "/a/b/c"), ("a", "/a", "/b/c")) self.assertEqual(shiftPath("/a", "/b/c"), ("b", "/a/b", "/c")) self.assertEqual(shiftPath("/a/b", "/c"), ("c", "/a/b/c", "")) self.assertEqual(shiftPath("/a/b/c", "/"), ("", "/a/b/c", "")) self.assertEqual(shiftPath("/a/b/c", ""), ("", "/a/b/c", ""))
def isUrlLockedByToken(self, url, locktoken): """Check, if url (or any of it's parents) is locked by locktoken.""" lockUrl = self.getLock(locktoken, "root") return lockUrl and util.isEqualOrChildUri(lockUrl, url)