Esempio n. 1
0
def pipe(cmdargs):
    """
    Execute a process in different way, create a Pipe to do read/write operations with child process.
    See `lib.nonblocking` module.
    """
    dhnio.Dprint(14, "child_process.pipe %s" % str(cmdargs))
    try:
        if dhnio.Windows():
            import win32process
            p = nonblocking.Popen(
                cmdargs,
                shell=False,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=False,
                creationflags = win32process.CREATE_NO_WINDOW,)
        else:
            p = nonblocking.Popen(
                cmdargs,
                shell=False,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=False,)
    except:
        dhnio.Dprint(1, 'child_process.pipe ERROR executing: ' + str(cmdargs) + '\n' + str(dhnio.formatExceptionInfo()))
        return None
    return p
Esempio n. 2
0
def send(filename, email, subject = 'datahaven_transport', reactor_stop=False, use_smtplib=False):
    transport_control.log('email', 'start sending to ' + email)
    smtp_info = [
            settings.getEmailAddress(),   #0
            settings.getSMTPHost(),       #1
            settings.getSMTPPort(),       #2
            settings.getSMTPUser(),       #3
            settings.getSMTPPass(),       #4
            settings.getSMTPSSL(),        #5
            settings.getSMTPNeedLogin()]  #6

    if smtp_info[0].strip() == '' or smtp_info[1].strip() == '':
        dhnio.Dprint(1, 'transport_email.send empty mailbox info. check your email options')
##        transport_control.msg('e', 'empty mailbox info. check your email options')
##        transport_control.connectionStatusCallback('email', email, None, 'empty mailbox info. check your email options')
        transport_control.sendStatusReport(email, filename,
            'failed', 'email',
            None, 'empty mailbox info. check your email options')
        return

##    print smtp_info
##    smtp_info = smtp3_info
    if not os.path.isfile(filename):
        dhnio.Dprint(1, 'transport_email.send wrong file name: %s' % filename)
##        transport_control.msg('e', 'wrong file name %s' % filename)
        return
    from_address = smtp_info[0]
    dhnio.Dprint(8, 'transport_email.send  from:%s to:%s' % (from_address, email))

    if use_smtplib:
        #send via smtplib
        try:
            send_smtplib(
                smtp_info[1],
                smtp_info[3],
                smtp_info[4],
                smtp_info[5],
                from_address,
                email,
                subject,
                filename)
        except:
            dhnio.Dprint(1, 'transport_email.send NETERROR sending email ' + dhnio.formatExceptionInfo())
##            transport_control.msg('e', 'Error sending email')
            transport_control.log('email', 'error sending email')
##            transport_control.connectionStatusCallback('email', email, None, 'error sending email')
            transport_control.sendStatusReport(email, filename,
                'failed', 'email',
                None, 'error sending email')
            return
##        if misc.transport_control_using():
        transport_control.sendStatusReport(email, filename,
            'finished', 'email')  # only one outstanding send per host
        transport_control.log('email', 'done')
        poll().send()
    else:
        #Send via Twisted
        def ok(x):
            dhnio.Dprint(14, 'transport_email.send.ok: sending done')
##            if misc.transport_control_using():
            # only one outstanding send per host
            transport_control.sendStatusReport(email, filename,
                'finished', 'email')
            transport_control.log('email', 'message successful sent')
            poll().send()
            if reactor_stop:
                reactor.stop()
        def fail(x):
##            if misc.transport_control_using():
            dhnio.Dprint(1, 'transport_email.send.fail NETERROR sending email \n' + str(x.getErrorMessage()))
##            transport_control.msg('e', 'error sending email: '  + str(x.getErrorMessage()) )
##            transport_control.connectionStatusCallback('email', smtp_info[0], x, 'error sending email')
            transport_control.sendStatusReport(email, filename,
                'failed', 'email',
                x, 'error sending email')
            transport_control.log('email', 'error sending email'  + str(x.getErrorMessage()))
            if reactor_stop:
                reactor.stop()

        if smtp_info[6]:
            #1th method
            res = sendTwistedMailAuth(
                smtp_info[1],
                smtp_info[2],
                smtp_info[3],
                smtp_info[4],
                smtp_info[5],
                smtp_info[6],
                from_address,
                email,
                subject,
                filename)
        else:
            #2th method:
            res = sendTwistedMail(
                smtp_info[1],
                smtp_info[0],
                email,
                subject,
                filename,
                smtp_info[2])
        res.addCallback(ok)
        res.addErrback(fail)
        return res