1
0
mirror of https://github.com/gryf/mc_adbfs.git synced 2026-03-26 21:43:30 +01:00

9 Commits

Author SHA1 Message Date
b1a6219d21 Removed deprecated encoding argument from json.loads. 2020-12-07 19:08:29 +01:00
d16f0f06b8 Merge branch 'thp-various-fixes' 2020-06-09 19:55:21 +02:00
c2f07f5516 Merge branch 'various-fixes' of https://github.com/thp/mc_adbfs into thp-various-fixes 2020-06-09 19:55:06 +02:00
e9b196eaf8 Change SafeConfigParser to ConfigParser 2020-05-21 10:10:43 +02:00
039c078a35 Fix missing attribute on conf object 2020-04-26 13:48:21 +02:00
2776668913 Fix for removing files with space/parentheses.
Also, some further py2 cleanup.
2020-04-26 09:32:59 +02:00
Thomas Perl
b088c45d3f Fix quoting for 'adb shell' 2019-05-09 11:58:29 +02:00
Thomas Perl
c5559f7d41 Python 3's ConfigParser is already the safe one 2019-05-09 11:38:21 +02:00
Thomas Perl
9ffa1a13af Default to Python 3 2019-05-09 11:38:00 +02:00
4 changed files with 19 additions and 51 deletions

View File

@@ -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)

View File

@@ -76,6 +76,7 @@ You can configure behaviour of this plugin using ``.ini`` file located under
root =
adb_command = adb
adb_connect =
try_su = false
where:
@@ -109,26 +110,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

11
adbfs
View File

@@ -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'))
@@ -80,6 +80,7 @@ class Conf(object):
self.suppress_colors = False
self.adb_command = 'adb'
self.adb_connect = ''
self.try_su = False
self.read()
self.connect()
@@ -187,7 +188,7 @@ class Conf(object):
if not os.path.exists(conf_fname):
return
cfg = configparser.SafeConfigParser()
cfg = configparser.ConfigParser()
cfg_map = {'debug': (cfg.getboolean, 'debug'),
'dirs_to_skip': (cfg.get, 'dirs_to_skip'),
'suppress_colors': (cfg.get, 'suppress_colors'),
@@ -204,7 +205,7 @@ class Conf(object):
pass
if self.dirs_to_skip and isinstance(self.dirs_to_skip, str):
self.dirs_to_skip = json.loads(self.dirs_to_skip, encoding='ascii')
self.dirs_to_skip = json.loads(self.dirs_to_skip)
self.dirs_to_skip = [x.encode('utf-8') for x in self.dirs_to_skip]
else:
self.dirs_to_skip = []
@@ -572,7 +573,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:

View File

@@ -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)