mirror of
https://github.com/gryf/mc_adbfs.git
synced 2025-12-18 20:10:21 +01:00
Added support for toolbox
This commit is contained in:
@@ -17,7 +17,7 @@ Make sure, that issuing from command line::
|
|||||||
|
|
||||||
$ adb shell busybox ls
|
$ adb shell busybox ls
|
||||||
|
|
||||||
should display files from root directory on the device.
|
it should display files from root directory on the device.
|
||||||
|
|
||||||
Features
|
Features
|
||||||
========
|
========
|
||||||
@@ -55,6 +55,8 @@ Limitations
|
|||||||
files are on the device and so on
|
files are on the device and so on
|
||||||
* Some filenames might be still inaccessible for operating
|
* Some filenames might be still inaccessible for operating
|
||||||
* All files operations which needs root privileges will fail (for now)
|
* All files operations which needs root privileges will fail (for now)
|
||||||
|
* The implementation is experimental and it's by now working with mine device;
|
||||||
|
while it might not work with yours
|
||||||
|
|
||||||
License
|
License
|
||||||
=======
|
=======
|
||||||
|
|||||||
49
adbfs
49
adbfs
@@ -18,6 +18,7 @@ import sys
|
|||||||
|
|
||||||
DEBUG = os.getenv("ADBFS_DEBUG", False)
|
DEBUG = os.getenv("ADBFS_DEBUG", False)
|
||||||
SKIP_SYSTEM_DIR = os.getenv("ADBFS_SKIP_SYSTEM_DIR", True)
|
SKIP_SYSTEM_DIR = os.getenv("ADBFS_SKIP_SYSTEM_DIR", True)
|
||||||
|
BOX = os.getenv("ADBFS_BOX", "busybox")
|
||||||
|
|
||||||
|
|
||||||
class File(object):
|
class File(object):
|
||||||
@@ -84,10 +85,7 @@ class File(object):
|
|||||||
|
|
||||||
def mk_link_relative(self, target_type):
|
def mk_link_relative(self, target_type):
|
||||||
"""Convert links to relative"""
|
"""Convert links to relative"""
|
||||||
rel_path = self.dirname
|
self.link_target = os.path.relpath(self.link_target, self.dirname)
|
||||||
# if target_type == "d":
|
|
||||||
# rel_path = self.filepath
|
|
||||||
self.link_target = os.path.relpath(self.link_target, rel_path)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""represent the file/entire node"""
|
"""represent the file/entire node"""
|
||||||
@@ -179,16 +177,17 @@ class Adb(object):
|
|||||||
|
|
||||||
def _retrieve_file_list(self, root=None):
|
def _retrieve_file_list(self, root=None):
|
||||||
"""Retrieve file list using adb"""
|
"""Retrieve file list using adb"""
|
||||||
|
|
||||||
# if root:
|
|
||||||
# print "retrieve for %s" % root.filepath
|
|
||||||
command = ["adb", "shell", "su", "-c"]
|
command = ["adb", "shell", "su", "-c"]
|
||||||
|
|
||||||
if not root:
|
if not root:
|
||||||
command.append("'busybox ls -anel'")
|
command.append("busybox ls -anel")
|
||||||
else:
|
else:
|
||||||
command.append("'busybox ls -Ranel {}'".format(root.filepath))
|
command.append("busybox ls -Ranel {}".format(root.filepath))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if DEBUG:
|
||||||
|
print "executing", " ".join(command)
|
||||||
|
|
||||||
lines = subprocess.check_output(command)
|
lines = subprocess.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")
|
||||||
@@ -233,28 +232,40 @@ class Adb(object):
|
|||||||
def list(self):
|
def list(self):
|
||||||
"""Output list contents directory"""
|
"""Output list contents directory"""
|
||||||
self._retrieve_file_list()
|
self._retrieve_file_list()
|
||||||
# self._retrieve_file_list_from_pickle()
|
|
||||||
# self._save_file_list_to_pickle()
|
|
||||||
self._normalize_links()
|
self._normalize_links()
|
||||||
|
# with open(os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||||
|
# # "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]))
|
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."""
|
||||||
|
# cmd = ["adb", "pull", pipes.quote(src), pipes.quote(dst)]
|
||||||
|
cmd = ["adb", "pull", src, dst]
|
||||||
|
if DEBUG:
|
||||||
|
sys.stderr.write(" ".join(cmd) + "\n")
|
||||||
|
|
||||||
with open(os.devnull, "w") as fnull:
|
with open(os.devnull, "w") as fnull:
|
||||||
return subprocess.call(["adb", "pull", pipes.quote(src),
|
err = subprocess.call(cmd, stdout=fnull, stderr=fnull)
|
||||||
pipes.quote(dst)],
|
|
||||||
stdout=fnull, stderr=fnull)
|
return err
|
||||||
|
|
||||||
def copyin(self, src, dst):
|
def copyin(self, src, dst):
|
||||||
"""Copy file to the device through adb."""
|
"""Copy file to the device through adb."""
|
||||||
if not dst.startswith("/"):
|
if not dst.startswith("/"):
|
||||||
dst = "/" + dst
|
dst = "/" + dst
|
||||||
|
|
||||||
|
# cmd = ["adb", "push", pipes.quote(src), pipes.quote(dst)]
|
||||||
|
cmd = ["adb", "push", src, dst]
|
||||||
|
if DEBUG:
|
||||||
|
sys.stderr.write(" ".join(cmd) + "\n")
|
||||||
|
|
||||||
with open(os.devnull, "w") as fnull:
|
with open(os.devnull, "w") as fnull:
|
||||||
err = subprocess.call(["adb", "push", pipes.quote(src),
|
err = subprocess.call(cmd, stdout=fnull, stderr=fnull)
|
||||||
pipes.quote(dst)],
|
|
||||||
stdout=fnull, stderr=fnull)
|
|
||||||
|
|
||||||
if err != 0:
|
if err != 0:
|
||||||
sys.stderr.write("Cannot push the file, "
|
sys.stderr.write("Cannot push the file, "
|
||||||
@@ -308,6 +319,7 @@ def main():
|
|||||||
sys.stderr.write("commandline: %s\n" % " ".join(sys.argv))
|
sys.stderr.write("commandline: %s\n" % " ".join(sys.argv))
|
||||||
if sys.argv[1] not in ('list', 'copyin', 'copyout', 'rm', "rmdir",
|
if sys.argv[1] not in ('list', 'copyin', 'copyout', 'rm', "rmdir",
|
||||||
'mkdir', "run"):
|
'mkdir', "run"):
|
||||||
|
print "missing argument" if DEBUG else None
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
@@ -331,6 +343,9 @@ def main():
|
|||||||
elif sys.argv[1] in ('rm', 'rmdir', 'run', 'mkdir'):
|
elif sys.argv[1] in ('rm', 'rmdir', 'run', 'mkdir'):
|
||||||
arg.dst = sys.argv[3]
|
arg.dst = sys.argv[3]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
if DEBUG:
|
||||||
|
print "there is a problem with identifying command and its args"
|
||||||
|
print "current args:", sys.argv
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
return CALL_MAP[sys.argv[1]](arg)
|
return CALL_MAP[sys.argv[1]](arg)
|
||||||
|
|||||||
Reference in New Issue
Block a user