Example #1
0
    info = {}
    for line in open(os.path.join(settings.FAX_SPOOL_DIR, qfile), 'r'):
        tag, data = line.split(':', 1)
	data = data.strip()
        if tag[0] == '!':
            if not tag in info:
                info[tag] = []
            info[tag].append(data)
        else:
            info[tag] = data
    print info

    try:
        fax = Fax.objects.get(comm_id=info['commid'])
    except Fax.DoesNotExist:
        fax = Fax()
    
    error_message = None
    if why != 'done' or int(info['state']) == 9:
        try:
            error_message = '%s: %s' % (why, info['status'])
        except KeyError:
            error_message = why
        fax.status = 2
    else:
        fax.status = 1
    print 'OK'

    # Continue if fax is done or aborted due to an error
    if why in ('blocked', 'requeued'):
        fax.status = 0
Example #2
0
    def handle(self, *args, **options):

        if 3 > len(args) > 4:
            raise AttributeError

        TIFF_OUTPUT_DIR = os.path.join(settings.FAX_SPOOL_DIR, 'senttiff')

        qfile, why, jobtime = args[:3]

        # Scan qfile for info
        info = {}
        for line in open(os.path.join(settings.FAX_SPOOL_DIR, qfile), 'r'):
            tag, data = line.split(':', 1)
            data = data.strip()
            if tag[0] == '!':
                if not tag in info:
                    info[tag] = []
                info[tag].append(data)
            else:
                info[tag] = data
        print info

        try:
            fax = Fax.objects.get(comm_id=info['commid'])
        except Fax.DoesNotExist:
            fax = Fax()

        error_message = None
        if why != 'done' or int(info['state']) == 9:
            try:
                error_message = '%s: %s' % (why, info['status'])
            except KeyError:
                error_message = why
            fax.status = 2
        else:
            fax.status = 1
        print 'OK'

        # Continue if fax is done or aborted due to an error
        if why in ('blocked', 'requeued'):
            fax.status = 0
            fax.save()
            sys.exit(1)

        fax.comm_id = info['commid']
        fax.local_sender = '%s@%s' % (info['mailaddr'], info['client'])
        fax.received_on = datetime.fromtimestamp(float(info['tts']))
        fax.outbound = True
        fax.caller_id = info['number']
        if error_message:
            fax.reason = error_message
        # Exit if job is not done
        if int(info['state']) < 7:
            fax.save()
            sys.exit(1)

        # List files
        input_files = []
        for tag in ('postscript', 'pdf', '!postscript', '!pdf'):
            if tag in info:
                input_files += [os.path.join(settings.FAX_SPOOL_DIR,
                                             name.split(':')[-1]) for name in info[tag]]

        # Build TIFF file
        output_file = '%s.tif' % os.path.join(TIFF_OUTPUT_DIR, info['commid'])
        os.system('gs -dBATCH -dNOPAUSE -q -sDEVICE=tiffg3 -sOutputFile=%s %s -r200'
                  % (output_file, ' '.join(input_files)))

        # Store in DB
        fax.filename = 'senttiff/%s.tif' % info['commid']
        fax.time_to_receive = 1
        fax.update_from_tiff()
        fax.save()
        from faxcelerate.fax.image import FaxImage

        FaxImage(fax).cache_thumbnails()
Example #3
0
def receive_fax():
    parameters = [arg.rstrip() for arg in argv]
    try:
        scriptname = parameters[0]
        filename = parameters[1]
        device = parameters[2]
        commid = parameters[3]
        reason = parameters[4]
        cid = parameters[5]
        mystery2 = parameters[6]
        msn = parameters[7]
    except IndexError:
        pass
    logging.info("Processing received fax %s" % commid)
    logging.debug(
        "Fax %s in file %s, received on device %s MSN %s, "
        'reason "%s", id %s' % (commid, filename, device, msn, reason, cid)
    )
    fullfname = settings.FAX_SPOOL_DIR + "/%s" % filename
    fax = Fax()
    fax.received_on = datetime.fromtimestamp(os.path.getmtime(fullfname))
    fax.filename = filename
    fax.device = device
    fax.comm_id = commid
    fax.msn = msn
    fax.caller_id = cid
    fax.msn = mystery2
    fax.status = 1  # Success
    fax.reason = reason
    try:
        fax.update_from_tiff()
    except ValueError, e:
        if not fax.reason == "":
            # There was an error
            fax.error = True
            fax.status = 2  # Error
            logging.info("Fax %s has an error; reason: %s" % fax.reason)
        else:
            raise e
Example #4
0
def create_fax_entry(metadata):
	from faxcelerate.fax.models import Fax
	def m(key):
		try:
			return metadata[key]
		except KeyError:
			return None
	f = Fax()
	f.comm_id = m('commid')
	f.station_id = m('tsi')
	f.msn = m('msn')
	f.received_on = m('date')
	f.time_to_receive = m('jobduration')
	f.conn_duration = m('connduration')
	f.pages = m('pages')
	f.params = m('params')
	f.reason = m('reason')
	f.filename = m('filename')
	f.caller_id = m('callerid')
	f.save()
	return f
Example #5
0
    def handle(self, *args, **options):

        if len(args) < 4:
            raise AttributeError

        qfile, devid, commid, msg = map(str.rstrip, args[:4])
        callid = map(str.strip, args[4:])

        logger.info('Processing received fax %s', commid)
        logger.debug('Fax %s in file %s, received on device %s, message: %s', commid, qfile, devid, msg)

        filename = settings.FAX_SPOOL_DIR + '/' + qfile

        fax = Fax()
        fax.received_on = datetime.fromtimestamp(os.path.getmtime(filename))
        fax.filename = qfile
        fax.device = devid
        fax.comm_id = commid
        fax.reason = msg
        fax.status = 1  # Success
        # TODO improve caller_id
        fax.caller_id = str(callid)

        if os.path.isfile(filename):
            fax.update_from_tiff()
        else:
            fax.error = True
            fax.status = 2  # Error
            logging.info("Fax %s has an error; reason: %s", commid, msg)

        fax.update_from_logfile()
        if fax.station_id == fax.caller_id or fax.station_id == '-':
            fax.station_id = None
        fax.set_sender()
        fax.save()
        FaxImage(fax).cache_thumbnails()