From 3b727b6ee6289068ff97bd7a7ad31e4e763c7cda Mon Sep 17 00:00:00 2001 From: Marcus Rickert Date: Thu, 14 Jan 2016 00:23:24 +0100 Subject: [PATCH 1/4] add parameter auth_mode --- easywebdav/client.py | 12 +++++++++--- etc/gitsynchista_config.txt | 11 +++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 etc/gitsynchista_config.txt diff --git a/easywebdav/client.py b/easywebdav/client.py index 4003198..9562f46 100644 --- a/easywebdav/client.py +++ b/easywebdav/client.py @@ -15,6 +15,9 @@ DOWNLOAD_CHUNK_SIZE_BYTES = 1 * 1024 * 1024 +AUTH_MODE_BASIC = 'basic' +AUTH_MODE_DIGEST = 'digest' + class WebdavException(Exception): pass @@ -73,7 +76,7 @@ def __init__(self, method, path, expected_code, actual_code): class Client(object): def __init__(self, host, port=0, auth=None, username=None, password=None, - protocol='http', verify_ssl=True, path=None, cert=None): + protocol='http', verify_ssl=True, path=None, cert=None, auth_mode=AUTH_MODE_BASIC): if not port: port = 443 if protocol == 'https' else 80 self.baseurl = '{0}://{1}:{2}'.format(protocol, host, port) @@ -90,7 +93,10 @@ def __init__(self, host, port=0, auth=None, username=None, password=None, if auth: self.session.auth = auth elif username and password: - self.session.auth = (username, password) + if auth_mode == AUTH_MODE_DIGEST: + self.session.auth = requests.auth.HTTPDigestAuth(username, password) + else: + self.session.auth = (username, password) def _send(self, method, path, expected_code, **kwargs): url = self._get_url(path) @@ -185,4 +191,4 @@ def ls(self, remote_path='.'): def exists(self, remote_path): response = self._send('HEAD', remote_path, (200, 301, 404)) - return True if response.status_code != 404 else False + return True if response.status_code != 404 else False \ No newline at end of file diff --git a/etc/gitsynchista_config.txt b/etc/gitsynchista_config.txt new file mode 100644 index 0000000..b6575b8 --- /dev/null +++ b/etc/gitsynchista_config.txt @@ -0,0 +1,11 @@ +[webdav] + +epoch_delta = 3600 + +[repository] + +name = easywebdav +local_path = ../easywebdav +remote_path = /easywebdav +auto_scan = 1 +#working_copy_wakeup = True \ No newline at end of file From f90bb6d7361f4e6b80fbd34d77a2c586c965d427 Mon Sep 17 00:00:00 2001 From: Marcus Rickert Date: Thu, 21 Jan 2016 17:20:31 +0100 Subject: [PATCH 2/4] add directory detection --- easywebdav/client.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/easywebdav/client.py b/easywebdav/client.py index 9562f46..edeefc7 100644 --- a/easywebdav/client.py +++ b/easywebdav/client.py @@ -1,3 +1,4 @@ +# coding: utf-8 import requests import platform from numbers import Number @@ -9,15 +10,19 @@ if py_majversion == '2': from httplib import responses as HTTP_CODES from urlparse import urlparse + from urlparse import urlsplit else: from http.client import responses as HTTP_CODES from urllib.parse import urlparse - + from urllib.parse import urlsplit + DOWNLOAD_CHUNK_SIZE_BYTES = 1 * 1024 * 1024 AUTH_MODE_BASIC = 'basic' AUTH_MODE_DIGEST = 'digest' +CONTENT_TYPE_DIRECTORY = 'httpd/unix-directory' + class WebdavException(Exception): pass @@ -29,7 +34,7 @@ def codestr(code): return HTTP_CODES.get(code, 'UNKNOWN') -File = namedtuple('File', ['name', 'size', 'mtime', 'ctime', 'contenttype']) +File = namedtuple('File', ['name', 'size', 'mtime', 'ctime', 'contenttype','contentlength', 'is_dir']) def prop(elem, name, default=None): @@ -38,12 +43,29 @@ def prop(elem, name, default=None): def elem2file(elem): + + href = prop(elem, 'href') + url_parts = urlsplit(href) + path = url_parts.path + + # remove trailing slashes + if path[-1] == '/': + path = path[0:len(path)-1] + + content_type = prop(elem, 'getcontenttype', '') + content_length = prop(elem, 'getcontentlength') + + # Try to detect directories... + is_dir = (content_type == CONTENT_TYPE_DIRECTORY) or content_length == None + return File( - prop(elem, 'href'), + path, int(prop(elem, 'getcontentlength', 0)), prop(elem, 'getlastmodified', ''), prop(elem, 'creationdate', ''), - prop(elem, 'getcontenttype', ''), + content_type, + int(content_length) if content_length != None else None, + is_dir ) @@ -82,6 +104,7 @@ def __init__(self, host, port=0, auth=None, username=None, password=None, self.baseurl = '{0}://{1}:{2}'.format(protocol, host, port) if path: self.baseurl = '{0}/{1}'.format(self.baseurl, path) + self.cwd = '/' self.session = requests.session() self.session.verify = verify_ssl @@ -191,4 +214,5 @@ def ls(self, remote_path='.'): def exists(self, remote_path): response = self._send('HEAD', remote_path, (200, 301, 404)) - return True if response.status_code != 404 else False \ No newline at end of file + return True if response.status_code != 404 else False + \ No newline at end of file From bb0d89012e33d2e7abefc00d102ff86809ed4513 Mon Sep 17 00:00:00 2001 From: Marcus Rickert Date: Fri, 12 Feb 2016 14:04:45 +0100 Subject: [PATCH 3/4] delete directory to allow for feature branch --- etc/gitsynchista_config.txt | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 etc/gitsynchista_config.txt diff --git a/etc/gitsynchista_config.txt b/etc/gitsynchista_config.txt deleted file mode 100644 index b6575b8..0000000 --- a/etc/gitsynchista_config.txt +++ /dev/null @@ -1,11 +0,0 @@ -[webdav] - -epoch_delta = 3600 - -[repository] - -name = easywebdav -local_path = ../easywebdav -remote_path = /easywebdav -auto_scan = 1 -#working_copy_wakeup = True \ No newline at end of file From 29e6a9d3b600c0b0e1c1f06f4189d05ba2edcf65 Mon Sep 17 00:00:00 2001 From: Marcus Rickert Date: Sun, 28 Feb 2016 08:59:31 +0100 Subject: [PATCH 4/4] Upgrade to Python 3.x --- easywebdav/client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/easywebdav/client.py b/easywebdav/client.py index edeefc7..0e82a2e 100644 --- a/easywebdav/client.py +++ b/easywebdav/client.py @@ -4,6 +4,7 @@ from numbers import Number import xml.etree.cElementTree as xml from collections import namedtuple +from six import string_types py_majversion, py_minversion, py_revversion = platform.python_version_tuple() @@ -179,7 +180,7 @@ def delete(self, path): self._send('DELETE', path, 204) def upload(self, local_path_or_fileobj, remote_path): - if isinstance(local_path_or_fileobj, basestring): + if isinstance(local_path_or_fileobj, string_types): with open(local_path_or_fileobj, 'rb') as f: self._upload(f, remote_path) else: @@ -190,7 +191,7 @@ def _upload(self, fileobj, remote_path): def download(self, remote_path, local_path_or_fileobj): response = self._send('GET', remote_path, 200, stream=True) - if isinstance(local_path_or_fileobj, basestring): + if isinstance(local_path_or_fileobj, string_types): with open(local_path_or_fileobj, 'wb') as f: self._download(f, response) else: @@ -215,4 +216,4 @@ def ls(self, remote_path='.'): def exists(self, remote_path): response = self._send('HEAD', remote_path, (200, 301, 404)) return True if response.status_code != 404 else False - \ No newline at end of file +