Ejemplo n.º 1
0
def sendfax(config, user, capi, faxfile,
            outgoing_num, dialstring, stationID=None, headline=None):
    """
    Send a fax out via the capi.

    Returns a tuple ((result, resultB3), faxinfo)
    """
    import capisuite.core as core

    controller = config.getint('GLOBAL', "send_controller")
    timeout = int(config.getUser(user, "outgoing_timeout"))

    # get defaults for stationID and headline from config
    if not stationID:
        stationID = config.getUser(user, "fax_stationID")
    if not stationID:
        core.error("Warning: fax_stationID for user %s not set" %user)
    if not headline:
        headline = config.getUser(user, "fax_headline")

    try:
        call, result = capi.call_faxG3(controller, outgoing_num,
                                       dialstring, timeout,
                                       stationID, headline)
        core.log('result from capi.call_faxG3: %s' % result, 2)
        if result:
            # an errror occured
            return (result, 0), None
        faxinfo = call.fax_send(faxfile)
        return call.disconnect(), faxinfo
    except core.CallGoneError:
        return call.disconnect(), None
Ejemplo n.º 2
0
def sendfax(config,
            user,
            capi,
            faxfile,
            outgoing_num,
            dialstring,
            stationID=None,
            headline=None):
    """
    Send a fax out via the capi.

    Returns a tuple ((result, resultB3), faxinfo)
    """
    import capisuite.core as core

    controller = config.getint('GLOBAL', "send_controller")
    timeout = int(config.getUser(user, "outgoing_timeout"))

    # get defaults for stationID and headline from config
    if not stationID:
        stationID = config.getUser(user, "fax_stationID")
    if not stationID:
        core.error("Warning: fax_stationID for user %s not set" % user)
    if not headline:
        headline = config.getUser(user, "fax_headline")

    try:
        call, result = capi.call_faxG3(controller, outgoing_num, dialstring,
                                       timeout, stationID, headline)
        core.log('result from capi.call_faxG3: %s' % result, 2)
        if result:
            # an errror occured
            return (result, 0), None
        faxinfo = call.fax_send(faxfile)
        return call.disconnect(), faxinfo
    except core.CallGoneError:
        return call.disconnect(), None
Ejemplo n.º 3
0
        raise ValueError, "missing lock name"
    lockfile = open(name, "w")
    try:
        if blocking:
            fcntl.lockf(lockfile, fcntl.LOCK_EX)
        else:
            fcntl.lockf(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
    except IOError, err: # can't get the lock
        if err.errno in (errno.EACCES, errno.EAGAIN):
            lockfile.close()
            raise LockTakenError
        else:
            raise
    # currently log is only available if running within capisuite
    if hasattr(core, 'log'):
        core.log("lock taken %s" % name, 3)
    return (name, lockfile)


def _releaseLock((lockname, lockfile)):
    fcntl.lockf(lockfile, fcntl.LOCK_UN)
    lockfile.close()
    try:
        os.unlink(lockname)
    except OSError, err:
        # as we don't hold the lock any more, the other thread can be quicker
        # in deleting than we; this doesn't harm, so ignore it
        if (err.errno!=2): 
            raise
    # currently log is only available if running within capisuite
    if hasattr(core, 'log'):
Ejemplo n.º 4
0
        return

    # search in all user-specified sendq's
    for user in config.listUsers():
        outgoing_num = config.getUser(user, "outgoing_msn")
        if not outgoing_num:
            incoming_nums = config.getUser(user, "fax_numbers")
            if not incoming_nums:
                continue
            outgoing_num = incoming_nums.split(',')[0].strip()

        mailaddress = config.getUser(user, "fax_email", user)
        fromaddress = config.getUser(user, "fax_email_from", user)

        for jobnum, controlfile in capisuite.fax.getQueueFiles(config, user):
            core.log("checking job %s %s" % (jobnum, controlfile), 3)
            assert controlfile == os.path.abspath(controlfile)
            try:
                # lock the job so that it isn't deleted while sending
                lock = _getLock('dummy', forfile=controlfile, blocking=0)
            except LockTakenError:
                # if we didn't get the lock, continue with next job
                continue
            try:
                control = capisuite.config.JobDescription(controlfile)

                fax_file = control.get('filename')
                assert fax_file == os.path.abspath(fax_file)

                # both the job control file and the fax file must have
                # the users uid
Ejemplo n.º 5
0
        return

    # search in all user-specified sendq's
    for user in config.listUsers():
        outgoing_num = config.getUser(user, "outgoing_msn")
        if not outgoing_num:
            incoming_nums = config.getUser(user, "fax_numbers")
            if not incoming_nums:
                continue
            outgoing_num = incoming_nums.split(',')[0].strip()

        mailaddress = config.getUser(user, "fax_email", user)
        fromaddress = config.getUser(user, "fax_email_from", user)

        for jobnum, controlfile in capisuite.fax.getQueueFiles(config, user):
            core.log("checking job %s %s" % (jobnum, controlfile), 3)
            assert controlfile == os.path.abspath(controlfile)
            try:
                # lock the job so that it isn't deleted while sending
                lock = _getLock('dummy', forfile=controlfile, blocking=0)
            except LockTakenError:
                # if we didn't get the lock, continue with next job
                continue
            try:
                control = capisuite.config.JobDescription(controlfile)

                fax_file = control.get('filename')
                assert fax_file == os.path.abspath(fax_file)

                # both the job control file and the fax file must have
                # the users uid