Skip to content

Commit ffb30bf

Browse files
author
马飞
committed
init apptoolkit
0 parents  commit ffb30bf

File tree

9 files changed

+277
-0
lines changed

9 files changed

+277
-0
lines changed

.gitignore

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Python template
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
*.py[cod]
6+
*$py.class
7+
8+
# C extensions
9+
*.so
10+
11+
# Distribution / packaging
12+
.Python
13+
env/
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*,cover
48+
.hypothesis/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
58+
# Flask stuff:
59+
instance/
60+
.webassets-cache
61+
62+
# Scrapy stuff:
63+
.scrapy
64+
65+
# Sphinx documentation
66+
67+
# PyBuilder
68+
target/
69+
70+
# IPython Notebook
71+
.ipynb_checkpoints
72+
73+
# pyenv
74+
.python-version
75+
76+
# celery beat schedule file
77+
celerybeat-schedule
78+
79+
# dotenv
80+
.env
81+
82+
# virtualenv
83+
venv/
84+
ENV/
85+
.venv/
86+
87+
# Spyder project settings
88+
.spyderproject
89+
90+
# Rope project settings
91+
.ropeproject
92+
.idea/
93+
/dump.rdb

CHANGES

Whitespace-only changes.

LICENSE

Whitespace-only changes.

MANIFEST.in

Whitespace-only changes.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Introduction
2+
3+
## Design Philosophy
4+
5+
This is a lightweight set of tools for obtaining information about Android devices in Python
6+
7+
## Learn more
8+
9+
You can read this [blog][mafei-blog] to learn more about the `apptoolkit`.
10+
11+
[mafei-blog]: http://mafei.me/

apptoolkit/__init__.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
apptoolkit
5+
~~~~~~~~~~~~
6+
7+
This module is the main config.
8+
9+
:copyright: (c) 2017 by Ma Fei.
10+
"""
11+
12+
import os
13+
14+
import subprocess
15+
16+
__version__ = '0.0.2'
17+
18+
19+
class Shell:
20+
def __init__(self):
21+
pass
22+
23+
@staticmethod
24+
def invoke(cmd):
25+
output, errors = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
26+
o = output.decode("utf-8")
27+
return o
28+
29+
30+
# 判断是否设置环境变量ANDROID_HOME
31+
if "ANDROID_HOME" in os.environ:
32+
command = os.path.join(
33+
os.environ["ANDROID_HOME"],
34+
"platform-tools",
35+
"adb")
36+
else:
37+
raise EnvironmentError(
38+
"Adb not found in $ANDROID_HOME path: %s." %
39+
os.environ["ANDROID_HOME"])
40+
41+
42+
class ADB(object):
43+
"""
44+
参数: device_id
45+
"""
46+
47+
def __init__(self, device_id=""):
48+
49+
if device_id == "":
50+
self.device_id = ""
51+
else:
52+
self.device_id = "-s %s" % device_id
53+
54+
def adb(self, args):
55+
cmd = "%s %s %s" % (command, self.device_id, str(args))
56+
return Shell.invoke(cmd)
57+
58+
def shell(self, args):
59+
cmd = "%s %s shell %s" % (command, self.device_id, str(args),)
60+
return Shell.invoke(cmd)
61+
62+
def get_device_state(self):
63+
"""
64+
获取设备状态: offline | bootloader | device
65+
"""
66+
return self.adb("get-state").stdout.read().strip()
67+
68+
def get_device_id(self):
69+
"""
70+
获取设备id号,return serialNo
71+
"""
72+
return self.adb("get-serialno").stdout.read().strip()
73+
74+
def get_android_version(self):
75+
"""
76+
获取设备中的Android版本号,如4.2.2
77+
"""
78+
return self.shell(
79+
"getprop ro.build.version.release").strip()
80+
81+
def get_sdk_version(self):
82+
"""
83+
获取设备SDK版本号,如:24
84+
"""
85+
return self.shell("getprop ro.build.version.sdk").strip()
86+
87+
def get_product_brand(self):
88+
"""
89+
获取设备品牌,如:HUAWEI
90+
"""
91+
return self.shell("getprop ro.product.brand").strip()
92+
93+
def get_product_model(self):
94+
"""
95+
获取设备型号,如:MHA-AL00
96+
"""
97+
return self.shell("getprop ro.product.model").strip()
98+
99+
def get_product_rom(self):
100+
"""
101+
获取设备ROM名,如:MHA-AL00C00B213
102+
"""
103+
return self.shell("getprop ro.build.display.id").strip()
104+
105+
106+
class DeviceInfo:
107+
def __init__(self, uid, os_type, os_version, sdk_version, brand, model, rom_version):
108+
self.uid = uid
109+
self.os_type = os_type
110+
self.os_version = os_version
111+
self.sdk_version = sdk_version
112+
self.brand = brand
113+
self.model = model
114+
self.rom_version = rom_version
115+
116+
117+
class Device:
118+
def __init__(self):
119+
pass
120+
121+
@staticmethod
122+
def get_android_devices():
123+
android_devices_list = []
124+
android_devices_infos = []
125+
for device in Shell.invoke('adb devices').splitlines():
126+
if 'device' in device and 'devices' not in device:
127+
device = device.split('\t')[0]
128+
android_devices_list.append(device)
129+
for device_uid in android_devices_list:
130+
device_info = DeviceInfo(device_uid, "Android", ADB(device_uid).get_android_version(),
131+
ADB(device_uid).get_sdk_version(),
132+
ADB(device_uid).get_product_brand(), ADB(device_uid).get_product_model(),
133+
ADB(device_uid).get_product_rom())
134+
android_devices_infos.append(device_info.__dict__)
135+
return android_devices_infos

deploy.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
# 指定脚本版本,然后进行部署.
4+
source venv/bin/activate
5+
rm -rf dist/*
6+
python setup.py bdist_wheel --universal
7+
twine upload dist/apptoolkit*

requirements.txt

Whitespace-only changes.

setup.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
#############################################
5+
# File Name: setup.py
6+
# Author: mafei
7+
8+
# Created Time: 2017-06-26 01:25:34 AM
9+
#############################################
10+
11+
from setuptools import setup, find_packages
12+
13+
import apptoolkit
14+
15+
setup(
16+
name="apptoolkit",
17+
version=apptoolkit.__version__,
18+
description="apptoolkit",
19+
long_description=open("README.md").read(),
20+
license="MIT Licence",
21+
22+
author="mafei",
23+
author_email="[email protected]",
24+
url="https://github.com/logan62334/python-apptoolkit.git",
25+
26+
packages=find_packages(),
27+
include_package_data=True,
28+
zip_safe=True,
29+
platforms="any",
30+
install_requires=[]
31+
)

0 commit comments

Comments
 (0)