Ejemplo n.º 1
0
async def reverse_listener(reader, writer):
    data = b''
    while len(data)<3:
        dat = await reader.read(2048)
        data += dat
    
    while len(data)>=3:
        print("data:", len(data), data[:10])
        if data[:3] == b'con':
            if not state_map['activated']:
                print("reverse proxy established")
            else:
                print("A new connect have been established, the old one is disconnected")
                #state_map['connected_reader'].close()
                state_map['connected_writer'].close()

            state_map['activated'] = True
            state_map['connected_reader'] = reader
            state_map['connected_writer'] = writer
            # Can the reader and the writer still work after the function(coroutine) exit?

            data = data[3:]

        elif data[:3] == b'new':
            idx = unsigned_short.unpack(data[3:5])[0]
            print("reverse idx:", idx)
            if idx not in available_set:
                print("The idx is suspicious since it have not been considered as valid token")
                #reader.close() #AttributeError: 'StreamReader' object has no attribute 'close'
                writer.close()
                return
            if len(waiting_stack) ==0:
                print("Empty waiting stack, the verbose connection is rejected.")
                writer.close()
                return
            print("New channel connection have been established")
            reader_request, writer_request = waiting_stack.pop() #channel_map[idx]

            pipe1 = pipe(reader_request, writer)
            pipe2 = pipe(reader, writer_request)

            try:
                await asyncio.gather(pipe1, pipe2)
            finally:
                print("writer.close()")
                writer.close()

            #channel_map[idx] = (reader, writer)

            data = data[5:]

        else:
            print("Unknown command {}, exit".format(data[:3]))
            #reader.close()
            writer.close()
            return
Ejemplo n.º 2
0
    def get_sign_info(apk_file, is_windows=False):
        """获得签名信息
        return (md5,sha1,sha256,result)
        """
        # reg_group = utils.reg_group

        # 查找、释放 rsa 文件
        rsa_out = setting_atool.temp_dir
        m_zip = util_atool.Unzip(apk_file)
        rsa = m_zip.find_rsa()
        m_zip.extract(rsa, rsa_out)
        m_zip.destroy()

        url = rsa_out + os.sep + rsa
        if not os.path.exists(url):
            print('rsa文件释放失败 {}'.format(url))
            return '', '', ''

        url_pem = str(Path(url).with_suffix(".pem"))
        c_trans_cert = '{openssl} pkcs7 -inform DER -in {rsa} -out {pem} -outform PEM -print_certs'
        c_print_cert = '{openssl} x509 -inform pem -in {pem} -fingerprint -{hash_type} -noout'
        openssl = util_atool.openssl_path if is_windows else 'openssl'
        index = len('openssl')

        # 转换RSA文件为PEM
        s = c_trans_cert.format(openssl=openssl, rsa=url, pem=url_pem)
        utils.execute(s)

        c_print = c_print_cert.format(openssl=openssl,
                                      rsa=url,
                                      pem=url_pem,
                                      hash_type="{hash_type}")
        s = c_print.format(hash_type="md5")
        result = utils.pipe(s)
        arr = result.split("Fingerprint=")
        # MD5 Fingerprint=EF:43:77:9C:15:7C:69:5E:25:BD:2D:6C:D3:49:FC:DD
        if len(arr) > 1:
            md5 = arr[1].replace(":", "")
        else:
            md5 = "计算出错"

        s = c_print.format(hash_type="SHA1")
        result = utils.pipe(s)
        arr = result.split("Fingerprint=")
        sha1 = arr[1] if len(arr) > 1 else "计算出错"

        s = c_print.format(hash_type="SHA256")
        result = utils.pipe(s)
        arr = result.split("Fingerprint=")
        sha256 = arr[1] if len(arr) > 1 else "计算出错"

        md5 = md5.replace("\\n'", "")
        sha1 = sha1.replace("\\n'", "")
        sha256 = sha256.replace("\\n'", "")
        return md5, sha1, sha256
Ejemplo n.º 3
0
async def listener(reader, writer):
    try:

        #async with websockets.connect(xi_addr) as websocket:
        remote_reader, remote_writer = await asyncio.open_connection(
            xi_host, xi_port)
        pipe1 = pipe(reader, remote_writer)
        pipe2 = pipe(remote_reader, writer)
        await asyncio.gather(pipe1, pipe2)
    finally:
        print("writer.close()")
        writer.close()
Ejemplo n.º 4
0
def set_resolution(_serial, _size="", _density=""):
    """ 设置屏幕分辨率和屏幕密度, 支持单独设置 """
    if _size and _density:
        s = '{adb} -s {serial} shell wm size {size} && \\'
        s += '{adb} -s {serial} shell wm density {density}'
        # s += '{adb} -s {serial} shell am kill com.android.settings'
        s = utils.fix_cmd_wrap(s)
        s = s.format(adb=adb_path,
                     serial=_serial,
                     size=_size,
                     density=_density)
    elif _size:
        s = '{adb} -s {serial} shell wm size {size}'
        s = utils.fix_cmd_wrap(s)
        s = s.format(adb=adb_path, serial=_serial, size=_size)
    elif _density:
        s = '{adb} -s {serial} shell wm density {density}'
        s = utils.fix_cmd_wrap(s)
        s = s.format(adb=adb_path, serial=_serial, density=_density)
    else:
        s = ""

    if s:
        result = utils.pipe(s)
        print(result)
        return result
    else:
        print("set_resolution方法 传参错误!!")
        return ""
Ejemplo n.º 5
0
def log_fast(_serial):
    txt_path = 'logcat-{now}.txt'.format(now=__get_now())

    save_dir = setting_atool.output_dir + os.sep + "logcat"
    final_txt = save_dir + os.sep + txt_path
    utils.make_dir(save_dir)

    s = '{adb} -s {serial} logcat -d -v time > "{final_txt}"'
    s = s.format(adb=adb_path, serial=_serial, final_txt=final_txt)
    print(s)
    utils.pipe(s)

    # 替换日志中多余的换行
    if utils.is_windows:
        _replace_empty_line(final_txt)

    return final_txt
Ejemplo n.º 6
0
def huawei_unlock(_serial):
    """华为解锁"""
    # 先按电源键, 再滑动
    s = '{adb} -s {serial} shell input keyevent {keycode} && \\'
    s += "{adb} -s {serial} shell input swipe 250 250 600 600"
    s = utils.fix_cmd_wrap(s)
    s = s.format(adb=adb_path, serial=_serial, keycode=26)
    return utils.pipe(s)
Ejemplo n.º 7
0
def main():
    grid = parse(sys.stdin.readlines())

    after100 = nth(iterate(animate, grid), 100)
    print('part1: ', count_on(after100))

    after100 = nth(iterate(pipe(animate, turn_edges), grid), 100)
    print('part1: ', count_on(after100))
Ejemplo n.º 8
0
def main():
  grid = parse(sys.stdin.readlines())

  after100 = nth(iterate(animate, grid), 100)
  print('part1: ', count_on(after100))

  after100 = nth(iterate(pipe(animate, turn_edges), grid), 100)
  print('part1: ', count_on(after100))
Ejemplo n.º 9
0
async def make_pipe(command, reverse_ip, reverse_port):

    reader_expose, writer_expose = await asyncio.open_connection(
        "127.0.0.1", expose_port)
    reader_reverse, writer_reverse = await asyncio.open_connection(
        reverse_ip, reverse_port)

    writer_reverse.write(b"new" + unsigned_short.pack(command))
    await writer_reverse.drain()

    pipe1 = pipe(reader_reverse, writer_expose)
    pipe2 = pipe(reader_expose, writer_reverse)
    try:
        await asyncio.gather(pipe1, pipe2)
    finally:
        print("writer_reverse writer_expose close")
        writer_reverse.close()
        writer_expose.close()
Ejemplo n.º 10
0
def lines_fromfiles(top):
    '''
    Generate lines from files
    Parameter
        top: path to top of directory tree
    Returns
        generator for lines in files
    '''
    return pipe((gen_filelist, ), (gen_open, ), (gen_cat, ))(top)
Ejemplo n.º 11
0
def open_wifi_debug(_serial):
    """开启wifi调试"""
    s = '{adb} -s {serial} shell setprop service.adb.tcp.port 5555 && \\'
    s += '{adb} -s {serial} tcpip 5555'
    s = utils.fix_cmd_wrap(s)
    s = s.format(adb=adb_path, serial=_serial)
    print(s.replace(" && \\", "\n"))
    result = utils.pipe(s)
    print(result)
    return result
Ejemplo n.º 12
0
async def listener(reader, writer):
    print('start server listener:',reader, writer)

    event_list, data = await recv_http_socket(reader)
    print('recv_http_socket:', event_list, data)
    request = parse_request(event_list)

    remote_reader, remote_writer = await asyncio.open_connection(request['host'], request['port'])

    if request['method'] == b'CONNECT':
        #await writer.write(b'HTTP/1.0 200 Connection Established\r\nProxy-agent: Pyx\r\n\r\n')
        writer.write(b'HTTP/1.1 200 Connection Established\r\n\r\n')
        await writer.drain()
    else:
        remote_writer.write(data)
        await remote_writer.drain()

    pipe1 = pipe(remote_reader, writer)
    pipe2 = pipe(reader, remote_writer)
    await asyncio.gather(pipe1, pipe2)
Ejemplo n.º 13
0
def screen_capture(_serial, auto_open=False):
    """截图
    """
    _arr = get_current_activity(_serial)
    activity_name = _arr[1]

    if activity_name:
        activity_name = activity_name.replace('.', '-')
        prefix = activity_name
    else:
        # 'adb -s {} shell getprop ro.product.model'.format(device)
        # getprop ro.product.name
        # s1 = 'adb -s {serial} shell getprop ro.product.name'.format(serial=_serial)
        d = device_data_find(_serial)
        ss = d.getprop('ro.product.name')
        device_name = ss.replace(' ', '_').replace('\n', '')

        ss = d.getprop('ro.build.id')
        build_id = ss.replace(' ', '_').replace('\n', '')
        prefix = device_name + '-' + build_id

    # s1 = 'adb -s {serial} shell getprop ro.product.name'.format(serial=_serial)
    # device_name = execute(s1).replace(' ', '_').replace('\r\n', '')
    # need_fix = True if device_name == 'lineage_m2note' else False

    png = '{prefix}-{now}.png'.format(prefix=prefix, now=__get_now())
    # s = 'cd {outdir} && \\'
    s = '{adb} -s {serial} shell screencap -p /sdcard/{png} && \\'
    s += '{adb} -s {serial} pull /sdcard/{png} {outdir} && \\'
    s += '{adb} -s {serial} shell rm /sdcard/{png}'
    s = utils.fix_cmd_wrap(s)
    final_png = setting_atool.output_dir + os.sep + png
    s = s.format(adb=adb_path, outdir=final_png, serial=_serial, png=png)
    print(no_xuhangfu(s))
    utils.pipe(s)

    show_msg("已截屏 " + png)
    if auto_open:
        utils.open_file(final_png)

    setting_atool.last_screen_shot = final_png
Ejemplo n.º 14
0
def sampleStratEligible(graph, strats, strat, x):
    def filterStrat(x): return x[1] == strat
    def filterStrats(xs): return filter(filterStrat, xs)
    ofStrat = pipe(enumerate, filterStrats, mapNth(0), list)(strats)
    if not ofStrat:
        return None
    else:
        eligible = list(
            set(ofStrat) - set(graph.get_all_neighbors(x)) - set([x]))
        if not eligible:
            return None
        return np.random.choice(eligible)
Ejemplo n.º 15
0
def main():
    db = "{}/data/db".format(environ["WD"])
    if not exists(db):
        con = connect(db)
        data = \
            pipe( load_csv()
                , rename_columns
                , clean_date
                )
        data.to_sql(name="data", con=con)
    else:
        print("data already compiled to {}".format(db))
Ejemplo n.º 16
0
def debug_layout(_serial, is_on=False):
    """
    打开/关闭 布局边界
    adb shell setprop debug.layout true
    adb shell am start com.android.settings/.DevelopmentSettings
    """
    on_str = 'true' if is_on else 'false'
    s = '{adb} -s {serial} shell setprop debug.layout {on_str} && \\'
    s += '{adb} -s {serial} shell am start com.android.settings/.DevelopmentSettings'
    # s += '{adb} -s {serial} shell am kill com.android.settings'

    s = utils.fix_cmd_wrap(s)
    s = s.format(adb=adb_path, serial=_serial, on_str=on_str)
    return utils.pipe(s)
Ejemplo n.º 17
0
def screen_record(_serial, second=180):
    """录屏
    """
    # 'adb -s {} shell getprop ro.product.model'.format(device)
    # s2 = 'adb -s {serial} shell getprop ro.build.id'.format(serial=serial)
    # buildId = execute(s2).replace(' ', '_')
    # 部分手机不支持录屏
    d = device_data_find(_serial)
    # if not d.can_record:
    #     utils.showinfo("当前设备不能录屏")
    #     return

    device_name = d.getprop('ro.product.model')
    prefix = utils.legal_file_name(device_name)

    mp4 = '{prefix}-{now}.mp4'.format(prefix=prefix, now=__get_now())
    show_msg('正在录屏,倒计时{}s。录屏文件名:'.format(second) + mp4)

    # s = 'cd {outdir} && \\'
    s = '{adb} -s {serial} shell screenrecord --time-limit {second} /sdcard/{mp4} && \\'
    s += '{adb} -s {serial} pull /sdcard/{mp4} {outdir} && \\'
    s += '{adb} -s {serial} shell rm /sdcard/{mp4}'
    s = utils.fix_cmd_wrap(s)
    final_mp4 = setting_atool.output_dir + os.sep + mp4
    s = s.format(adb=adb_path,
                 outdir=final_mp4,
                 serial=_serial,
                 mp4=mp4,
                 second=second)
    print(no_xuhangfu(s))
    utils.pipe(s)
    if setting_atool.need_auto_open() == '1':
        utils.open_file(final_mp4)
    show_msg("已录屏 " + mp4)

    setting_atool.last_screen_shot = final_mp4
    print('已录屏 ' + mp4)
Ejemplo n.º 18
0
def send_input_clipper_set(_serial, text):
    # https://github.com/majido/clipper/releases
    # 检查clipper
    check_clipper(_serial)
    package = 'ca.zgrs.clipper'
    # 启动 clipper
    s = '{adb} -s {serial} shell monkey -p {package} -c android.intent.category.LAUNCHER 1 && \\'
    # 发送文本
    s += '{adb} -s {serial} shell am broadcast -a clipper.set -e text "{text}" && \\'
    # 退出 clipper
    s += '{adb} -s {serial} shell am force-stop {package}'
    s = utils.fix_cmd_wrap(s)
    s = s.format(adb=adb_path, serial=_serial, text=text, package=package)
    print(s)
    return utils.pipe(s)
Ejemplo n.º 19
0
def most_frequest_words(db, pypipeline=None):
    """
    Most frequent words in messages
    :param db:
    :param pypipeline: optional filter functions
    :return: ChartData
    """
    def limit(n):
        def inner(data):
            return data[:n]

        return inner

    def filter_short_word(n):
        def inner(data):
            return filter(lambda x: len(x.get('_id')) > n, data)

        return inner

    pypipeline = pypipeline or [filter_short_word(3), limit(10)]
    pipeline = [
        # {"$unwind": "$user"},
        {
            "$project": {
                "word": {
                    "$split": ["$message", " "]
                }
            }
        },
        {
            "$unwind": "$word"
        },
        {
            "$group": {
                "_id": "$word",
                "count": {
                    "$sum": 1
                }
            }
        },
        {
            "$sort": SON([("count", -1)])
        }
    ]

    data = pipe(list(db.messages.aggregate(pipeline)), pypipeline)
    return ChartData(map(operator.itemgetter('_id'), data),
                     map(operator.itemgetter('count'), data))
Ejemplo n.º 20
0
def examine(data, column):
    n = len(data)
    n_null = sum(data[column].isnull())
    n_unique = data[column].nunique()
    return \
        { "column": column
        , "n": n
        , "pct_nan": n_null / n
        , "n_unique": n_unique
        , "table":
            pipe( Counter(data[column]) if n_unique < 50 else Counter([])
                , histogram
                , lambda xs: xs[::-1]
                , dict
                )
        }
Ejemplo n.º 21
0
def execute_aapt(command_str):
    """执行 appt 命令
    """
    mark = 'aapt'
    if not command_str.startswith(mark + ' '):
        print('aapt命令行调用错误!\n' + command_str)
        return ''
    result = ''
    s = command_str.replace(mark, aapt_path, 1)
    if utils.is_mac:
        # 设置aapt为可执行
        if os.access(aapt_path, os.X_OK) is not True:
            os.chmod(aapt_path, stat.S_IRWXU)
        result = utils.execute(s)
    if utils.is_windows:
        result = utils.pipe(s, True)
        result = result.replace('\r\n', '\n')
    return result
Ejemplo n.º 22
0
def execute(cmd_str, has_adb_path=False):
    """执行 adb 或 appt 命令
    例如:adb device_list
    """
    result = ''
    if not has_adb_path:
        mark = 'adb'
        if not has_adb_path and not cmd_str.startswith(mark + ' '):
            print('adb命令行调用错误!\n' + cmd_str)
            return ''
        p_str = cmd_str.replace(mark, adb_path, 1)
    else:
        p_str = cmd_str

    if utils.is_mac:
        # 设置aapt为可执行
        if os.access(adb_path, os.X_OK) is not True:
            os.chmod(adb_path, stat.S_IRWXU)
        result = utils.execute(p_str)
    if utils.is_windows:
        result = utils.pipe(p_str, True)
        # result = result.replace('\r\n', '\n')
        result = utils.fix_wrap(result)
    return result
Ejemplo n.º 23
0
        lines: object that returns lines in a file
    Returns
        line matching pattern
    '''
    patc = re.compile(pat)
    for line in lines:
        if patc.match(line.strip()):
            yield line.strip()


def lines_fromfiles(top):
    '''
    Generate lines from files
    Parameter
        top: path to top of directory tree
    Returns
        generator for lines in files
    '''
    return pipe((gen_filelist, ), (gen_open, ), (gen_cat, ))(top)


if __name__ == '__main__':
    PATH_BASE = ''.join([
        '/Users/dpmlto1/Documents/Patent/Thomson Innovation/',
        'clustering/data/uspto-full-text'
    ])
    lines = pipe((lines_fromfiles, ), (gen_grep, r'^[A-Z\s]+$'))(PATH_BASE)
    capset = set([line for line in lines])
    for member in capset:
        print(member)
Ejemplo n.º 24
0
def get_from_server():
	# ws = create_connection("ws://*****:*****@sockets.route('/gesture')
def echo_socket(ws):

	web_socket = ws

	while True:
		continue

if __name__ == '__main__':
	server = multiprocessing.Process(target=get_from_server)
	server.start()
	# connect_to_server()
	app.run()
Ejemplo n.º 25
0
 def f(column):
     return pipe(column, lambda column: examine(data, column))
Ejemplo n.º 26
0
    n = len(data)
    n_null = sum(data[column].isnull())
    n_unique = data[column].nunique()
    return \
        { "column": column
        , "n": n
        , "pct_nan": n_null / n
        , "n_unique": n_unique
        , "table":
            pipe( Counter(data[column]) if n_unique < 50 else Counter([])
                , histogram
                , lambda xs: xs[::-1]
                , dict
                )
        }


def pipeline(data):
    def f(column):
        return pipe(column, lambda column: examine(data, column))

    return f


if __name__ == "__main__":
    data = \
        pipe( load_csv()
            , rename_columns
            )
    pipe(map(pipeline(data), data.columns), list, dumps, print)
Ejemplo n.º 27
0
def sampleStrat(strats, strat):
    def filterStrat(x): return x[1] == strat
    def filterStrats(xs): return filter(filterStrat, xs)
    sampleIt = pipe(enumerate, filterStrats, mapNth(0), list, maybeChoice)
    return sampleIt(strats)
Ejemplo n.º 28
0
from utils import flatten, pipe
import numpy as np
# get first degree neighbors of the nodes ids


flattenUnique = pipe(flatten, set, list)


def getNeighbors(graph, ids):
    return flattenUnique([graph.get_all_neighbors(id) for id in ids])
# get a list of for the nth degree neighbors between 0 and n


def getNthNeighbors(graph, id, n):
    nthNeighbors = [[id]] + [[] for i in range(n)]
    for i in range(n):
        nthNeighbors[i+1] = getNeighbors(graph, nthNeighbors[i])
    return nthNeighbors

# Ego Sampling

# %%


def maybeChoice(eligible): return None if not eligible else (
    np.random.choice(eligible))


def mapNth(n): return lambda xs: map(lambda x: x[n], xs)

Ejemplo n.º 29
0
            axs[x, y].set_title("\n".join([key, str(value)]), fontsize=9)
        else:
            axs[x, y].set_axis_off()

    plt.tight_layout()
    plt.savefig("pngs/{}_geoplot.png".format(column))
    plt.close()


if __name__ == "__main__":
    geojson = "data/borough_boundaries.geojson"
    geodata = read_file(geojson)
    data = \
        pipe( load_csv()
            , rename_columns
            , string_to_date("summons_date")
            , df_to_gdf
            )
    columns = \
        [ "summons_date"
        , "offense_description"
        , "law_section_number"
        , "law_description"
        , "summons_category_type"
        , "age_group"
        , "sex"
        , "race"
        , "jurisdiction_code"
        , "borough"
        , "precinct_of_occurrence"
        ]
Ejemplo n.º 30
0
def install(_serial, _apk_file, action_type=0):
    """安装 apk 到对应设备
    action_type=2 测试应用
    """
    if action_type == 2:
        # s = 'adb -s {serial} install -t -r "{apk}"'.format(serial=_serial, apk=_apk_file)
        # result = execute(s)
        s = '{adb} -s {serial} push "{apk}" /data/local/tmp/{a_apk} && \\'
        s += '{adb} -s {serial} shell pm install -t -r /data/local/tmp/{a_apk}'
        s = utils.fix_cmd_wrap(s)
        a_apk = 'apk-{now}.apk'.format(now=__get_now())
        s = s.format(adb=adb_path, serial=_serial, apk=_apk_file, a_apk=a_apk)
        print(no_xuhangfu(s))
        result = utils.pipe(s, True)

    else:
        # s = 'adb -s {serial} install -t -r "{apk}"'.format(serial=_serial, apk=_apk_file)
        # result = execute(s)
        s = '{adb} -s {serial} push "{apk}" /data/local/tmp/{a_apk} && \\'
        s += '{adb} -s {serial} shell pm install -r /data/local/tmp/{a_apk}'
        s = utils.fix_cmd_wrap(s)
        a_apk = 'apk-{now}.apk'.format(now=__get_now())
        s = s.format(adb=adb_path, serial=_serial, apk=_apk_file, a_apk=a_apk)
        print(no_xuhangfu(s))
        result = utils.pipe(s, True)

    result_lower = result.lower()

    if result_lower.count('success'):
        paa = get_package_and_activity(_apk_file)
        am_start_activity(_serial, paa)
        dc = get_apk_info(_apk_file)
        app_name = dc['app_name']
        show_msg("《{0}》安装成功!正在启动:{1}".format(app_name, paa))

    else:
        r_str = "安装受限,请在设备上开启“允许 usb 安装“\n 魅族:打开手机管家--点击权限管理--点击USB安装管理--关闭USB安装管理"
        # 错误代码, 错误描述, 操作类型
        # 操作类型
        #   0   仅提示
        #   1   需要重新安装
        #   2   testonly
        # ('[INSTALL_PARSE_FAILED_NO_CERTIFICATES]', '签名冲突', 1),
        _arr = [('[INSTALL_FAILED_VERSION_DOWNGRADE]', '已存在更高版', 1),
                ('INSTALL_FAILED_ALREADY_EXISTS]', '程序已经存在', 1),
                ('INSTALL_FAILED_DUPLICATE_PACKAGE]', '已存在同名程序', 1),
                ('INSTALL_FAILED_UPDATE_INCOMPATIBLE]', '版本不能共存', 1),
                ('INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES', '签名不一致', 1),
                ('failed to copy', "apk路径中含有中文", 2),
                ('[INSTALL_FAILED_TEST_ONLY]', '测试apk', 2),
                ('[INSTALL_FAILED_USER_RESTRICTED]', r_str, 0),
                ('INSTALL_FAILED_INVALID_APK]', '无效的APK', 0),
                ('INSTALL_FAILED_INVALID_URI]', '无效的链接', 0),
                ('INSTALL_FAILED_INSUFFICIENT_STORAGE]', '没有足够的存储空间', 0),
                ('INSTALL_FAILED_NO_SHARED_USER]', '要求的共享用户不存在', 0),
                ('INSTALL_FAILED_SHARED_USER_INCOMPATIBLE]', '需求的共享用户签名错误', 0),
                ('INSTALL_FAILED_MISSING_SHARED_LIBRARY]', '需求的共享库已丢失', 0),
                ('INSTALL_FAILED_REPLACE_COULDNT_DELETE]', '需求的共享库无效', 0),
                ('INSTALL_FAILED_DEXOPT]', 'DEX优化验证失败', 0),
                ('INSTALL_FAILED_OLDER_SDK]', '系统版本过旧', 0),
                ('INSTALL_FAILED_NEWER_SDK]', '系统版本过新', 0),
                ('INSTALL_FAILED_CONFLICTING_PROVIDER]', '存在同名的内容提供者', 0),
                ('INSTALL_FAILED_CPU_ABI_INCOMPATIBLE]', '包含的本机代码不兼容', 0),
                ('CPU_ABIINSTALL_FAILED_MISSING_FEATURE]', '使用了一个无效的特性', 0),
                ('INSTALL_FAILED_CONTAINER_ERROR]', 'SD卡访问失败', 0),
                ('INSTALL_FAILED_MEDIA_UNAVAILABLE]', 'SD卡不存在', 0),
                ('INSTALL_FAILED_INVALID_INSTALL_LOCATION]', '无效的安装路径', 0),
                ('INSTALL_FAILED_INTERNAL_ERROR]', '系统问题导致安装失败', 0),
                ('INSTALL_PARSE_FAILED_NO_CERTIFICATES', 'apk签名问题', 0),
                ('DEFAULT]', '未知错误', 0)]
        index = -1
        count = 0
        for item in _arr:
            code = item[0].lower()
            if result_lower.count(code):
                index = count
                break
            else:
                count += 1
        if index != -1:
            f_err = _arr[index][0]
            f_dec = _arr[index][1]
            f_ext = _arr[index][2]
            if f_ext == 1:
                params = [_serial, _apk_file]
                s = "{0},是否卸载并重新安装!\n错误代码:{1}".format(f_dec, f_err)
                utils.alert(s, reinstall, params)
            elif f_ext == 2:
                params = [_serial, _apk_file, 2]
                s = "{0},是否坚持安装!\n提示代码:{1}\n注意:本apk不能提交给市场审核!"
                s = s.format(f_dec, f_err)
                utils.alert(s, install, params)
            elif f_ext == 100:
                params = [_serial, _apk_file, 100]
                s = "{0},是否尝试另一种安装方法!"
                s = s.format(f_dec, f_err)
                utils.alert(s, install, params)
            else:
                s = "安装失败{0}\n错误代码:{1}".format(f_dec, f_err)
                utils.showinfo(s)
        else:
            s = "安装失败\n" + result[-200:]
            utils.showinfo(s)
Ejemplo n.º 31
0
def log_clear(_serial):
    s = '{adb} -s {serial} logcat -c'.format(adb=adb_path, serial=_serial)
    utils.pipe(s, True)