1# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4; encoding:utf8 -*- 2# 3# Copyright 2014 Andrea Grandi <a.grandi@gmail.com> 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 2 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 21import os.path 22import duplicity.backend 23import duplicity.util 24 25 26class SXBackend(duplicity.backend.Backend): 27 u"""Connect to remote store using Skylable Protocol""" 28 def __init__(self, parsed_url): 29 duplicity.backend.Backend.__init__(self, parsed_url) 30 self.url_string = parsed_url.url_string 31 32 def _put(self, source_path, remote_filename): 33 remote_filename = util.fsdecode(remote_filename) 34 remote_path = os.path.join(self.url_string, remote_filename) 35 commandline = u"sxcp {0} {1}".format(source_path.uc_name, remote_path) 36 self.subprocess_popen(commandline) 37 38 def _get(self, remote_filename, local_path): 39 remote_filename = util.fsdecode(remote_filename) 40 remote_path = os.path.join(self.url_string, remote_filename) 41 commandline = u"sxcp {0} {1}".format(remote_path, local_path.uc_name) 42 self.subprocess_popen(commandline) 43 44 def _list(self): 45 # Do a long listing to avoid connection reset 46 commandline = u"sxls {0}/".format(self.url_string) 47 _, l, _ = self.subprocess_popen(commandline) 48 # Look for our files as the last element of a long list line 49 return [util.fsencode(x[x.rindex(u'/') + 1:].split()[-1]) for x in l.split(u'\n') 50 if x and not x.startswith(u"total ")] 51 52 def _delete(self, filename): 53 commandline = u"sxrm {0}/{1}".format(self.url_string, filename) 54 self.subprocess_popen(commandline) 55 56 57duplicity.backend.register_backend(u"sx", SXBackend) 58