From 277666891316d6f81abdb41473b202e8df310e84 Mon Sep 17 00:00:00 2001 From: gryf Date: Sun, 26 Apr 2020 09:32:17 +0200 Subject: [PATCH] Fix for removing files with space/parentheses. Also, some further py2 cleanup. --- Makefile | 15 +-------------- README.rst | 12 +++--------- adbfs | 6 +++--- test_adbfs.py | 31 ++++++++----------------------- 4 files changed, 15 insertions(+), 49 deletions(-) diff --git a/Makefile b/Makefile index ba6fac2..c925353 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,17 @@ # simple makefile for running tests for the adbfs plugin -all: test_dir py2 py3 flake8 +all: test_dir py3 flake8 TEST_DIR='.test' -PY2_VENV=$(TEST_DIR)/py2 PY3_VENV=$(TEST_DIR)/py3 FL8_VENV=$(TEST_DIR)/flake8 TST_EXISTS=$(shell [ -e $(TEST_DIR) ] && echo 1 || echo 0) -PY2_EXISTS=$(shell [ -e $(PY2_VENV) ] && echo 1 || echo 0) PY3_EXISTS=$(shell [ -e $(PY3_VENV) ] && echo 1 || echo 0) FL8_EXISTS=$(shell [ -e $(FL8_VENV) ] && echo 1 || echo 0) py3: test_dir virtualenv3 .test/py3/bin/python test_adbfs.py -py2: test_dir virtualenv2 - .test/py2/bin/python test_adbfs.py - flake8: test_dir virtualenv_flake8 .test/flake8/bin/flake8 adbfs test_adbfs.py @@ -35,14 +30,6 @@ else virtualenv3: endif -ifeq ($(PY2_EXISTS), 0) -virtualenv2: - virtualenv -p python2 $(PY2_VENV) - $(PY2_VENV)/bin/pip install mock -else -virtualenv2: -endif - ifeq ($(FL8_EXISTS), 0) virtualenv_flake8: virtualenv -p python2 $(FL8_VENV) diff --git a/README.rst b/README.rst index 5a4c766..b6c81c2 100644 --- a/README.rst +++ b/README.rst @@ -109,26 +109,20 @@ The reason why `tox`_ wasn't used is, that there is no ``setup.py`` file, and it's difficult to install simple script, which isn't a python module (python interpreter will refuse to import module without ``.py`` extension). -It requires GNU ``make`` program, and also ``virtualenv`` besides Python in -version 2 and 3. Using it is simple as running following command: +It requires GNU ``make`` program, and also ``virtualenv``. Using it is simple +as running following command: .. code:: shell-session $ make -it will run `py2`, `py3` and `flake8` jobs to check it against the code. For +it will run `py3` and `flake8` jobs to check it against the code. For running tests against Python 3: .. code:: shell-session $ make py3 -or Python 2: - -.. code:: shell-session - - $ make py2 - or flake 8: .. code:: shell-session diff --git a/adbfs b/adbfs index 4f2dec2..09c780d 100755 --- a/adbfs +++ b/adbfs @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """ adbfs Virtual filesystem for Midnight Commander @@ -15,7 +15,7 @@ import subprocess import sys import shlex -__version__ = 0.13 +__version__ = 0.14 XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.expanduser('~/.config')) @@ -572,7 +572,7 @@ class Adb(object): sys.stderr.write(self.error) return 10 - cmd = self._shell_cmd(False, 'rm', dst) + cmd = self._shell_cmd(False, 'rm %s' % shlex.quote(dst)) try: err = check_output(cmd).strip() except subprocess.CalledProcessError: diff --git a/test_adbfs.py b/test_adbfs.py index a105ce9..0b9f1d3 100644 --- a/test_adbfs.py +++ b/test_adbfs.py @@ -1,24 +1,15 @@ # -*- coding: utf-8 -*- import os -import six +from importlib.util import spec_from_loader, module_from_spec +from importlib.machinery import SourceFileLoader import unittest -try: - from unittest import mock -except ImportError: - import mock +from unittest import mock -FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'adbfs') -try: - from importlib.util import spec_from_loader, module_from_spec - from importlib.machinery import SourceFileLoader - spec = spec_from_loader("adbfs", SourceFileLoader("adbfs", FILE)) - adbfs = module_from_spec(spec) - spec.loader.exec_module(adbfs) -except ImportError: - # py27 - import imp - adbfs = imp.load_source('adbfs', FILE) +module_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'adbfs') +spec = spec_from_loader("adbfs", SourceFileLoader("adbfs", module_path)) +adbfs = module_from_spec(spec) +spec.loader.exec_module(adbfs) LISTING = '''\ -rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 /storage/emulated/0/Grüß Gott @@ -44,10 +35,7 @@ class TestCheckOutput(unittest.TestCase): Python3 treats string as unicode objects, but subprocess.check_output returns bytes object, which is equvalend for py2 string… annoying. """ - if six.PY3: - out.return_value = bytes(LISTING, 'utf-8') - else: - out.return_value = LISTING + out.return_value = bytes(LISTING, 'utf-8') result = adbfs.check_output(None) self.assertEqual(result, LISTING) @@ -57,9 +45,6 @@ class TestCheckOutput(unittest.TestCase): Special case for py3. We have bytes with some weird character - like some system write something with codepage, instead of utf8. """ - if six.PY2: - # doesn't affect Python 2 - return line = (b'-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 ' b'/storage/emulated/0/\xe2\n') # Latin 1 char â out.return_value = bytes(line)