通过sweech应用程序与android设备交互的命令行实用程序
sweech-cli的Python项目详细描述
这是什么?
它是与Sweech Wifi file transfer交互的命令行工具。
sweech是一款android应用,你可以通过它浏览手机内容并传输文件。它基于一个http服务器。此工具与sweech的http api交互。您可以直接从喜爱的外壳通过WiFi推送和拉取文件
很好,我怎么得到它?
使用python的pip
$ pip install sweech-cli
或者下载python脚本并将其添加到$PATH
$ curl -o sweech https://raw.githubusercontent.com/alberthier/sweech-cli/master/sweech.py
或
$ wget -O sweech https://raw.githubusercontent.com/alberthier/sweech-cli/master/sweech.py
我怎么用?
sweech工具完全独立:
$ sweech -u http://192.168.0.65 info
在linux/macos上创建一个包含连接设置的配置文件是可行的:~/.config/sweech.json,在windows上创建一个包含连接设置的配置文件是可行的%APPDATA%/sweech.json。
下面是一个示例文件,用于将192.168.0.65作为IP地址的电话
{"url":"http://192.168.0.65:4444","user":"","password":"","defaultdir":"/storage/emulated/0/Downloads"}
如果定义了defaultdir,则所有相对远程路径都将相对于此默认目录进行解释。
假设您已将sweech添加到PATH:
$ sweech info
打印设备的信息和默认路径
$ sweech ls /storage/emulated/0/Download
列出文件夹的内容或显示文件的详细信息
$ sweech push testdir
将文件或目录推送到远程路径。如果未指定远程文件,则使用defaultdir。
只能在内部存储中创建文件和目录。如果您已在应用程序的设置中授予Sweech此授权,则外部存储(SD卡)也可以写入。
--keep选项只上载远程设备上丢失的文件。现有文件未被触碰。
$ sweech pull testdir
将文件和文件夹从远程设备拉到本地文件夹。如果远程文件路径是相对的,defaultdir将用作基路径
--keep选项只下载丢失的本地文件。现有文件未被触碰。
$ sweech mkdir testdir
创建目录。也会创建缺少的中间目录
$ sweech rm /some/path
删除文件或目录(及其内容)
$ sweech mv /some/path /some/otherpath
移动文件或目录(及其内容)。在某些情况下,在目录之间移动文件可能会很慢(在不同存储之间,在Android 7.0之前的外部SD卡上)
$ sweech cat /path/to/some/file.txt
显示文件的内容
$ sweech clipboard
显示Android剪贴板的内容
$ sweech clipboard "Hello World"
设置Android剪贴板的内容
如果我想在python脚本中使用它呢?
只需导入sweech模块并使用Connector对象。所有cli命令都有其等效的方法:
importsweechc=sweech.Connector('http://192.168.0.11:4444')print(c.info())forfinc.ls('/storage/emulated/0/Download'):print(f)withopen('test.txt','wt')asf:f.write('Hello World')c.push('test.txt','/storage/emulated/0/Download')c.pull('/storage/emulated/0/Download/test.txt','/tmp')f=c.cat('/storage/emulated/0/Download/test.txt')print(f.read().decode('utf-8'))f.close()c.mkdir('/storage/emulated/0/Download/testdir')c.mv('/storage/emulated/0/Download/testdir','/storage/emulated/0/Download/testdir2')c.rm('/storage/emulated/0/Download/testdir2')txt=c.clipboard()c.clipboard(txt+" hello world")
依赖关系
- python 2.7或python 3.5+