Source code for tksn.adb.utils
# -*- coding: utf-8 -*-
"""Utilities
:copyright: (c) 2016 by tksn
:license: MIT
"""
from __future__ import unicode_literals
import io
import os
import re
import sys
import tempfile
import uuid
import tksn.adb.call
[docs]def get_device_serials():
"""
Get connected device serial numbers
Returns:
list: list of serial number(string)s.
"""
adb = tksn.adb.call.get_adb_executable()
result_out, _ = tksn.adb.call.call_sync((adb, 'devices'))
strio = io.StringIO(result_out.decode(sys.getdefaultencoding()))
serials = []
for line in strio.readlines():
m = re.search(r'(\S+)\s+device\s*$', line)
if m:
serials.append(m.group(1))
return serials
[docs]def get_tempfilepath():
"""
Get temporary file path.
Returns:
str: temporary file path
"""
tempdir = tempfile.gettempdir()
tempprefix = tempfile.gettempprefix()
random_str = str(uuid.uuid4())
filename = tempprefix + '_' + random_str
return os.path.join(tempdir, filename)