Пример #1
0
 def copy(from_info, to_info):
     System.copy(from_info, to_info)
Пример #2
0
 def symlink(from_info, to_info):
     System.symlink(from_info, to_info)
Пример #3
0
def get_inode(path):
    inode = System.inode(path)
    logger.debug("Path '%s' inode '%d'", path, inode)
    return inode
Пример #4
0
    tmp_dir.dvc_gen({"foo": "foo", "bar": "bar"})

    shutil.copy("bar", "foo")

    copy_spy = mocker.spy(dvc.cache.local.tree, "copy")

    dvc.add("foo")

    assert copy_spy.mock.call_count == 0


@pytest.mark.parametrize(
    "link,new_link,link_test_func",
    [
        ("hardlink", "copy", lambda path: not System.is_hardlink(path)),
        ("symlink", "copy", lambda path: not System.is_symlink(path)),
        ("copy", "hardlink", System.is_hardlink),
        ("copy", "symlink", System.is_symlink),
    ],
)
def test_should_relink_on_repeated_add(link, new_link, link_test_func, tmp_dir,
                                       dvc):
    from dvc.path_info import PathInfo

    dvc.config["cache"]["type"] = link

    tmp_dir.dvc_gen({"foo": "foo", "bar": "bar"})

    os.remove("foo")
    getattr(dvc.cache.local.tree, link)(PathInfo("bar"), PathInfo("foo"))
Пример #5
0
def get_inode(path):
    inode = System.inode(path)
    logger.debug("Path {} inode {}".format(path, inode))
    return inode
Пример #6
0
 def reflink(from_info, to_info):
     System.reflink(from_info, to_info)
Пример #7
0
 def inode(path):
     return str(System.inode(path))
Пример #8
0
 def is_hardlink(path_info):
     return System.is_hardlink(path_info)
Пример #9
0
 def is_symlink(path_info):
     return System.is_symlink(path_info)
Пример #10
0
 def iscopy(self, path_info):
     return not (
         System.is_symlink(path_info) or System.is_hardlink(path_info)
     )
Пример #11
0
    def _do_draw(self, screen):  # pragma: no cover
        # pylint: disable=too-many-locals
        # pylint: disable=too-many-branches, too-many-statements
        from dvc.system import System
        from asciimatics.event import KeyboardEvent

        offset_x = 0
        offset_y = 0
        smaxrow, smaxcol = screen.dimensions
        assert smaxrow > 1
        assert smaxcol > 1
        smaxrow -= 1
        smaxcol -= 1

        if self.lines + 1 > smaxrow:
            max_y = self.lines + 1 - smaxrow
        else:
            max_y = 0

        if self.cols + 1 > smaxcol:
            max_x = self.cols + 1 - smaxcol
        else:
            max_x = 0

        while True:
            for y in range(smaxrow + 1):
                y_index = offset_y + y
                line = []
                for x in range(smaxcol + 1):
                    x_index = offset_x + x
                    if (
                        len(self.canvas) > y_index
                        and len(self.canvas[y_index]) > x_index
                    ):
                        line.append(self.canvas[y_index][x_index])
                    else:
                        line.append(" ")
                assert len(line) == (smaxcol + 1)
                screen.print_at("".join(line), 0, y)

            screen.refresh()

            # NOTE: get_event() doesn't block by itself,
            # so we have to do the blocking ourselves.
            #
            # NOTE: using this workaround while waiting for PR [1]
            # to get merged and released. After that need to adjust
            # asciimatics version requirements.
            #
            # [1] https://github.com/peterbrittain/asciimatics/pull/188
            System.wait_for_input(self.TIMEOUT)

            event = screen.get_event()
            if not isinstance(event, KeyboardEvent):
                continue

            k = event.key_code
            if k == screen.KEY_DOWN or k == ord("s"):
                offset_y += 1
            elif k == screen.KEY_PAGE_DOWN or k == ord("S"):
                offset_y += smaxrow
            elif k == screen.KEY_UP or k == ord("w"):
                offset_y -= 1
            elif k == screen.KEY_PAGE_UP or k == ord("W"):
                offset_y -= smaxrow
            elif k == screen.KEY_RIGHT or k == ord("d"):
                offset_x += 1
            elif k == ord("D"):
                offset_x += smaxcol
            elif k == screen.KEY_LEFT or k == ord("a"):
                offset_x -= 1
            elif k == ord("A"):
                offset_x -= smaxcol
            elif k == ord("q") or k == ord("Q"):
                break

            if offset_y > max_y:
                offset_y = max_y
            elif offset_y < 0:
                offset_y = 0

            if offset_x > max_x:
                offset_x = max_x
            elif offset_x < 0:
                offset_x = 0