~ubuntu-branches/ubuntu/trusty/duplicity/trusty

« back to all changes in this revision

Viewing changes to duplicity/backends/tahoebackend.py

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2011-12-06 14:15:01 UTC
  • mfrom: (1.9.4)
  • Revision ID: package-import@ubuntu.com-20111206141501-nvfaaauqivpwyb7f
Tags: 0.6.17-0ubuntu1
* New upstream release
* debian/patches/06_use_passphrase.dpatch,
  debian/patches/07_large_rackspace_list.dpatch,
  debian/patches/08_check_volumes.dpatch:
  - Dropped, applied upstream
* debian/rules:
  - Run new upstream test suite during build
* debian/control:
  - Add rdiff as a build-dep to run above test suite
* debian/patches/06testfixes.dpatch:
  - Fix a few tests to not fail erroneously
* debian/patches/07fixincresume.dpatch:
  - Fix a bug with resuming an incremental backup that would result in
    a bogus error.  Also patches in a test for it.
* debian/tests/full-cycle-local:
  - New DEP-8 test script that backs up locally, restores, and checks files
* debian/tests/full-cycle-u1:
  - New DEP-8 test script that does the same as above, but to Ubuntu One
* debian/tests/control:
  - Start of DEP-8 test suite.  Only enable above full-cycle-local test
    for automatic execution.  The other is for manual testing right now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
 
2
#
 
3
# Copyright 2008 Francois Deppierraz
 
4
#
 
5
# This file is part of duplicity.
 
6
#
 
7
# Duplicity is free software; you can redistribute it and/or modify it
 
8
# under the terms of the GNU General Public License as published by the
 
9
# Free Software Foundation; either version 3 of the License, or (at your
 
10
# option) any later version.
 
11
#
 
12
# Duplicity is distributed in the hope that it will be useful, but
 
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
# General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with duplicity; if not, write to the Free Software Foundation,
 
19
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
20
 
 
21
import duplicity.backend
 
22
from duplicity import log
 
23
from duplicity.errors import * #@UnusedWildImport
 
24
 
 
25
from commands import getstatusoutput
 
26
 
 
27
class TAHOEBackend(duplicity.backend.Backend):
 
28
    """
 
29
    Backend for the Tahoe file system
 
30
    """
 
31
 
 
32
    def __init__(self, parsed_url):
 
33
        duplicity.backend.Backend.__init__(self, parsed_url)
 
34
 
 
35
        url = parsed_url.path.strip('/').split('/')
 
36
 
 
37
        self.alias = url[0]
 
38
 
 
39
        if len(url) > 2:
 
40
            self.directory = "/".join(url[1:])
 
41
        elif len(url) == 2:
 
42
            self.directory = url[1]
 
43
        else:
 
44
            self.directory = ""
 
45
 
 
46
        log.Debug("tahoe: %s -> %s:%s" % (url, self.alias, self.directory))
 
47
 
 
48
    def get_remote_path(self, filename=None):
 
49
        if filename == None:
 
50
            if self.directory != "":
 
51
                return "%s:%s" % (self.alias, self.directory)
 
52
            else:
 
53
                return "%s:" % self.alias
 
54
 
 
55
        if self.directory != "":
 
56
            return "%s:%s/%s" % (self.alias, self.directory, filename)
 
57
        else:
 
58
            return "%s:%s" % (self.alias, filename)
 
59
 
 
60
    def run(self, *args):
 
61
        cmd = " ".join(args)
 
62
        log.Debug("tahoe execute: %s" % cmd)
 
63
        (status, output) = getstatusoutput(cmd)
 
64
 
 
65
        if status != 0:
 
66
            raise BackendException("Error running %s" % cmd)
 
67
        else:
 
68
            return output
 
69
 
 
70
    def put(self, source_path, remote_filename=None):
 
71
        self.run("tahoe", "cp", source_path.name, self.get_remote_path(remote_filename))
 
72
 
 
73
    def get(self, remote_filename, local_path):
 
74
        self.run("tahoe", "cp", self.get_remote_path(remote_filename), local_path.name)
 
75
        local_path.setdata()
 
76
 
 
77
    def list(self):
 
78
        log.Debug("tahoe: List")
 
79
        return self.run("tahoe", "ls", self.get_remote_path()).split('\n')
 
80
 
 
81
    def delete(self, filename_list):
 
82
        log.Debug("tahoe: delete(%s)" % filename_list)
 
83
        for filename in filename_list:
 
84
            self.run("tahoe", "rm", self.get_remote_path(filename))
 
85
 
 
86
duplicity.backend.register_backend("tahoe", TAHOEBackend)