1
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
3
# Copyright 2008 Francois Deppierraz
5
# This file is part of duplicity.
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.
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.
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
21
import duplicity.backend
22
from duplicity import log
23
from duplicity.errors import * #@UnusedWildImport
25
from commands import getstatusoutput
27
class TAHOEBackend(duplicity.backend.Backend):
29
Backend for the Tahoe file system
32
def __init__(self, parsed_url):
33
duplicity.backend.Backend.__init__(self, parsed_url)
35
url = parsed_url.path.strip('/').split('/')
40
self.directory = "/".join(url[1:])
42
self.directory = url[1]
46
log.Debug("tahoe: %s -> %s:%s" % (url, self.alias, self.directory))
48
def get_remote_path(self, filename=None):
50
if self.directory != "":
51
return "%s:%s" % (self.alias, self.directory)
53
return "%s:" % self.alias
55
if self.directory != "":
56
return "%s:%s/%s" % (self.alias, self.directory, filename)
58
return "%s:%s" % (self.alias, filename)
62
log.Debug("tahoe execute: %s" % cmd)
63
(status, output) = getstatusoutput(cmd)
66
raise BackendException("Error running %s" % cmd)
70
def put(self, source_path, remote_filename=None):
71
self.run("tahoe", "cp", source_path.name, self.get_remote_path(remote_filename))
73
def get(self, remote_filename, local_path):
74
self.run("tahoe", "cp", self.get_remote_path(remote_filename), local_path.name)
78
log.Debug("tahoe: List")
79
return self.run("tahoe", "ls", self.get_remote_path()).split('\n')
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))
86
duplicity.backend.register_backend("tahoe", TAHOEBackend)