def action_put(backend, inp, out):
    filename = read_safe_filename(inp)
    tmp = NamedTemporaryFile(delete=False)
    try:
        try:
            copyfileobj(inp, tmp.file)
        finally:
            tmp.file.close()
        backend.put(duplicity.path.Path(tmp.name), filename)
        out.write(StatusCodes.OK)
    finally:
        os.remove(tmp.name)
Esempio n. 2
0
    def try_basic(self, backend):
        """Try basic operations with given backend.

        Requires backend be empty at first, and all operations are
        allowed.

        """
        def cmp_list(l):
            """Assert that backend.list is same as l"""
            blist = backend.list()
            blist.sort()
            l.sort()
            assert blist == l, \
                   ("Got list: %s\nWanted: %s\n" % (repr(blist), repr(l)))

        # Identify test that's running
        print self.my_test_id, "... ",

        assert not os.system("rm -rf testfiles/backend_tmp")
        assert not os.system("mkdir testfiles/backend_tmp")

        regpath = path.Path("testfiles/various_file_types/regular_file")
        normal_file = "testfile"
        colonfile = ("file%swith.%scolons_-and%s%setc" %
                     ((globals.time_separator,) * 4))
        tmpregpath = path.Path("testfiles/backend_tmp/regfile")

        # Test list and put
        cmp_list([])
        backend.put(regpath, normal_file)
        cmp_list([normal_file])
        backend.put(regpath, colonfile)
        cmp_list([normal_file, colonfile])

        # Test get
        regfilebuf = regpath.open("rb").read()
        backend.get(colonfile, tmpregpath)
        backendbuf = tmpregpath.open("rb").read()
        assert backendbuf == regfilebuf

        # Test delete
        backend.delete([colonfile, normal_file])
        cmp_list([])
Esempio n. 3
0
    def try_basic(self, backend):
        """Try basic operations with given backend.

        Requires backend be empty at first, and all operations are
        allowed.

        """
        def cmp_list(l):
            """Assert that backend.list is same as l"""
            blist = backend.list()
            blist.sort()
            l.sort()
            assert blist == l, \
                   ("Got list: %s  Wanted: %s\n" % (repr(blist), repr(l)))

        # Identify test that's running
        print self.my_test_id, "... ",

        assert not os.system("rm -rf testfiles/backend_tmp")
        assert not os.system("mkdir testfiles/backend_tmp")

        regpath = path.Path("testfiles/various_file_types/regular_file")
        normal_file = "testfile"
        colonfile = ("file%swith.%scolons_-and%s%setc" %
                     ((globals.time_separator,) * 4))
        tmpregpath = path.Path("testfiles/backend_tmp/regfile")

        # Test list and put
        cmp_list([])
        backend.put(regpath, normal_file)
        cmp_list([normal_file])
        backend.put(regpath, colonfile)
        cmp_list([normal_file, colonfile])

        # Test get
        regfilebuf = regpath.open("rb").read()
        backend.get(colonfile, tmpregpath)
        backendbuf = tmpregpath.open("rb").read()
        assert backendbuf == regfilebuf

        # Test delete
        backend.delete([colonfile, normal_file])
        cmp_list([])