rorpiter.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:rdiff-backup 作者: sol1 项目源码 文件源码
def FillInIter(rpiter, rootrp):
    """Given ordered rpiter and rootrp, fill in missing indicies with rpaths

    For instance, suppose rpiter contains rpaths with indicies (),
    (1,2), (2,5).  Then return iter with rpaths (), (1,), (1,2), (2,),
    (2,5).  This is used when we need to process directories before or
    after processing a file in that directory.

    """
    # Handle first element as special case
    first_rp = rpiter.next() # StopIteration gets passed upwards
    cur_index = first_rp.index
    for i in range(len(cur_index)): yield rootrp.new_index(cur_index[:i])
    yield first_rp
    del first_rp
    old_index = cur_index

    # Now do all the other elements
    for rp in rpiter:
        cur_index = rp.index
        if not cur_index[:-1] == old_index[:-1]: # Handle special case quickly
            for i in range(1, len(cur_index)): # i==0 case already handled
                if cur_index[:i] != old_index[:i]:
                    filler_rp = rootrp.new_index(cur_index[:i])
                    if not filler_rp.isdir():
                        log.Log("Warning: expected %s to be a directory but "
                                "found %s instead.\nThis is probably caused "
                                "by a bug in versions 1.0.0 and earlier." %
                                (filler_rp.path, filler_rp.lstat()), 2)
                        filler_rp.make_zero_dir(rootrp)
                    yield filler_rp
        yield rp
        old_index = cur_index
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号