mirror of
https://github.com/gryf/mc_adbfs.git
synced 2025-12-18 20:10:21 +01:00
Added adb_connect feature
This commit is contained in:
@@ -70,6 +70,8 @@ You can configure behaviour of this plugin using ``.ini`` file located under
|
|||||||
suppress_colors = false
|
suppress_colors = false
|
||||||
root =
|
root =
|
||||||
adb_command = adb
|
adb_command = adb
|
||||||
|
adb_connect =
|
||||||
|
|
||||||
|
|
||||||
where:
|
where:
|
||||||
|
|
||||||
@@ -84,7 +86,12 @@ where:
|
|||||||
* ``root`` root directory to read. Everything outside of that directory will be
|
* ``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
|
omitted. That would be the fastest way to access certain location on the
|
||||||
device. Note, that ``dirs_to_skip`` still apply inside this directory.
|
device. Note, that ``dirs_to_skip`` still apply inside this directory.
|
||||||
* ``adb_command`` = path to ``adb`` command.
|
* ``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 usefull for *adb over network*
|
||||||
|
feature. Typical value here is a device IP address with optional port, which
|
||||||
|
defaults to 5555.
|
||||||
|
|
||||||
Limitations
|
Limitations
|
||||||
===========
|
===========
|
||||||
|
|||||||
53
adbfs
53
adbfs
@@ -57,8 +57,10 @@ class Conf(object):
|
|||||||
self.root = None
|
self.root = None
|
||||||
self.suppress_colors = False
|
self.suppress_colors = False
|
||||||
self.adb_command = 'adb'
|
self.adb_command = 'adb'
|
||||||
|
self.adb_connect = ''
|
||||||
|
|
||||||
self.read()
|
self.read()
|
||||||
|
self.connect()
|
||||||
self.get_the_box()
|
self.get_the_box()
|
||||||
|
|
||||||
def get_the_box(self):
|
def get_the_box(self):
|
||||||
@@ -94,6 +96,54 @@ class Conf(object):
|
|||||||
sys.stderr.write('There is no toolbox or busybox available.\n')
|
sys.stderr.write('There is no toolbox or busybox available.\n')
|
||||||
sys.exit(1)
|
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 = subprocess.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 = subprocess.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):
|
||||||
"""
|
"""
|
||||||
Read config file and change the options according to values from that
|
Read config file and change the options according to values from that
|
||||||
@@ -111,7 +161,8 @@ class Conf(object):
|
|||||||
'dirs_to_skip': (cfg.get, 'dirs_to_skip'),
|
'dirs_to_skip': (cfg.get, 'dirs_to_skip'),
|
||||||
'suppress_colors': (cfg.get, 'suppress_colors'),
|
'suppress_colors': (cfg.get, 'suppress_colors'),
|
||||||
'root': (cfg.get, 'root'),
|
'root': (cfg.get, 'root'),
|
||||||
'adb_command': (cfg.get, 'adb_command')}
|
'adb_command': (cfg.get, 'adb_command'),
|
||||||
|
'adb_connect': (cfg.get, 'adb_connect')}
|
||||||
cfg.read(conf_fname)
|
cfg.read(conf_fname)
|
||||||
|
|
||||||
for key, (function, attr) in cfg_map.items():
|
for key, (function, attr) in cfg_map.items():
|
||||||
|
|||||||
Reference in New Issue
Block a user