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

    try:
        iresult = IResult()

        excelPath = json.loads(param)["target"]["excelPath"]
        sheetName = json.loads(param)["target"]["sheet"]
        data = json.loads(param)["target"]["cell"].upper()

        app = xw.App(visible=False, add_book=False)
        wb = app.books.open(excelPath)
        sht = wb.sheets[sheetName]
        cellValue = sht.range(data).value
        iresult.obj = cellValue
        wb.save()
        wb.close()

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

    iresult = IResult()
    msg = cli_pack_au3(img_res_path, param, 2,1)
    try:
        tmp_au3_file_path = gen_au3(img_res_path, msg)

        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_dbclick]")
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 do_win_title_list():
    __logger.echo_msg(u"Ready to execute[win_title_list]")

    iresult = IResult()
    iresult.status = 0

    try:
        dicResult = ubpa.base_cs_dll.getWinList()
        stringRst = dicResult["winlist"]
        if stringRst == "":  # 表示没有得到窗口标题列表

            for le in range(0, __try_times):

                dicResult = ubpa.base_cs_dll.getWinList()
                stringRst = dicResult["winlist"]
                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))

        iresult.obj = dicResult["winlist"]
        iresult.echo_result()
        return iresult
    except Exception as e:
        raise e
    finally:
        __logger.echo_msg(u"end execute[win_title_list]")
Example #5
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 #6
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 #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]")
Example #8
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 #9
0
def do_cs_select(win_title="", win_text="", target=None, select_sring=""):
    __logger.info(u"Afferent parameter:select_sring:" + str(select_sring))
    __logger.echo_msg(u"Ready to execute[do_cs_select]")

    iresult = IResult()
    iresult.status = 0

    try:
        dicResult = ubpa.base_cs_dll.dllControlCommand(win_title, win_text,
                                                       target, select_sring)
        stringRst = dicResult["control_command"]
        if stringRst != 1:

            for le in range(0, __try_times):

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

                dicResult = ubpa.base_cs_dll.dllControlCommand(
                    win_title, win_text, target, select_sring)
                stringRst = dicResult["control_command"]
                if stringRst == 1:
                    __logger.info(str((le + 1)) + "times,try success")
                    break

                time.sleep(1)

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

        iresult.obj = dicResult["control_command"]
        iresult.echo_result()
        return iresult
    except Exception as e:
        raise e
    finally:
        __logger.echo_msg(u"end execute[do_cs_select]")
Example #10
0
def do_win_activate(win_title="", win_text=None):
    __logger.info(u"Afferent parameter:win_title:" + str(win_title))
    __logger.echo_msg(u"Ready to execute[win_activate_cs]")

    iresult = IResult()
    iresult.status = 0

    try:
        dicResult = ubpa.base_cs_dll.dllWinActivate(win_title, win_text)
        stringRst = dicResult["win_activate"]
        if stringRst != 1:

            for le in range(0, __try_times):

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

                dicResult = ubpa.base_cs_dll.dllWinActivate(
                    win_title, win_text)
                stringRst = dicResult["win_activate"]
                if stringRst == 1:
                    __logger.info(str((le + 1)) + "times,try success")
                    break

                time.sleep(1)

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

        iresult.obj = dicResult["win_activate"]
        iresult.echo_result()
        return iresult
    except Exception as e:
        raise e
    finally:
        __logger.echo_msg(u"end execute[win_activate_cs]")
Example #11
0
def control_set_text_cs(param):
    __logger.info(u"Afferent parameter:" + param)
    __logger.echo_msg(u"Ready to execute[control_set_text_cs]")

    iresult = IResult()
    iresult.status = 0

    try:
        dicResult = ubpa.base_cs_dll.dllsetText(param)
        stringRst = dicResult["setText"]
        if stringRst != 1:  #

            for le in range(0, __try_times):

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

                dicResult = ubpa.base_cs_dll.dllsetText(param)
                stringRst = dicResult["setText"]
                if stringRst == 1:
                    __logger.info(str((le + 1)) + "times,try success")
                    break

                time.sleep(1)

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

        iresult.obj = dicResult["setText"]
        iresult.echo_result()
        return iresult
    except Exception as e:
        raise e
    finally:
        __logger.echo_msg(u"end execute[control_set_text_cs]")
Example #12
0
def run_cs(param):
    __logger.info(u"Afferent parameter:" + param)
    __logger.echo_msg(u"Ready to execute[run_cs]")

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

    try:
        dicResult = ubpa.base_cs_dll.dllRun(param)
        stringRst = dicResult["run"]
        if stringRst == 0:  # 返回pid  为0表示没有运行成功

            for le in range(0, __try_times):

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

                dicResult = ubpa.base_cs_dll.dllRun(param)
                stringRst = dicResult["run"]
                if stringRst != 0:
                    __logger.info(str((le + 1)) + "times,try success")
                    break

                time.sleep(1)

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

        iresult.obj = dicResult["run"]
        iresult.echo_result()
        return iresult
    except Exception as e:
        raise e
    finally:
        __logger.echo_msg(u"end execute[run_cs]")
Example #13
0
def sendMail(param):
    __logger.info(u"Afferent parameter:" + param)
    __logger.echo_msg(u"Ready to execute[sendMail]")

    try:
        iresult = IResult()

        msgRoot = MIMEMultipart()
        target = json.loads(param)["target"]
        host = target.get('host', "")
        port = target.get('port', "")
        username = target.get('username', "")
        password = target.get('password', "")
        sender = target.get('sender', "")
        receiver = target.get('receiver', "")
        cc = target.get('cc', "")

        input = json.loads(param)["input"]
        subject = input.get('subject', "")
        body = input.get('body', "")
        fileDir = input.get('fileDir', "")

        if len(fileDir) > 0:
            fileDirs = fileDir.split(",")
            for s in fileDirs:
                excelFile = open(s, 'rb').read()  #单个附件
                if s.find("/") >= 0:
                    file = s.split("/")
                else:
                    file = s.split("\\")
                fileName = file[len(file) - 1]
                att = MIMEApplication(excelFile)
                att.add_header('Content-Disposition',
                               'attachment',
                               filename=('gb2312', '', fileName))
                msgRoot.attach(att)  # 构造附件

        bodyText = MIMEText(body)

        msgRoot['Subject'] = subject  #构造标题
        msgRoot.attach(bodyText)  #构造正文
        msgRoot['Cc'] = cc  #构造抄送
        msgRoot['From'] = sender
        msgRoot['To'] = receiver

        if cc != "":
            re = receiver.split(',') + cc.split(',')
        else:
            re = receiver.split(',')

        smtp = smtplib.SMTP()
        smtp.connect(host, port)
        smtp.login(username, password)
        smtp.sendmail(sender, re, msgRoot.as_string())
        smtp.quit()

        iresult.status = 0
        iresult.echo_result()
        return iresult
    except Exception as e:
        raise e
    finally:
        __logger.echo_msg(u"end execute[sendMail]")