Example #1
0
def img_exists(img_res_path, param):
    __logger.info(u"Afferent parameter:" + param)
    __logger.echo_msg(u"Ready to execute[img_exists]")

    iresult = IResult()
    msg = is_exist_pack_au3(img_res_path, param)
    try:
        tmp_au3_file_path = gen_au3(img_res_path, msg)
        status, error_string, stdout_string = run_autoit(tmp_au3_file_path)
        iresult.obj = True
        if status:
            '''程序执行错误'''
            iresult.status = 1
            iresult.err = get_cmd_message(error_string)
            iresult.obj = False
        elif str(get_cmd_message(stdout_string)) == "NO":
            '''autoit 执行返回结果为未找到'''
            iresult.status = 1
            iresult.err = u'image not found'
            iresult.obj = False

        iresult.echo_result()
        return iresult
    except Exception as e:
        raise e
    finally:
        __cleanup(tmp_au3_file_path)
        __logger.echo_msg(u"end execute[img_exists]")
Example #2
0
def img_click(img_res_path, param):
    __logger.info(u"Afferent parameter:" + param)
    __logger.echo_msg(u"Ready to execute[img_click]")

    iresult = IResult()
    msg = cli_pack_au3(img_res_path, param, 1,1)  ##组装生成au3所需的数据
    try:
        tmp_au3_file_path = gen_au3(img_res_path, msg)  # 生成XXX.au3文件并返回路径

        status, error_string, stdout_string = run_autoit(tmp_au3_file_path)

        if status:
            '''程序执行错误'''
            iresult.status = 1
            iresult.err = get_cmd_message(error_string)
            raise Exception(iresult.err)
        elif str(get_cmd_message(stdout_string)) == "NO":
            '''autoit 执行返回结果为未找到'''
            iresult.status = 1
            iresult.err = u'image not found'
            raise Exception(iresult.err)

        iresult.echo_result()
        return iresult
    except Exception as e:
        raise e
    finally:
        __cleanup(tmp_au3_file_path)
        __logger.echo_msg(u"end execute[img_click]")
Example #3
0
def capture_image(win_title = "", win_text = "", in_img_path = "", left_indent = 0, top_indent = 0, width = 0, height = 0):
    __logger.info(u"Afferent parameter:left_indent:" + str(left_indent) + ",top_indent:" + str(top_indent) + ",width:" + str(width) + ",height:" + str(height))
    __logger.echo_msg(u"Ready to execute[capture_image]")

    ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 8))

    if in_img_path == "": # 当没有输入路径的时候
        in_img_path = tempfile.mktemp(prefix='tm_')
        in_img_path = in_img_path + ran_str + ".png"
        in_img_path = in_img_path.replace("\\", "\\\\")
    else:
        in_img_path = in_img_path + ran_str + ".png"

    iresult = IResult()
    right_indent = left_indent + width
    bottom_indent = top_indent + height
    msg = img_capture_pack_au3("'" +in_img_path+ "'",left_indent, top_indent, right_indent, bottom_indent)
    try:
        tmp_au3_file_path = gen_au3_file(msg)
        status, error_string, stdout_string = run_autoit(tmp_au3_file_path)

        iresult.obj = in_img_path
        if status != 0:
            '''程序执行错误'''
            iresult.status = 1
            iresult.err = get_cmd_message(error_string)
            raise Exception(iresult.err)

        iresult.echo_result()
        return iresult
    except Exception as e:
        raise e
    finally:
        __cleanup(tmp_au3_file_path)
        __logger.echo_msg(u"end execute[capture_image]")
Example #4
0
def existsText(param):
    __logger.info(u"Afferent parameter:" + param)
    __logger.echo_msg(u"Ready to execute[existsText]")

    iresult = IResult()
    iresult.status = 0

    try:
        stringText = dll.existsText(param)
        stringRst = check_is_wrong()

        if stringRst != "":

            for le in range(0, __try_times):

                __logger.info(
                    str((le + 1)) + "times," + "Afferent parameter:" + param)

                stringText = dll.existsText(param)
                stringRst = check_is_wrong()
                if stringRst == "":
                    __logger.info(str((le + 1)) + "times,try success")
                    break

                time.sleep(1)

        if stringRst != "":
            iresult.status = 1
            __logger.info(u"Interface returns error information:" +
                          str(stringRst))

        if stringText == 1:
            iresult.obj = True
        if stringText == 0:
            iresult.obj = False
        iresult.err = stringRst
        iresult.echo_result()
        return iresult
    except Exception as e:
        print(e)
    finally:
        __logger.echo_msg(u"end execute[existsText]")
Example #5
0
def send_outlook(receiver=None,
                 cc=None,
                 bcc=None,
                 subject=None,
                 body=None,
                 attachments=None):
    __logger.echo_msg(u"Ready to execute[send_outlook]")
    iresult = IResult()

    try:
        outlook = win32com.client.Dispatch("Outlook.Application")
        mail = outlook.CreateItem(0)

        if receiver != None:
            tos_receiver = receiver.split(";")
            for to in tos_receiver:
                mail.Recipients.Add(to)
        if cc != None:
            mail.CC = cc
        if bcc != None:
            mail.BCC = bcc
        if subject != None:
            mail.Subject = subject
        if body != None:
            mail.Body = body
        if attachments != None:
            attachment_list = attachments.split(",")
            for att in attachment_list:
                mail.Attachments.Add(att, 1, 1, '我的文件')

        mail.Send()
        iresult.obj = True
    except BaseException as ex:
        iresult.status = 1
        iresult.err = u"Program execution error" + str(ex)
        __logger.error(u"Program execution error" + str(ex))
        iresult.obj = False
    finally:
        __logger.echo_msg(u"end execute[send_outlook]")
        iresult.echo_result()
        return iresult
Example #6
0
def doSelect(param):
    __logger.info(u"Afferent parameter:" + param)
    __logger.echo_msg(u"Ready to execute[doSelect]")

    iresult = IResult()
    iresult.status = 0

    try:
        stringText = dll.doSelect(param)
        stringRst = check_is_wrong()

        if stringRst != "":

            for le in range(0, __try_times):

                __logger.info(
                    str((le + 1)) + "times," + "Afferent parameter:" + param)

                stringText = dll.doSelect(param)
                stringRst = check_is_wrong()
                if stringRst == "":
                    __logger.info(str((le + 1)) + "times,try success")
                    break

                time.sleep(1)

        if stringRst != "":
            __logger.info(u"Interface returns error information:" +
                          str(stringRst))
            raise Exception(u"Interface returns error information:" +
                            str(stringRst))

        iresult.obj = stringText
        iresult.err = stringRst
        iresult.echo_result()
        return iresult
    except Exception as e:
        raise e
    finally:
        __logger.echo_msg(u"end execute[doSelect]")
Example #7
0
def getHtml(param):
    __logger.info(u"Afferent parameter:" + param)
    __logger.echo_msg(u"Ready to execute[getHtml]")

    iresult = IResult()  # new一个返回结果的新对象
    iresult.status = 0  # status初始赋值   status =0 成功  1 表示失败

    try:
        stringText = get_html(param)  #取得getHtml方法返回值
        stringRst = check_is_wrong()  #判断getHtml方法是否成功

        if stringRst != "":  #表示报错了

            for le in range(0, __try_times):
                __logger.info(
                    str((le + 1)) + "times," + "Afferent parameter:" + param)

                stringText = get_html(param)
                stringRst = check_is_wrong()
                if stringRst == "":
                    __logger.info(str((le + 1)) + "times,try success")
                    break

                time.sleep(1)

        if stringRst != "":
            iresult.status = 1
            __logger.info(u"Interface returns error information:" +
                          str(stringRst))

        iresult.obj = stringText
        iresult.err = stringRst
        iresult.echo_result()
        return iresult
    except Exception as e:
        print(e)
    finally:
        __logger.echo_msg(u"end execute[getHtml]")