mirror of
https://github.com/gryf/mc_adbfs.git
synced 2026-03-27 05:43:33 +01:00
Compare commits
28 Commits
0.8
...
cbef13ccea
| Author | SHA1 | Date | |
|---|---|---|---|
| cbef13ccea | |||
|
|
9cfa834604 | ||
| b1a6219d21 | |||
| d16f0f06b8 | |||
| c2f07f5516 | |||
| e9b196eaf8 | |||
| 039c078a35 | |||
| 2776668913 | |||
| 390f1b1112 | |||
| f7a6b145fd | |||
| 9f1a51fdbf | |||
| 5ece2d579c | |||
| 63fdc2c605 | |||
|
|
b088c45d3f | ||
|
|
c5559f7d41 | ||
|
|
9ffa1a13af | ||
| e4a4aa8974 | |||
| 755ce62321 | |||
| d44050118c | |||
| a216b31ef1 | |||
| 1c6a6cfdf8 | |||
| 7ce2dd2568 | |||
| 11f980beb1 | |||
| bc742ccdf6 | |||
| 7a6a8a499b | |||
| b2163e0fba | |||
| 57509eaac0 | |||
| 210d7f2962 |
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.test
|
||||||
|
__pycache__
|
||||||
|
adbfsc
|
||||||
42
Makefile
Normal file
42
Makefile
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# simple makefile for running tests for the adbfs plugin
|
||||||
|
|
||||||
|
all: test_dir py3 flake8
|
||||||
|
|
||||||
|
TEST_DIR='.test'
|
||||||
|
PY3_VENV=$(TEST_DIR)/py3
|
||||||
|
FL8_VENV=$(TEST_DIR)/flake8
|
||||||
|
TST_EXISTS=$(shell [ -e $(TEST_DIR) ] && 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
|
||||||
|
|
||||||
|
flake8: test_dir virtualenv_flake8
|
||||||
|
.test/flake8/bin/flake8 adbfs test_adbfs.py
|
||||||
|
|
||||||
|
ifeq ($(TST_EXISTS), 0)
|
||||||
|
test_dir:
|
||||||
|
mkdir -p .test
|
||||||
|
else
|
||||||
|
test_dir:
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PY3_EXISTS), 0)
|
||||||
|
virtualenv3:
|
||||||
|
virtualenv -p python3 $(PY3_VENV)
|
||||||
|
$(PY3_VENV)/bin/pip install six
|
||||||
|
else
|
||||||
|
virtualenv3:
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(FL8_EXISTS), 0)
|
||||||
|
virtualenv_flake8:
|
||||||
|
virtualenv -p python2 $(FL8_VENV)
|
||||||
|
$(FL8_VENV)/bin/pip install flake8
|
||||||
|
else
|
||||||
|
virtualenv_flake8:
|
||||||
|
endif
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -fr $(TEST_DIR) __pycache__ adbfsc
|
||||||
103
README.rst
103
README.rst
@@ -5,20 +5,27 @@ Midnight Commander adbfs external fs plugin
|
|||||||
This is Midnight Commander extfs plugin for browsing Android device through
|
This is Midnight Commander extfs plugin for browsing Android device through
|
||||||
``adb`` interface written in Python.
|
``adb`` interface written in Python.
|
||||||
|
|
||||||
|
|
||||||
Rquirements
|
Rquirements
|
||||||
===========
|
===========
|
||||||
|
|
||||||
* Python 2.7
|
* Python 3.x (tested on 3.5.4, 3.6 and 3.7)
|
||||||
* ``adb`` installed and in ``$PATH``
|
* ``adb`` installed and in ``$PATH`` or provided via the config file
|
||||||
* An Android device or emulator preferably rooted
|
* An Android device or emulator preferably rooted
|
||||||
* Busybox installed and available in the path on the device
|
* ``busybox`` (``toolbox``, ``toybox``) installed and available in the path on
|
||||||
|
the device
|
||||||
|
|
||||||
Make sure, that issuing from command line::
|
Make sure, that issuing from command line:
|
||||||
|
|
||||||
|
.. code:: shell-session
|
||||||
|
|
||||||
$ adb shell busybox ls
|
$ adb shell busybox ls
|
||||||
|
$ # or in case of no PATH adb placement
|
||||||
|
$ /path/to/adb shell busybox ls
|
||||||
|
|
||||||
it should display files from root directory on the device.
|
it should display files from root directory on the device.
|
||||||
|
|
||||||
|
|
||||||
Features
|
Features
|
||||||
========
|
========
|
||||||
|
|
||||||
@@ -30,24 +37,103 @@ Features
|
|||||||
* Symbolic links in lists are corrected to be relative to the file system
|
* Symbolic links in lists are corrected to be relative to the file system
|
||||||
* Symbolic links also point to the right target, skipping intermediate links
|
* Symbolic links also point to the right target, skipping intermediate links
|
||||||
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
============
|
============
|
||||||
|
|
||||||
Copy adbfs into ``~/.local/share/mc/extfs.d/`` directory and make it executable
|
Copy adbfs into ``~/.local/share/mc/extfs.d/`` directory and make it executable
|
||||||
if needed.
|
if needed.
|
||||||
|
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
To use it, just issue::
|
To use it, just issue:
|
||||||
|
|
||||||
cd adbfs://
|
.. code:: shell-session
|
||||||
|
|
||||||
|
$ cd adbfs://
|
||||||
|
|
||||||
under MC - after some time you should see the files and directories on your
|
under MC - after some time you should see the files and directories on your
|
||||||
device. For convenience you can add a bookmark (accessible under CTRL+\) for
|
device. For convenience you can add a bookmark (accessible under CTRL+\\) for
|
||||||
fast access. The time is depended on how many files and directories you have on
|
fast access. The time is depended on how many files and directories you have on
|
||||||
your device and how fast it is :)
|
your device and how fast it is :)
|
||||||
|
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
You can configure behaviour of this plugin using ``.ini`` file located under
|
||||||
|
``$XDG_CONFIG_HOME/mc/adbfs.ini`` (which usually is located under
|
||||||
|
``~/.config/mc/adbfs.ini``), and have default values, like:
|
||||||
|
|
||||||
|
.. code:: ini
|
||||||
|
|
||||||
|
[adbfs]
|
||||||
|
debug = false
|
||||||
|
dirs_to_skip = ["acct", "charger", "d", "dev", "proc", "sys"]
|
||||||
|
suppress_colors = false
|
||||||
|
root =
|
||||||
|
adb_command = adb
|
||||||
|
adb_connect =
|
||||||
|
try_su = false
|
||||||
|
|
||||||
|
where:
|
||||||
|
|
||||||
|
* ``debug`` will provide a little bit more verbose information, useful for
|
||||||
|
debugging
|
||||||
|
* ``dirs_to_skip`` list of paths to directories which will be skipped during
|
||||||
|
reading. If leaved empty, or setted to empty list (``[]``) will read
|
||||||
|
everything (slow!)
|
||||||
|
* ``suppress_colors`` this option will make ``busybox`` not to display colors,
|
||||||
|
helpful, if ``busybox ls`` is configured to display colors by default. Does
|
||||||
|
not affect ``toolbox`` or ``toybox``.
|
||||||
|
* ``root`` root directory to read. Everything outside of that directory will be
|
||||||
|
omitted. That would be the fastest way to access certain location on the
|
||||||
|
device. Note, that ``dirs_to_skip`` still apply inside this directory.
|
||||||
|
* ``adb_command`` absolute or relative path to ``adb`` command. ``~/`` or
|
||||||
|
environment variables are allowed.
|
||||||
|
* ``adb_connect`` specifies if connection to specific device needs to be
|
||||||
|
performed before accessing shell. It is useful for *adb over network*
|
||||||
|
feature. Typical value here is a device IP address with optional port, which
|
||||||
|
defaults to 5555.
|
||||||
|
* ``try_su`` specifies whether or not to try to detect if ``su`` command is
|
||||||
|
available and usable.
|
||||||
|
|
||||||
|
|
||||||
|
Contribution
|
||||||
|
============
|
||||||
|
|
||||||
|
There is a ``Makefile`` in the top directory, which is basic helper for running
|
||||||
|
the tests. Please use it, and adapt/add tests for provided fixes/functionality.
|
||||||
|
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``. Using it is simple
|
||||||
|
as running following command:
|
||||||
|
|
||||||
|
.. code:: shell-session
|
||||||
|
|
||||||
|
$ make
|
||||||
|
|
||||||
|
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 flake 8:
|
||||||
|
|
||||||
|
.. code:: shell-session
|
||||||
|
|
||||||
|
$ make flake8
|
||||||
|
|
||||||
|
Exit status on any of those means that test fail. Appropriate message/traceback
|
||||||
|
will also be visible.
|
||||||
|
|
||||||
|
|
||||||
Limitations
|
Limitations
|
||||||
===========
|
===========
|
||||||
|
|
||||||
@@ -58,8 +144,11 @@ Limitations
|
|||||||
* The implementation is experimental and it's by now working with mine device;
|
* The implementation is experimental and it's by now working with mine device;
|
||||||
while it might not work with yours
|
while it might not work with yours
|
||||||
|
|
||||||
|
|
||||||
License
|
License
|
||||||
=======
|
=======
|
||||||
|
|
||||||
This software is licensed under 3-clause BSD license. See LICENSE file for
|
This software is licensed under 3-clause BSD license. See LICENSE file for
|
||||||
details.
|
details.
|
||||||
|
|
||||||
|
.. _tox: https://tox.readthedocs.io
|
||||||
|
|||||||
430
adbfs
430
adbfs
@@ -1,32 +1,44 @@
|
|||||||
#! /usr/bin/env python
|
#! /usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
adbfs Virtual filesystem for Midnight Commander
|
adbfs Virtual filesystem for Midnight Commander
|
||||||
|
|
||||||
* Copyright (c) 2016, Roman Dobosz,
|
* Copyright (c) 2016, Roman Dobosz,
|
||||||
* Published under 3-clause BSD-style license (see LICENSE file)
|
* Published under 3-clause BSD-style license (see LICENSE file)
|
||||||
"""
|
"""
|
||||||
|
import configparser
|
||||||
import ConfigParser
|
|
||||||
import argparse
|
import argparse
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import errno
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import shlex
|
||||||
|
|
||||||
__version__ = 0.8
|
__version__ = 0.14
|
||||||
|
|
||||||
XDG_CONFIG_HOME = os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config"))
|
XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
|
||||||
|
|
||||||
|
|
||||||
class NoBoxFoundException(OSError):
|
def check_output(command_list, stderr=None):
|
||||||
"""
|
"""
|
||||||
Exception raised in case of not found either toolbox or busybox on remote
|
For some reason, in py3 it was decided that command output should be bytes
|
||||||
filesystem accessed via adb
|
instead of string. This little function will check if we have string or
|
||||||
|
bytes and in case of bytes it will convert it to string.
|
||||||
"""
|
"""
|
||||||
pass
|
result = subprocess.check_output(command_list, stderr=stderr)
|
||||||
|
if not isinstance(result, str):
|
||||||
|
_result = []
|
||||||
|
for t in result.split(b'\n'):
|
||||||
|
if not t:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
_result.append(t.decode('utf-8'))
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
_result.append(t.decode('iso-8859-1'))
|
||||||
|
result = '\n'.join(_result) + '\n'
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class Conf(object):
|
class Conf(object):
|
||||||
"""Simple config parser"""
|
"""Simple config parser"""
|
||||||
@@ -48,38 +60,63 @@ class Conf(object):
|
|||||||
r'(?P<size>\d+)?\s'
|
r'(?P<size>\d+)?\s'
|
||||||
r'(?P<date>\d{4}-\d{2}-\d{2}\s'
|
r'(?P<date>\d{4}-\d{2}-\d{2}\s'
|
||||||
r'\d{2}:\d{2})\s'
|
r'\d{2}:\d{2})\s'
|
||||||
r'(?P<name>.*)'}
|
r'(?P<name>.*)'},
|
||||||
}
|
'toybox': {'ls': 'toybox ls -anl',
|
||||||
|
'rls': 'toybox ls -Ranl {}',
|
||||||
|
'file_re': r'^(?P<perms>[-bcdlps][-rwxsStT]{9})\s+'
|
||||||
|
r'(?P<links>\d+)\s+'
|
||||||
|
r'(?P<uid>\d+)\s+'
|
||||||
|
r'(?P<gid>\d+)\s+'
|
||||||
|
r'(?P<size>\d+)?\s'
|
||||||
|
r'(?P<date>\d{4}-\d{2}-\d{2}\s'
|
||||||
|
r'\d{2}:\d{2})\s'
|
||||||
|
r'(?P<name>.*)'}}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.box = None
|
self.box = None
|
||||||
self.debug = False
|
self.debug = False
|
||||||
self.skip_dirs = True
|
self.dirs_to_skip = ['acct', 'charger', 'd', 'dev', 'proc', 'sys']
|
||||||
self.dirs_to_skip = ["acct", "charger", "d", "dev", "proc", "sys"]
|
self.root = None
|
||||||
|
self.suppress_colors = False
|
||||||
|
self.adb_command = 'adb'
|
||||||
|
self.adb_connect = ''
|
||||||
|
self.try_su = False
|
||||||
|
|
||||||
self.get_the_box()
|
|
||||||
self.read()
|
self.read()
|
||||||
|
self.connect()
|
||||||
|
self.get_the_box()
|
||||||
|
|
||||||
def get_the_box(self):
|
def get_the_box(self):
|
||||||
"""Detect if we dealing with busybox or toolbox"""
|
"""Detect if we dealing with busybox or toolbox"""
|
||||||
|
cmd = [self.adb_command] + 'shell which'.split()
|
||||||
try:
|
try:
|
||||||
with open(os.devnull, "w") as fnull:
|
with open(os.devnull, 'w') as fnull:
|
||||||
result = subprocess.check_output('adb shell which '
|
result = check_output(cmd + ['busybox'], stderr=fnull)
|
||||||
'busybox'.split(),
|
|
||||||
stderr=fnull)
|
|
||||||
|
|
||||||
if 'busybox' in result:
|
if 'busybox' in result:
|
||||||
self.box = Conf.boxes['busybox']
|
self.box = Conf.boxes['busybox']
|
||||||
|
if self.suppress_colors:
|
||||||
|
self.box.update({'ls': 'busybox ls --color=none -anel',
|
||||||
|
'rls': 'busybox ls --color=none '
|
||||||
|
'-Ranel {}'})
|
||||||
Adb.file_re = re.compile(self.box['file_re'])
|
Adb.file_re = re.compile(self.box['file_re'])
|
||||||
return
|
return
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(os.devnull, "w") as fnull:
|
with open(os.devnull, 'w') as fnull:
|
||||||
result = subprocess.check_output('adb shell which '
|
result = check_output(cmd + ['toybox'], stderr=fnull)
|
||||||
'toolbox'.split(),
|
|
||||||
stderr=fnull)
|
if 'toybox' in result:
|
||||||
|
self.box = Conf.boxes['toybox']
|
||||||
|
Adb.file_re = re.compile(self.box['file_re'])
|
||||||
|
return
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(os.devnull, 'w') as fnull:
|
||||||
|
result = check_output(cmd + ['toolbox'], stderr=fnull)
|
||||||
|
|
||||||
if 'toolbox' in result:
|
if 'toolbox' in result:
|
||||||
self.box = Conf.boxes['toolbox']
|
self.box = Conf.boxes['toolbox']
|
||||||
@@ -88,8 +125,56 @@ class Conf(object):
|
|||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
raise NoBoxFoundException(errno.ENOENT,
|
sys.stderr.write('There is no toolbox or busybox available.\n')
|
||||||
"There is no toolbox or busybox available")
|
sys.exit(1)
|
||||||
|
|
||||||
|
def get_attached_devices(self):
|
||||||
|
"""Return a list of attached devices"""
|
||||||
|
cmd = [self.adb_command, 'devices']
|
||||||
|
devices = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(os.devnull, 'w') as fnull:
|
||||||
|
result = check_output(cmd, stderr=fnull)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
result = ''
|
||||||
|
|
||||||
|
for line in result.split('\n'):
|
||||||
|
if line.startswith('*'):
|
||||||
|
continue
|
||||||
|
if line.strip() == 'List of devices attached':
|
||||||
|
continue
|
||||||
|
if line.strip() == '':
|
||||||
|
continue
|
||||||
|
identifier, _ = line.split()
|
||||||
|
devices.append(identifier)
|
||||||
|
|
||||||
|
return devices
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
"""
|
||||||
|
If adb_connect is non empty string, perform connecting to specified
|
||||||
|
device over network using an address (or hostname).
|
||||||
|
"""
|
||||||
|
if not self.adb_connect:
|
||||||
|
return
|
||||||
|
|
||||||
|
devices = self.get_attached_devices()
|
||||||
|
|
||||||
|
for device in devices:
|
||||||
|
if self.adb_connect in device:
|
||||||
|
return # already connected, no need to reconnect
|
||||||
|
|
||||||
|
cmd = [self.adb_command, 'connect', self.adb_connect]
|
||||||
|
with open(os.devnull, 'w') as fnull:
|
||||||
|
result = check_output(cmd, stderr=fnull)
|
||||||
|
if result.split()[0] == 'connected':
|
||||||
|
subprocess.call([self.adb_command, 'wait-for-device'])
|
||||||
|
return
|
||||||
|
|
||||||
|
sys.stderr.write('Unable to connect to `%s\'. Is adb over network '
|
||||||
|
'enabled on device?\n' % self.adb_connect)
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
"""
|
"""
|
||||||
@@ -103,20 +188,31 @@ class Conf(object):
|
|||||||
if not os.path.exists(conf_fname):
|
if not os.path.exists(conf_fname):
|
||||||
return
|
return
|
||||||
|
|
||||||
cfg = ConfigParser.SafeConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
cfg_map = {'debug': (cfg.getboolean, 'debug'),
|
cfg_map = {'debug': (cfg.getboolean, 'debug'),
|
||||||
'skip_dirs': (cfg.getboolean, 'skip_dirs'),
|
'dirs_to_skip': (cfg.get, 'dirs_to_skip'),
|
||||||
'dirs_to_skip': (cfg.get, 'dirs_to_skip')}
|
'suppress_colors': (cfg.get, 'suppress_colors'),
|
||||||
|
'root': (cfg.get, 'root'),
|
||||||
|
'adb_command': (cfg.get, 'adb_command'),
|
||||||
|
'adb_connect': (cfg.get, 'adb_connect'),
|
||||||
|
'try_su': (cfg.getboolean, 'try_su')}
|
||||||
cfg.read(conf_fname)
|
cfg.read(conf_fname)
|
||||||
|
|
||||||
for key, (function, attr) in cfg_map.items():
|
for key, (function, attr) in cfg_map.items():
|
||||||
try:
|
try:
|
||||||
setattr(self, attr, function('adbfs', key))
|
setattr(self, attr, function('adbfs', key))
|
||||||
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
|
except (configparser.NoSectionError, configparser.NoOptionError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if isinstance(self.dirs_to_skip, str):
|
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 = []
|
||||||
|
|
||||||
|
if self.adb_command:
|
||||||
|
self.adb_command = os.path.expandvars(self.adb_command)
|
||||||
|
self.adb_command = os.path.expanduser(self.adb_command)
|
||||||
|
|
||||||
|
|
||||||
class File(object):
|
class File(object):
|
||||||
@@ -133,7 +229,7 @@ class File(object):
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.date = date # as string
|
self.date = date # as string
|
||||||
|
|
||||||
self.dirname = ""
|
self.dirname = ''
|
||||||
self.type = None
|
self.type = None
|
||||||
self.string = None
|
self.string = None
|
||||||
self.link_target = None
|
self.link_target = None
|
||||||
@@ -142,7 +238,7 @@ class File(object):
|
|||||||
def _correct_link(self):
|
def _correct_link(self):
|
||||||
"""Canonize filename and fill the link attr"""
|
"""Canonize filename and fill the link attr"""
|
||||||
try:
|
try:
|
||||||
name, target = self.name.split(" -> ")
|
name, target = self.name.split(' -> ')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -151,7 +247,7 @@ class File(object):
|
|||||||
if not self.size:
|
if not self.size:
|
||||||
self.size = 0
|
self.size = 0
|
||||||
|
|
||||||
if target.startswith("/"):
|
if target.startswith('/'):
|
||||||
self.link_target = target
|
self.link_target = target
|
||||||
else:
|
else:
|
||||||
self.link_target = os.path.abspath(os.path.join(self.dirname,
|
self.link_target = os.path.abspath(os.path.join(self.dirname,
|
||||||
@@ -159,34 +255,34 @@ class File(object):
|
|||||||
|
|
||||||
def update(self, dirname):
|
def update(self, dirname):
|
||||||
"""update object fields"""
|
"""update object fields"""
|
||||||
month_num = {"Jan": 1,
|
month_num = {'Jan': 1,
|
||||||
"Feb": 2,
|
'Feb': 2,
|
||||||
"Mar": 3,
|
'Mar': 3,
|
||||||
"Apr": 4,
|
'Apr': 4,
|
||||||
"May": 5,
|
'May': 5,
|
||||||
"Jun": 6,
|
'Jun': 6,
|
||||||
"Jul": 7,
|
'Jul': 7,
|
||||||
"Aug": 8,
|
'Aug': 8,
|
||||||
"Sep": 9,
|
'Sep': 9,
|
||||||
"Oct": 10,
|
'Oct': 10,
|
||||||
"Nov": 11,
|
'Nov': 11,
|
||||||
"Dec": 12}
|
'Dec': 12}
|
||||||
self.dirname = dirname
|
self.dirname = dirname
|
||||||
if self.date_time:
|
if self.date_time:
|
||||||
date = self.date_time.split()
|
date = self.date_time.split()
|
||||||
date = "%s-%02d-%s %s" % (date[1],
|
date = '%s-%02d-%s %s' % (date[1],
|
||||||
month_num[date[0]],
|
month_num[date[0]],
|
||||||
date[3],
|
date[3],
|
||||||
date[2])
|
date[2])
|
||||||
date = datetime.strptime(date, "%d-%m-%Y %H:%M:%S")
|
date = datetime.strptime(date, '%d-%m-%Y %H:%M:%S')
|
||||||
elif self.date:
|
elif self.date:
|
||||||
date = datetime.strptime(self.date, "%Y-%m-%d %H:%M")
|
date = datetime.strptime(self.date, '%Y-%m-%d %H:%M')
|
||||||
|
|
||||||
self.date_time = date.strftime("%m/%d/%Y %H:%M:01")
|
self.date_time = date.strftime('%m/%d/%Y %H:%M:01')
|
||||||
|
|
||||||
self.type = self.perms[0] if self.perms else None
|
self.type = self.perms[0] if self.perms else None
|
||||||
|
|
||||||
if self.type == "l" and " -> " in self.name:
|
if self.type == 'l' and ' -> ' in self.name:
|
||||||
self._correct_link()
|
self._correct_link()
|
||||||
|
|
||||||
self.filepath = os.path.join(self.dirname, self.name)
|
self.filepath = os.path.join(self.dirname, self.name)
|
||||||
@@ -199,22 +295,22 @@ class File(object):
|
|||||||
"""represent the file/entire node"""
|
"""represent the file/entire node"""
|
||||||
fullname = os.path.join(self.dirname, self.name)
|
fullname = os.path.join(self.dirname, self.name)
|
||||||
if self.link_target:
|
if self.link_target:
|
||||||
fullname += " -> " + self.link_target
|
fullname += ' -> ' + self.link_target
|
||||||
return "<File {type} {name} {id}>".format(type=self.type,
|
return '<File {type} {name} {id}>'.format(type=self.type,
|
||||||
name=fullname,
|
name=fullname,
|
||||||
id=hex(id(self)))
|
id=hex(id(self)))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""display the file/entire node"""
|
"""display the file/entire node"""
|
||||||
template = ("{perms} {links:>4} {uid:<8} {gid:<8} {size:>8} "
|
template = ('{perms} {links:>4} {uid:<8} {gid:<8} {size:>8} '
|
||||||
"{date_time} {fullname}\n")
|
'{date_time} {fullname}\n')
|
||||||
|
|
||||||
if not self.name:
|
if not self.name:
|
||||||
return ""
|
return ''
|
||||||
|
|
||||||
fullname = os.path.join(self.dirname, self.name)
|
fullname = os.path.join(self.dirname, self.name)
|
||||||
if self.link_target:
|
if self.link_target:
|
||||||
fullname += " -> " + self.link_target
|
fullname += ' -> ' + self.link_target
|
||||||
|
|
||||||
return template.format(perms=self.perms,
|
return template.format(perms=self.perms,
|
||||||
links=self.links,
|
links=self.links,
|
||||||
@@ -227,9 +323,8 @@ class File(object):
|
|||||||
|
|
||||||
class Adb(object):
|
class Adb(object):
|
||||||
"""Class for interact with android rooted device through adb"""
|
"""Class for interact with android rooted device through adb"""
|
||||||
dirs_to_skip = ["acct", "charger", "d", "dev", "proc", "sys"]
|
|
||||||
file_re = None
|
file_re = None
|
||||||
current_re = re.compile(r"^(\./)?(?P<dir>.+):$")
|
current_re = re.compile(r'^(\./)?(?P<dir>.+):$')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Prepare archive content for operations"""
|
"""Prepare archive content for operations"""
|
||||||
@@ -240,22 +335,32 @@ class Adb(object):
|
|||||||
self._links = {}
|
self._links = {}
|
||||||
self._got_root = False
|
self._got_root = False
|
||||||
|
|
||||||
self.__su_check()
|
if self.conf.try_su:
|
||||||
|
self.__su_check()
|
||||||
|
|
||||||
|
def _shell_cmd(self, with_root, *args):
|
||||||
|
cmd = [self.conf.adb_command, 'shell']
|
||||||
|
|
||||||
|
if with_root and self._got_root:
|
||||||
|
_args = [shlex.quote(x) for x in args]
|
||||||
|
cmd += ['su', '-c', shlex.quote(' '.join(_args))]
|
||||||
|
else:
|
||||||
|
cmd += args
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
|
||||||
def __su_check(self):
|
def __su_check(self):
|
||||||
"""Check if we are able to get elevated privileges"""
|
"""Check if we are able to get elevated privileges"""
|
||||||
|
cmd = self._shell_cmd(False, 'su -c whoami')
|
||||||
try:
|
try:
|
||||||
with open(os.devnull, "w") as fnull:
|
with open(os.devnull, 'w') as fnull:
|
||||||
result = subprocess.check_output('adb shell su -c '
|
result = check_output(cmd, stderr=fnull)
|
||||||
'whoami'.split(),
|
|
||||||
stderr=fnull)
|
|
||||||
|
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return
|
return
|
||||||
|
|
||||||
if 'root' in result:
|
if 'root' in result:
|
||||||
self._got_root = True
|
self._got_root = True
|
||||||
return
|
|
||||||
|
|
||||||
def _find_target(self, needle):
|
def _find_target(self, needle):
|
||||||
"""Find link target"""
|
"""Find link target"""
|
||||||
@@ -294,33 +399,87 @@ class Adb(object):
|
|||||||
for idx in sorted(elems_to_remove, reverse=True):
|
for idx in sorted(elems_to_remove, reverse=True):
|
||||||
del self._entries[idx]
|
del self._entries[idx]
|
||||||
|
|
||||||
def _retrieve_file_list(self, root=None):
|
def _retrieve_single_dir_list(self, dir_):
|
||||||
"""Retrieve file list using adb"""
|
"""Retrieve file list using adb"""
|
||||||
command = ["adb", "shell", "su", "-c"]
|
lscmd = self.conf.box['rls'].format(shlex.quote(dir_))
|
||||||
skip_dirs = self.conf.skip_dirs
|
command = self._shell_cmd(True, *shlex.split(lscmd))
|
||||||
|
|
||||||
if not root:
|
|
||||||
command.append(self.conf.box['ls'])
|
|
||||||
else:
|
|
||||||
command.append(self.conf.box['rls'].format(root.filepath))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.conf.debug:
|
if self.conf.debug:
|
||||||
print "executing", " ".join(command)
|
print('executing', ' '.join(command))
|
||||||
|
|
||||||
lines = subprocess.check_output(command)
|
lines = check_output(command)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
sys.stderr.write("Cannot read directory. Is device connected?\n")
|
sys.stderr.write('Cannot read directory. Is device connected?\n')
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
current_dir = root.dirname if root else "/"
|
lines = [l.strip() for l in lines.split('\n') if l.strip()]
|
||||||
for line in lines.split("\n"):
|
if len(lines) == 1:
|
||||||
|
reg_match = self.file_re.match(lines[0])
|
||||||
|
entry = File(**reg_match.groupdict())
|
||||||
|
entry.update('/')
|
||||||
|
|
||||||
|
if entry.filepath in self.conf.dirs_to_skip:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._entries.append(entry)
|
||||||
|
if entry.type == 'l':
|
||||||
|
self._links[entry.filepath] = entry
|
||||||
|
self._retrieve_single_dir_list(entry.link_target)
|
||||||
|
else:
|
||||||
|
for line in lines:
|
||||||
|
current_dir_re = self.current_re.match(line)
|
||||||
|
if current_dir_re:
|
||||||
|
current_dir = current_dir_re.groupdict()['dir']
|
||||||
|
if not current_dir:
|
||||||
|
current_dir = '/'
|
||||||
|
continue
|
||||||
|
|
||||||
|
reg_match = self.file_re.match(line)
|
||||||
|
if not reg_match:
|
||||||
|
continue
|
||||||
|
|
||||||
|
entry = File(**reg_match.groupdict())
|
||||||
|
if entry.name in ('.', '..'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
entry.update(current_dir)
|
||||||
|
|
||||||
|
if entry.filepath in self.conf.dirs_to_skip:
|
||||||
|
continue
|
||||||
|
|
||||||
|
self._entries.append(entry)
|
||||||
|
|
||||||
|
if entry.type == 'l':
|
||||||
|
self._links[entry.filepath] = entry
|
||||||
|
|
||||||
|
def _retrieve_file_list(self, root=None):
|
||||||
|
"""Retrieve file list using adb"""
|
||||||
|
|
||||||
|
if not root:
|
||||||
|
lscmd = self.conf.box['ls']
|
||||||
|
else:
|
||||||
|
lscmd = self.conf.box['rls'].format(shlex.quote(root.filepath))
|
||||||
|
|
||||||
|
command = self._shell_cmd(True, *shlex.split(lscmd))
|
||||||
|
|
||||||
|
try:
|
||||||
|
if self.conf.debug:
|
||||||
|
print('executing', ' '.join(command))
|
||||||
|
|
||||||
|
lines = check_output(command)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
sys.stderr.write('Cannot read directory. Is device connected?\n')
|
||||||
|
return 2
|
||||||
|
|
||||||
|
current_dir = root.dirname if root else '/'
|
||||||
|
for line in lines.split('\n'):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
current_dir_re = self.current_re.match(line)
|
current_dir_re = self.current_re.match(line)
|
||||||
if current_dir_re:
|
if current_dir_re:
|
||||||
current_dir = current_dir_re.groupdict()["dir"]
|
current_dir = current_dir_re.groupdict()['dir']
|
||||||
if not current_dir:
|
if not current_dir:
|
||||||
current_dir = "/"
|
current_dir = '/'
|
||||||
continue
|
continue
|
||||||
|
|
||||||
reg_match = self.file_re.match(line)
|
reg_match = self.file_re.match(line)
|
||||||
@@ -328,60 +487,58 @@ class Adb(object):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
entry = File(**reg_match.groupdict())
|
entry = File(**reg_match.groupdict())
|
||||||
if entry.name in (".", ".."):
|
if entry.name in ('.', '..'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entry.update(current_dir)
|
entry.update(current_dir)
|
||||||
|
|
||||||
if skip_dirs and entry.filepath in self.conf.dirs_to_skip:
|
if entry.filepath in self.conf.dirs_to_skip:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self._entries.append(entry)
|
self._entries.append(entry)
|
||||||
if root is None and entry.type == "d":
|
if root is None and entry.type == 'd':
|
||||||
self._retrieve_file_list(entry)
|
self._retrieve_file_list(entry)
|
||||||
|
|
||||||
if entry.type == "l":
|
if entry.type == 'l':
|
||||||
self._links[entry.filepath] = entry
|
self._links[entry.filepath] = entry
|
||||||
|
|
||||||
def run(self, fname):
|
def run(self, fname):
|
||||||
"""Not supported"""
|
"""Not supported"""
|
||||||
sys.stderr.write("Not supported - or maybe you are on compatible "
|
sys.stderr.write('Not supported - or maybe you are on compatible '
|
||||||
"architecture?\n")
|
'architecture?\n')
|
||||||
return 1
|
return 3
|
||||||
|
|
||||||
def list(self):
|
def list(self):
|
||||||
"""Output list contents directory"""
|
"""Output list contents directory"""
|
||||||
if self.error:
|
if self.error:
|
||||||
sys.stderr.write(self.error)
|
sys.stderr.write(self.error)
|
||||||
return 1
|
return 4
|
||||||
|
|
||||||
|
if self.conf.root:
|
||||||
|
self._retrieve_single_dir_list(self.conf.root)
|
||||||
|
else:
|
||||||
|
self._retrieve_file_list()
|
||||||
|
|
||||||
self._retrieve_file_list()
|
|
||||||
self._normalize_links()
|
self._normalize_links()
|
||||||
# with open(os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
sys.stdout.write(''.join([str(entry) for entry in self._entries]))
|
||||||
# # "list.pcl"), "w") as fob:
|
|
||||||
# "list.pcl")) as fob:
|
|
||||||
# import cPickle
|
|
||||||
# # cPickle.dump(self._entries, fob)
|
|
||||||
# self._entries = cPickle.load(fob)
|
|
||||||
sys.stdout.write("".join([str(entry) for entry in self._entries]))
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def copyout(self, src, dst):
|
def copyout(self, src, dst):
|
||||||
"""Copy file form the device using adb."""
|
"""Copy file form the device using adb."""
|
||||||
if self.error:
|
if self.error:
|
||||||
sys.stderr.write(self.error)
|
sys.stderr.write(self.error)
|
||||||
return 1
|
return 5
|
||||||
|
|
||||||
cmd = ["adb", "pull", src, dst]
|
cmd = [self.conf.adb_command, 'pull', src, dst]
|
||||||
if self.conf.debug:
|
if self.conf.debug:
|
||||||
sys.stderr.write(" ".join(cmd) + "\n")
|
sys.stderr.write(' '.join(cmd) + '\n')
|
||||||
|
|
||||||
with open(os.devnull, "w") as fnull:
|
with open(os.devnull, 'w') as fnull:
|
||||||
try:
|
try:
|
||||||
err = subprocess.call(cmd, stdout=fnull, stderr=fnull)
|
err = subprocess.call(cmd, stdout=fnull, stderr=fnull)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
sys.stderr.write('Error executing adb shell')
|
sys.stderr.write('Error executing adb shell')
|
||||||
return 1
|
return 6
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
||||||
@@ -389,83 +546,82 @@ class Adb(object):
|
|||||||
"""Copy file to the device through adb."""
|
"""Copy file to the device through adb."""
|
||||||
if self.error:
|
if self.error:
|
||||||
sys.stderr.write(self.error)
|
sys.stderr.write(self.error)
|
||||||
return 1
|
return 7
|
||||||
if not dst.startswith("/"):
|
if not dst.startswith('/'):
|
||||||
dst = "/" + dst
|
dst = '/' + dst
|
||||||
|
|
||||||
# cmd = ["adb", "push", pipes.quote(src), pipes.quote(dst)]
|
cmd = [self.conf.adb_command, 'push', src, dst]
|
||||||
cmd = ["adb", "push", src, dst]
|
|
||||||
if self.conf.debug:
|
if self.conf.debug:
|
||||||
sys.stderr.write(" ".join(cmd) + "\n")
|
sys.stderr.write(' '.join(cmd) + '\n')
|
||||||
|
|
||||||
with open(os.devnull, "w") as fnull:
|
with open(os.devnull, 'w') as fnull:
|
||||||
try:
|
try:
|
||||||
err = subprocess.call(cmd, stdout=fnull, stderr=fnull)
|
err = subprocess.call(cmd, stdout=fnull, stderr=fnull)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
sys.stderr.write('Error executing adb shell')
|
sys.stderr.write('Error executing adb shell')
|
||||||
return 1
|
return 8
|
||||||
|
|
||||||
if err != 0:
|
if err != 0:
|
||||||
sys.stderr.write("Cannot push the file, "
|
sys.stderr.write('Cannot push the file, '
|
||||||
"%s, error %d" % (dst, err))
|
'%s, error %d' % (dst, err))
|
||||||
return 1
|
return 9
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def rm(self, dst):
|
def rm(self, dst):
|
||||||
"""Remove file from device."""
|
"""Remove file from device."""
|
||||||
if self.error:
|
if self.error:
|
||||||
sys.stderr.write(self.error)
|
sys.stderr.write(self.error)
|
||||||
return 1
|
return 10
|
||||||
|
|
||||||
cmd = ["adb", "shell", "rm", dst]
|
cmd = self._shell_cmd(False, 'rm %s' % shlex.quote(dst))
|
||||||
try:
|
try:
|
||||||
err = subprocess.check_output(cmd)
|
err = check_output(cmd).strip()
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
sys.stderr.write('Error executing adb shell')
|
sys.stderr.write('Error executing adb shell')
|
||||||
return 1
|
return 11
|
||||||
|
|
||||||
if err != "":
|
if err != '':
|
||||||
sys.stderr.write(err)
|
sys.stderr.write(err)
|
||||||
return 1
|
return 12
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def rmdir(self, dst):
|
def rmdir(self, dst):
|
||||||
"""Remove directory from device."""
|
"""Remove directory from device."""
|
||||||
if self.error:
|
if self.error:
|
||||||
sys.stderr.write(self.error)
|
sys.stderr.write(self.error)
|
||||||
return 1
|
return 13
|
||||||
|
|
||||||
cmd = ["adb", "shell", "rm", "-r", dst]
|
cmd = self._shell_cmd(False, 'rm -r %s' % shlex.quote(dst))
|
||||||
try:
|
try:
|
||||||
err = subprocess.check_output(cmd)
|
err = check_output(cmd).strip()
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
sys.stderr.write('Error executing adb shell')
|
sys.stderr.write('Error executing adb shell')
|
||||||
return 1
|
return 14
|
||||||
|
|
||||||
if err != "":
|
if err != '':
|
||||||
sys.stderr.write(err)
|
sys.stderr.write(err)
|
||||||
return 1
|
return 15
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def mkdir(self, dst):
|
def mkdir(self, dst):
|
||||||
"""Make directory on the device through adb."""
|
"""Make directory on the device through adb."""
|
||||||
if self.error:
|
if self.error:
|
||||||
sys.stderr.write(self.error)
|
sys.stderr.write(self.error)
|
||||||
return 1
|
return 16
|
||||||
|
|
||||||
if not dst.startswith("/"):
|
if not dst.startswith('/'):
|
||||||
dst = "/" + dst
|
dst = '/' + dst
|
||||||
|
|
||||||
cmd = ["adb", "shell", "mkdir", dst]
|
cmd = self._shell_cmd(False, 'mkdir %s' % shlex.quote(dst))
|
||||||
try:
|
try:
|
||||||
err = subprocess.check_output(cmd)
|
err = check_output(cmd).strip()
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
sys.stderr.write('Error executing adb shell')
|
sys.stderr.write('Error executing adb shell')
|
||||||
return 1
|
return 17
|
||||||
|
|
||||||
if err != "":
|
if err != '':
|
||||||
sys.stderr.write(err)
|
sys.stderr.write(err)
|
||||||
return 1
|
return 18
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@@ -524,8 +680,12 @@ def main():
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
return args.func(args)
|
try:
|
||||||
|
return args.func(args)
|
||||||
|
except AttributeError:
|
||||||
|
parser.print_help()
|
||||||
|
parser.exit()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|||||||
56
test_adbfs.py
Normal file
56
test_adbfs.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import os
|
||||||
|
from importlib.util import spec_from_loader, module_from_spec
|
||||||
|
from importlib.machinery import SourceFileLoader
|
||||||
|
import unittest
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 /storage/emulated/0/\x80
|
||||||
|
-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 /storage/emulated/0/Γεια σας
|
||||||
|
-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 /storage/emulated/0/Здравствуйте
|
||||||
|
-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 /storage/emulated/0/שָׁלוֹם
|
||||||
|
-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 /storage/emulated/0/السَّلامُ عَلَيْكُمْ
|
||||||
|
-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 /storage/emulated/0/გამარჯობა
|
||||||
|
-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 /storage/emulated/0/こんにちは。
|
||||||
|
-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 /storage/emulated/0/안녕하십니까
|
||||||
|
''' # noqa
|
||||||
|
|
||||||
|
|
||||||
|
class TestCheckOutput(unittest.TestCase):
|
||||||
|
|
||||||
|
@mock.patch('subprocess.check_output')
|
||||||
|
def test_check_output(self, out):
|
||||||
|
"""
|
||||||
|
As for Python2 (and its last version: 2.7), subprocess.check_output
|
||||||
|
always return string like objects, contrary to bytes - no conversion
|
||||||
|
to string is needed.
|
||||||
|
Python3 treats string as unicode objects, but subprocess.check_output
|
||||||
|
returns bytes object, which is equvalend for py2 string… annoying.
|
||||||
|
"""
|
||||||
|
out.return_value = bytes(LISTING, 'utf-8')
|
||||||
|
result = adbfs.check_output(None)
|
||||||
|
self.assertEqual(result, LISTING)
|
||||||
|
|
||||||
|
@mock.patch('subprocess.check_output')
|
||||||
|
def test_check_output_py3_invalid_char(self, out):
|
||||||
|
"""
|
||||||
|
Special case for py3. We have bytes with some weird character - like
|
||||||
|
some system write something with codepage, instead of utf8.
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
result = adbfs.check_output(None)
|
||||||
|
self.assertEqual(result, line.decode('iso-8859-1'))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user