Skip to content
Snippets Groups Projects
Commit 9c8d379b authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[webdav3] Use official implementation

parent 126f2cc3
Branches
Tags
1 merge request!262Python-only pipelines
......@@ -25,36 +25,3 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
Code from the "webdav3" directory was copied from the Github repository
https://github.com/ezhov-evgeny/webdav-client-python-3, but later modified and
repackaged as part of this package.
The authors asked to reproduce the following license text.
COPYRIGHT AND PERMISSION NOTICE
-------------------------------
Copyright (c) 2016, The WDC Project, and many contributors, see the THANKS
file.
All rights reserved.
Permission to use, copy, modify, and distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of a copyright holder shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization of the copyright holder.
This diff is collapsed.
from os.path import exists
from .exceptions import OptionNotValid
from .urn import Urn
class ConnectionSettings:
def is_valid(self):
pass
def valid(self):
try:
self.is_valid()
except OptionNotValid:
return False
else:
return True
class WebDAVSettings(ConnectionSettings):
ns = "webdav:"
prefix = "webdav_"
keys = {
"hostname",
"login",
"password",
"token",
"root",
"cert_path",
"key_path",
"recv_speed",
"send_speed",
"verbose",
}
hostname = None
login = None
password = None
token = None
root = None
cert_path = None
key_path = None
recv_speed = None
send_speed = None
verbose = None
def __init__(self, options):
self.options = dict()
for key in self.keys:
value = options.get(key, "")
self.options[key] = value
self.__dict__[key] = value
self.root = Urn(self.root).quote() if self.root else ""
self.root = self.root.rstrip(Urn.separate)
def is_valid(self):
if not self.hostname:
raise OptionNotValid(
name="hostname", value=self.hostname, ns=self.ns
)
if self.cert_path and not exists(self.cert_path):
raise OptionNotValid(
name="cert_path", value=self.cert_path, ns=self.ns
)
if self.key_path and not exists(self.key_path):
raise OptionNotValid(
name="key_path", value=self.key_path, ns=self.ns
)
if self.key_path and not self.cert_path:
raise OptionNotValid(
name="cert_path", value=self.cert_path, ns=self.ns
)
if self.password and not self.login:
raise OptionNotValid(name="login", value=self.login, ns=self.ns)
if not self.token and not self.login:
raise OptionNotValid(name="login", value=self.login, ns=self.ns)
class ProxySettings(ConnectionSettings):
ns = "proxy:"
prefix = "proxy_"
keys = {"hostname", "login", "password"}
hostname = None
login = None
password = None
def __init__(self, options):
self.options = dict()
for key in self.keys:
value = options.get(key, "")
self.options[key] = value
self.__dict__[key] = value
def is_valid(self):
if self.password and not self.login:
raise OptionNotValid(name="login", value=self.login, ns=self.ns)
if self.login or self.password:
if not self.hostname:
raise OptionNotValid(
name="hostname", value=self.hostname, ns=self.ns
)
class WebDavException(Exception):
pass
class NotValid(WebDavException):
pass
class OptionNotValid(NotValid):
def __init__(self, name, value, ns=""):
self.name = name
self.value = value
self.ns = ns
def __str__(self):
return "Option ({ns}{name}={value}) have invalid name or value".format(
ns=self.ns, name=self.name, value=self.value
)
class CertificateNotValid(NotValid):
pass
class NotFound(WebDavException):
pass
class LocalResourceNotFound(NotFound):
def __init__(self, path):
self.path = path
def __str__(self):
return "Local file: {path} not found".format(path=self.path)
class RemoteResourceNotFound(NotFound):
def __init__(self, path):
self.path = path
def __str__(self):
return "Remote resource: {path} not found".format(path=self.path)
class RemoteParentNotFound(NotFound):
def __init__(self, path):
self.path = path
def __str__(self):
return "Remote parent for: {path} not found".format(path=self.path)
class ResourceTooBig(WebDavException):
def __init__(self, path, size, max_size):
self.path = path
self.size = size
self.max_size = max_size
def __str__(self):
return "Resource {path} is too big, it should be less then {max_size} but actually: {size}".format(
path=self.path, max_size=self.max_size, size=self.size
)
class MethodNotSupported(WebDavException):
def __init__(self, name, server):
self.name = name
self.server = server
def __str__(self):
return "Method {name} not supported for {server}".format(
name=self.name, server=self.server
)
class ConnectionException(WebDavException):
def __init__(self, exception):
self.exception = exception
def __str__(self):
return self.exception.__str__()
class NoConnection(WebDavException):
def __init__(self, hostname):
self.hostname = hostname
def __str__(self):
return "Not connection with {hostname}".format(hostname=self.hostname)
# This exception left only for supporting original library interface.
class NotConnection(WebDavException):
def __init__(self, hostname):
self.hostname = hostname
def __str__(self):
return "No connection with {hostname}".format(hostname=self.hostname)
class ResponseErrorCode(WebDavException):
def __init__(self, url, code, message):
self.url = url
self.code = code
self.message = message
def __str__(self):
return "Request to {url} failed with code {code} and message: {message}".format(
url=self.url, code=self.code, message=self.message
)
class NotEnoughSpace(WebDavException):
def __init__(self):
pass
def __str__(self):
return "Not enough space on the server"
try:
from urllib.parse import quote, unquote, urlsplit
except ImportError:
from urllib import unquote, quote
from urlparse import urlsplit
from re import sub
class Urn(object):
separate = "/"
def __init__(self, path, directory=False):
self._path = quote(path)
expressions = r"/\.+/", "/+"
for expression in expressions:
self._path = sub(expression, Urn.separate, self._path)
if not self._path.startswith(Urn.separate):
self._path = "{begin}{end}".format(
begin=Urn.separate, end=self._path
)
if directory and not self._path.endswith(Urn.separate):
self._path = "{begin}{end}".format(
begin=self._path, end=Urn.separate
)
def __str__(self):
return self.path()
def path(self):
return unquote(self._path)
def quote(self):
return self._path
def filename(self):
path_split = self._path.split(Urn.separate)
name = (
path_split[-2] + Urn.separate
if path_split[-1] == ""
else path_split[-1]
)
return unquote(name)
def parent(self):
path_split = self._path.split(Urn.separate)
nesting_level = self.nesting_level()
parent_path_split = path_split[:nesting_level]
parent = (
self.separate.join(parent_path_split)
if nesting_level != 1
else Urn.separate
)
if not parent.endswith(Urn.separate):
return unquote(parent + Urn.separate)
else:
return unquote(parent)
def nesting_level(self):
return self._path.count(Urn.separate, 0, -1)
def is_dir(self):
return self._path[-1] == Urn.separate
@staticmethod
def normalize_path(path):
result = sub("/{2,}", "/", path)
return (
result
if len(result) < 1 or result[-1] != Urn.separate
else result[:-1]
)
@staticmethod
def compare_path(path_a, href):
unqouted_path = Urn.separate + unquote(urlsplit(href).path)
return Urn.normalize_path(path_a) == Urn.normalize_path(unqouted_path)
......@@ -53,6 +53,7 @@ requirements:
- tabulate
- python-graphviz
- pip
- webdavclient3
test:
requires:
......
......@@ -16,7 +16,6 @@
bob.devtools.mirror
bob.devtools.deploy
bob.devtools.graph
bob.devtools.webdav3.client
Detailed Information
......@@ -41,9 +40,3 @@ Detailed Information
.. automodule:: bob.devtools.deploy
.. automodule:: bob.devtools.graph
WebDAV Python Client
--------------------
.. automodule:: bob.devtools.webdav3.client
......@@ -29,6 +29,7 @@ requires = [
"termcolor",
"psutil",
"pytz",
"webdavclient3",
]
setup(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment