From e26f19dacb16f9bcd349da8b7d8ad797f25023e9 Mon Sep 17 00:00:00 2001 From: Jingbei Li Date: Mon, 20 Nov 2017 16:36:44 +0800 Subject: [PATCH 1/3] python 3 compatibility with six --- nutstore_cli/client/path_helper.py | 3 ++- nutstore_cli/client/utils.py | 5 +++-- nutstore_cli/config.py | 2 +- nutstore_cli/execution.py | 7 ++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/nutstore_cli/client/path_helper.py b/nutstore_cli/client/path_helper.py index 0aa2fb4..3348bb2 100644 --- a/nutstore_cli/client/path_helper.py +++ b/nutstore_cli/client/path_helper.py @@ -4,7 +4,8 @@ basename, splitext, ) -from urlparse import urljoin + +from six.moves.urllib.parse import urljoin __all__ = ( 'join', diff --git a/nutstore_cli/client/utils.py b/nutstore_cli/client/utils.py index 58a2c52..1253072 100644 --- a/nutstore_cli/client/utils.py +++ b/nutstore_cli/client/utils.py @@ -3,10 +3,11 @@ import os from nutstore_cli.client.exceptions import FileNotExistException +from six import string_types def get_attr(obj, attr_or_fn): - if isinstance(attr_or_fn, basestring): + if isinstance(attr_or_fn, string_types): return getattr(obj, attr_or_fn) elif callable(attr_or_fn): return attr_or_fn(obj) @@ -22,4 +23,4 @@ def deco(*args, **kwargs): raise FileNotExistException.make_exception(local_path) return func(*args, **kwargs) - return deco \ No newline at end of file + return deco diff --git a/nutstore_cli/config.py b/nutstore_cli/config.py index 1720238..08450d4 100644 --- a/nutstore_cli/config.py +++ b/nutstore_cli/config.py @@ -28,7 +28,7 @@ def load(self, filename): return config debug('Loading config from {}'.format(filename)) with open(filename) as f: - for line in f.xreadlines(): + for line in f.readlines(): m = self.PARSE_RE.search(line) if m and (m.group(1).strip() in CONFIG_KEYS): k = m.group(1).strip() diff --git a/nutstore_cli/execution.py b/nutstore_cli/execution.py index 237f1e9..a7577b5 100644 --- a/nutstore_cli/execution.py +++ b/nutstore_cli/execution.py @@ -1,7 +1,8 @@ # encoding: utf-8 import re from os import path -from itertools import ifilter + +from six.moves import filter import click import tabulate @@ -73,10 +74,10 @@ def visit_ls(self, node, children): LS_LABELS ) grep_keywords = children[2].children[4].children[0].text if children[2].children else None - rows = ifilter(lambda row: bool(row[0]), rows) + rows = filter(lambda row: bool(row[0]), rows) if grep_keywords: echo.debug('Issue a grep "{}"'.format(grep_keywords)) - rows = ifilter(lambda row: re.search(grep_keywords, row[0], flags=re.IGNORECASE), rows) + rows = filter(lambda row: re.search(grep_keywords, row[0], flags=re.IGNORECASE), rows) rows = list(rows) rows.sort(key=lambda row: row[2]) # order by mtime echo.echo(tabulate.tabulate(rows, headers=labels)) From c7c96aa19b37349213a89da4beddf906a6bbfdf0 Mon Sep 17 00:00:00 2001 From: Jingbei Li Date: Thu, 23 Nov 2017 17:20:55 +0800 Subject: [PATCH 2/3] Chinese charactor support --- nutstore_cli/client/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nutstore_cli/client/base.py b/nutstore_cli/client/base.py index 185955a..2ca855a 100644 --- a/nutstore_cli/client/base.py +++ b/nutstore_cli/client/base.py @@ -10,6 +10,7 @@ import easywebdav +from six.moves.urllib.parse import unquote class BaseNutStoreClient(object): """εšζžœδΊ‘""" @@ -49,6 +50,7 @@ def download(self, remote_path, local_path=None): def ls(self): def file_in_dir(filename, directory): + filename=unquote(filename) return (directory in filename) and (filename != directory) real_path = self.np.real From 5fdc81f85a55375bd47589da603e56f91b4d424a Mon Sep 17 00:00:00 2001 From: Jingbei Li Date: Thu, 23 Nov 2017 17:50:55 +0800 Subject: [PATCH 3/3] import Kxrr/easywebdav --- .gitmodules | 3 +++ easywebdav | 1 + nutstore_cli/client/base.py | 2 +- nutstore_cli/client/exceptions.py | 2 +- nutstore_cli/easywebdav/__init__.py | 1 + nutstore_cli/easywebdav/__version__.py | 1 + nutstore_cli/easywebdav/client.py | 1 + 7 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .gitmodules create mode 160000 easywebdav create mode 120000 nutstore_cli/easywebdav/__init__.py create mode 120000 nutstore_cli/easywebdav/__version__.py create mode 120000 nutstore_cli/easywebdav/client.py diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6699246 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "easywebdav"] + path = easywebdav + url = https://github.com/Kxrr/easywebdav diff --git a/easywebdav b/easywebdav new file mode 160000 index 0000000..8beb4b2 --- /dev/null +++ b/easywebdav @@ -0,0 +1 @@ +Subproject commit 8beb4b2b8795ef8ee99115c3318182a4866a834e diff --git a/nutstore_cli/client/base.py b/nutstore_cli/client/base.py index 2ca855a..630316d 100644 --- a/nutstore_cli/client/base.py +++ b/nutstore_cli/client/base.py @@ -8,7 +8,7 @@ from nutstore_cli.client.utils import check_local_path from nutstore_cli.client.path_helper import * -import easywebdav +from nutstore_cli import easywebdav from six.moves.urllib.parse import unquote diff --git a/nutstore_cli/client/exceptions.py b/nutstore_cli/client/exceptions.py index d9bb7a2..ccc19f2 100644 --- a/nutstore_cli/client/exceptions.py +++ b/nutstore_cli/client/exceptions.py @@ -1,5 +1,5 @@ # coding: utf-8 -from easywebdav.client import WebdavException +from nutstore_cli.easywebdav.client import WebdavException class NutStoreClientException(WebdavException): diff --git a/nutstore_cli/easywebdav/__init__.py b/nutstore_cli/easywebdav/__init__.py new file mode 120000 index 0000000..75711b6 --- /dev/null +++ b/nutstore_cli/easywebdav/__init__.py @@ -0,0 +1 @@ +../../easywebdav/easywebdav/__init__.py \ No newline at end of file diff --git a/nutstore_cli/easywebdav/__version__.py b/nutstore_cli/easywebdav/__version__.py new file mode 120000 index 0000000..a815e76 --- /dev/null +++ b/nutstore_cli/easywebdav/__version__.py @@ -0,0 +1 @@ +../../easywebdav/easywebdav/__version__.py \ No newline at end of file diff --git a/nutstore_cli/easywebdav/client.py b/nutstore_cli/easywebdav/client.py new file mode 120000 index 0000000..4c8f382 --- /dev/null +++ b/nutstore_cli/easywebdav/client.py @@ -0,0 +1 @@ +../../easywebdav/easywebdav/client.py \ No newline at end of file