def copytree(dc, src, dst, overwrite=None): """ copy a tree of resources to another location dc -- dataclass to use src -- src uri from where to copy dst -- dst uri overwrite -- if 1 then delete dst uri before returns dict of uri:error_code tuples from which another method can create a multistatus xml element. """ # first delete the destination resource if overwrite and dc.exists(dst): delres = deltree(dc, dst) else: delres = {} # if we cannot delete everything, then do not copy! if delres: return delres # get the tree we have to copy tlist = create_treelist(dc, src) result = {} # prepare destination URIs (get the prefix) dpath = urlparse.urlparse(dst)[2] for element in tlist: problem_uris = result.keys() # now URIs get longer and longer thus we have # to test if we had a parent URI which we were not # able to copy in problem_uris which is the prefix # of the actual element. If it is, then we cannot # copy this as well but do not generate another error. ok = 1 for p in problem_uris: if is_prefix(p, element): ok = None break if not ok: continue # now create the destination URI which corresponds to # the actual source URI. -> actual_dst # ("subtract" the base src from the URI and prepend the # dst prefix to it.) esrc = replace(element, src, "") actual_dst = dpath + esrc # now copy stuff try: copy(dc, element, actual_dst) except DAV_Error, (ec, dd): result[element] = ec
def copytree(dc,src,dst,overwrite=None): """ copy a tree of resources to another location dc -- dataclass to use src -- src uri from where to copy dst -- dst uri overwrite -- if 1 then delete dst uri before returns dict of uri:error_code tuples from which another method can create a multistatus xml element. """ # first delete the destination resource if overwrite and dc.exists(dst): delres=deltree(dc,dst) else: delres={} # if we cannot delete everything, then do not copy! if delres: return delres # get the tree we have to copy tlist = create_treelist(dc,src) result = {} # prepare destination URIs (get the prefix) dpath = urlparse.urlparse(dst)[2] for element in tlist: problem_uris = result.keys() # now URIs get longer and longer thus we have # to test if we had a parent URI which we were not # able to copy in problem_uris which is the prefix # of the actual element. If it is, then we cannot # copy this as well but do not generate another error. ok=1 for p in problem_uris: if is_prefix(p,element): ok=None break if not ok: continue # now create the destination URI which corresponds to # the actual source URI. -> actual_dst # ("subtract" the base src from the URI and prepend the # dst prefix to it.) esrc=replace(element,src,"") actual_dst=dpath+esrc # now copy stuff try: copy(dc,element,actual_dst) except DAV_Error, (ec,dd): result[element]=ec
def deltree(dc, uri, exclude={}): """ delete a tree of resources dc -- dataclass to use uri -- root uri to delete exclude -- an optional list of uri:error_code pairs which should not be deleted. returns dict of uri:error_code tuples from which another method can create a multistatus xml element. Also note that we only know Depth=infinity thus we don't have to test for it. """ tlist = create_treelist(dc, uri) result = {} for i in range(len(tlist), 0, -1): problem_uris = result.keys() element = tlist[i - 1] # test here, if an element is a prefix of an uri which # generated an error before. # note that we walk here from childs to parents, thus # we cannot delete a parent if a child made a problem. # (see example in 8.6.2.1) ok = 1 for p in problem_uris: if is_prefix(element, p): ok = None break if not ok: continue # here we test for the exclude list which is the other way round! for p in exclude.keys(): if is_prefix(p, element): ok = None break if not ok: continue # now delete stuff try: delone(dc, element) except DAV_Error, (ec, dd): result[element] = ec