Ejemplo n.º 1
0
def control_send_cs(win_title=None, text=None, waitfor=WAIT_FOR):
    '''
    :param win_title: 窗口标题
    :param text: 设置参数
    :param waitfor:  等待时间
    :return:
    '''
    __logger.debug('str control send:[win:' + str(win_title) + ']' + str(text))
    starttime = time.time()
    try:
        while True:
            ''''如果指定窗口'''
            if (win_title != None):
                ''''如果窗口不活跃状态'''
                if not iwin.do_win_is_active(win_title):
                    iwin.do_win_activate(win_title=win_title, waitfor=waitfor)

            text = encrypt.decrypt(text)
            result = str_dll.setElementValue(text)
            err = string_at(str_dll.getLastError(), -1).decode('utf-8')
            if err == "":
                return result
            else:
                runtime = time.time() - starttime
                if runtime >= waitfor:
                    __logger.debug(r'timeout ' + err)
                    raise ExcuteError('control send error:[' + win_title + ']')
                __logger.debug(r'try fail ,wait next' + err)
                time.sleep(TRY_INTERVAL)
    except Exception as e:
        raise e
Ejemplo n.º 2
0
def control_set_text_cs(win_title=None,
                        win_text="",
                        control=None,
                        text=None,
                        waitfor=WAIT_FOR):
    __logger.debug('Set text control:[' + str(win_title) + '][' +
                   str(control) + ']')
    try:
        starttime = time.time()
        while True:
            text = encrypt.decrypt(str(text))
            rst = _control_set_text_cs(win_title, win_text, control,
                                       text)  # 返回1,0,或者报错
            if rst == 1:
                return rst
            else:
                runtime = time.time() - starttime
                if runtime >= waitfor:
                    __logger.debug('Operation timeout')
                    raise Au3ExecError('Set text error:[' + str(win_title) +
                                       '][' + str(control) + ']')
                __logger.debug('Set text control error:[' + str(win_title) +
                               '][' + str(control) + ']')
                time.sleep(TRY_INTERVAL)
    except Exception as e:
        raise e
Ejemplo n.º 3
0
def do_keypress(win_title="",title="",url="",selector="",text="",waitfor=WAIT_FOR):
    __logger.debug('do_keypress:[' + str(title) + '][' + str(selector) + '][' + str(text) + ']')
    try:
        ''''如果指定窗口'''
        if win_title != None and win_title.strip() != '':
            ''''如果窗口不活跃状态'''
            if not iwin.do_win_is_active(win_title):
                iwin.do_win_activate(win_title=win_title, waitfor=waitfor)
                
                
        text = encrypt.decrypt(text)
        param = get_param(title, url,selector,text)
        starttime = time.time()
        while True:
            dll.doKeypress(param)
            err = string_at(dll.getLastError(), -1).decode('utf-8')
            if err == "":
                return True
            else:
                runtime = time.time() - starttime
                if runtime >= waitfor:
                    __logger.debug(r'Operation timeout ' + err)
                    raise Exception(err)
                __logger.debug(r'Attempt Failure - Wait for Attempt to Acquire ' + err)
                time.sleep(TRY_INTERVAL)
    except Exception as e:
        raise e
Ejemplo n.º 4
0
def set_element_val(program=None,
                    title=None,
                    className=None,
                    selector=None,
                    text=None,
                    waitfor=WAIT_FOR):

    __logger.debug('[set_element_val] Set text start')
    try:
        text = encrypt.decrypt(str(text))
        param = get_jsondata(program, title, className, selector, text=text)
        starttime = time.time()
        while True:
            return_data = dll.setElementValue(param)
            return_data = reverse_data(return_data)

            retCode = return_data["retCode"]
            retError = return_data["retError"]

            if retCode == 1:
                return True
            else:
                runtime = time.time() - starttime
                if runtime >= waitfor:
                    __logger.debug(r'Operation timeout ' + retError)
                    raise Exception(retError)
                __logger.debug(r'Attempt Failure - Wait for Attempt ' +
                               retError)
                time.sleep(TRY_INTERVAL)
    except Exception as e:
        raise e
Ejemplo n.º 5
0
def unlock_screen(uname,
                  upass,
                  try_times=3,
                  esc_wait_time=2000,
                  next_wait_time=2000):
    ldll = windll.LoadLibrary("../Com.Isearch.Driver.WinIO/RpaAutoLogin.dll")
    upass = encrypt.decrypt(upass)
    #     ldll = windll.LoadLibrary(r"D:\svn\isa\branches\ueba_5.0\makesetup\CdaSetupDate\plugin\Com.Isearch.Driver.WinIO\RpaAutoLogin.dll")
    result = ldll.do_autologin(uname, upass, try_times, esc_wait_time,
                               next_wait_time)
    return result
Ejemplo n.º 6
0
def key_send_cs(win_title=None, text=None, waitfor=WAIT_FOR):
    __logger.debug('keyboard send key:[win:' + str(win_title) + ']' +
                   str(text))
    try:
        ''''如果指定窗口'''
        if (win_title != None):
            ''''如果窗口不活跃状态'''
            if not iwin.do_win_is_active(win_title):
                iwin.do_win_activate(win_title=win_title, waitfor=waitfor)
        text = encrypt.decrypt(text)
        dll.AU3_Send(str(text), 0)
    except Exception as e:
        raise e
Ejemplo n.º 7
0
def send_smtp_mail(server=None,port=25,psw=None,sender=None,receivers=None,cc=None,bcc=None,subject=None,body=None,attachments=None,ssl='no'):
    '''
SMTP发送邮件
    server:smtp服务器  port:端口号   psw:登陆密码  sender:发送方  receivers:接收者
    cc:抄送  bcc:密抄  subject:标题  body:邮件正文  attachments:附件路径

'''
    __logger.debug('smtp Send mail:[' + str(server) + '][' + str(port) + ']')
    re = []
    try:
        msgRoot = MIMEMultipart()
        #msgRoot['Subject'] = subject   构造标题
        msgRoot['Subject'] = Header(subject, 'utf-8').encode()
        msgRoot['Cc'] = "".join(str(cc))
        msgRoot['Bcc'] = "".join(str(bcc))
        msgRoot['From'] = formataddr(["", sender])
        msgRoot['To'] = formataddr(["", receivers])
        msgRoot.attach(MIMEText(body, 'plain', 'utf-8'))

        if attachments != None:
            for attachment in attachments.split(','):
                rst= os.path.exists(attachment)
                if rst :
                        excelFile = open(attachment, 'rb').read()
                        fileName = os.path.basename(os.path.realpath(attachment))
                        att = MIMEApplication(excelFile)
                        att.add_header('Content-Disposition', 'attachment', fileName=('gbk', '', fileName))
                        msgRoot.attach(att)
                else:
                    __logger.debug(u'Attachment path does not exist')


        if receivers != None and receivers != '':
            re = receivers.split(',')
        if cc != None and cc != '':
            re = re + str(cc).split(',')
        if bcc !=None and bcc != '':
            re = re + str(bcc).split(',')

        smtp = smtplib.SMTP()
        if ssl=='yes':
            smtp = smtplib.SMTP_SSL()
        smtp.connect(server,port)
        psw = encrypt.decrypt(psw)
        smtp.login(sender, psw)
        smtp.sendmail(sender,re, msgRoot.as_string())
        smtp.quit() 
    except Exception as e:
        raise e
    finally:
        __logger.echo_msg(u"end execute[sendMail]")
Ejemplo n.º 8
0
def set_text(win_title=None,
             id=None,
             text=None,
             waitfor=WAIT_FOR,
             run_mode='noctrl'):
    """sap 设置文本"""
    try:
        __logger.debug('sap set text :' + str(id))
        if (win_title != None):
            if not iwin.do_win_is_active(win_title):
                iwin.do_win_activate(win_title=win_title, waitfor=waitfor)
        element = get_element(id, waitfor)
        text = encrypt.decrypt(str(text))
        element.text = text
    except Exception as e:
        raise e
Ejemplo n.º 9
0
def set_text(win_class=None,
             win_name=None,
             selector=None,
             text=None,
             waitfor=WAIT_FOR):
    try:
        text = encrypt.decrypt(text)
        automation.SetGlobalSearchTimeOut(waitfor)
        if win_name != None:
            iwin.do_win_activate(win_title=win_name, waitfor=waitfor)

        ctrl = get_control(win_class, win_name, selector)

        ctrl = automation.Control.CreateControlFromControl(ctrl)
        ctrl.SetValue(text)
    except Exception as e:
        raise e
Ejemplo n.º 10
0
def get_ydm_code(filename, codetype=5001, timeout=30):
    '''
    '''
    #     YDMApi = windll.LoadLibrary(r'd:\svn\isa\branches\ueba_5.0\makesetup\CdaSetupDate\bin\yundamaAPI.dll')
    YDMApi = windll.LoadLibrary("../../bin/yundamaAPI.dll")
    result = c_char_p(b"                              ")
    username = b"isearch"
    password = "******"
    password = encrypt.decrypt(password)
    password = bytes(password, encoding='utf-8')
    appId = 5364
    appKey = b"54b9ebb03b894bad4f52e4f3553edffb"
    #     filename = b"C:\Users\ibm\Desktop\dynamicPassword.jpg"
    filename = filename.encode(encoding="utf-8")
    captchaId = YDMApi.YDM_EasyDecodeByPath(username, password, appId, appKey,
                                            filename, codetype, timeout,
                                            result)

    __logger.debug("recognize:ID:%d,result:%s" % (captchaId, result.value))
    return str(result.value, encoding="utf-8")
Ejemplo n.º 11
0
def set_text(title="",url="",selector="",text="",waitfor=WAIT_FOR):
    __logger.debug('IE set text:['+str(title)+']['+str(selector)+']['+str(text)+']')
    try:
        text = encrypt.decrypt(text)
        param = get_param(title,url,selector,text)
        starttime = time.time()
        while True:
            dll.setText(param)
            err = string_at(dll.getLastError(), -1).decode('utf-8')  
            if err  == "": 
                return True
            else:
                runtime = time.time() - starttime
                if runtime >= waitfor:
                    __logger.debug(r'Operation timeout ' + err)
                    raise Exception(err)
                __logger.debug(r'Attempt Failure - Wait for Attempt to Acquire ' + err)
                time.sleep(TRY_INTERVAL)
    except Exception as e:
        raise e 
Ejemplo n.º 12
0
def bd_get_client():
    return AipOcr(encrypt.decrypt(APP_ID), encrypt.decrypt(API_KEY),
                  encrypt.decrypt(SECRET_KEY))
Ejemplo n.º 13
0
def unlock_screen_remote(uname='',
                         domain='',
                         upass='',
                         addr='',
                         port=3389,
                         try_interval=2,
                         waitfor=60):
    try:
        screen_dll = windll.LoadLibrary(
            "../Com.Isearch.Func.ScreenLock/ScreenLockCheck.dll")
        char_name = screen_dll.GetCurrentUsername()  # 调用dll 获取 uname
        uname = string_at(char_name, -1).decode('utf-8')
        screen_dll.FreePointer(char_name)

        char_domain = screen_dll.GetCurrentDomain()
        domain = string_at(char_domain, -1).decode('utf-8')  # 调用dll 获取 domain
        screen_dll.FreePointer(char_domain)

        rpasever = RpaServer()
        agentUUID = rpasever.AgentUUID
        mainServer = rpasever.MainServer
        webServicePort = rpasever.WebServicePort

        starttime = time.time()
        has_send_http_flag = False
        while True:
            screen_status = is_screen_locked()
            if screen_status == 0:
                __logger.debug('The screen is now unlocked')
                return True
            else:
                if has_send_http_flag == False:  # 未成功发送过http请求
                    upass = encrypt.decrypt(upass)
                    data = {
                        "msg_type": "rpa",
                        "a": "conn_desk",
                        "agent_no": agentUUID,
                        "user_name": uname,
                        "user_pass": upass,
                        "addr": addr,
                        "port": str(port),
                        "scale": "100",
                        "resolution": "widthXheight",
                        "timeout": "60",
                        "user_domain": domain
                    }
                    http_url = 'http://' + str(mainServer) + ":" + str(
                        webServicePort) + '/wservice.action'
                    whole_request_url = http_url + '?jsonStr=' + str(data)
                    res = requests.get(whole_request_url)
                    dict = json.loads(str(res.text))
                    status = dict['status']
                    if status == '0':
                        has_send_http_flag = True
                        __logger.debug('Has sent a screen request')
                else:  # 成功发送过http请求
                    runtime = time.time() - starttime
                    if runtime >= waitfor:
                        __logger.debug('Operation timeout')
                        raise Exception
                time.sleep(try_interval)
    except Exception as e:
        raise e