示例#1
0
def handle(*args, **options):

    # Message ID in DB is provided as first argument
    # multiple ID are passed for multipart.
    # we'll only work on firt one as Inbox retrieves other parts.
    if len(args) < 2:
        logger.error(u"No message ID provided")
        sys.exit(1)
    try:
        sql_id = int(args[1])
    except:
        sql_id = None

    if not isinstance(sql_id, int):
        logger.error(u"Provided ID (%s) is not an int." % sql_id)
        sys.exit(1)

    # retrieve message from DB
    try:
        message = Inbox.filter(ID=sql_id, Processed=Inbox.PROC_FALSE).get()
    except Inbox.DoesNotExist:
        logger.warning(u"No unprocessed row in DB for ID %d" % sql_id)
        return False

    # process handler
    try:
        handler_func = import_path(nosettings.NOSMSD_HANDLER)
    except AttributeError:
        message.status = Inbox.STATUS_ERROR
        message.save()
        logger.error(u"NO SMS_HANDLER defined while receiving SMS")
    except Exception as e:
        message.status = Inbox.STATUS_ERROR
        message.save()
        logger.error(u"Unbale to call SMS_HANDLER with %r" % e)
    else:
        try:
            handler_func(message)
        except Exception as e:
            message.status = Inbox.STATUS_ERROR
            message.save()
            logger.error(u"SMS handler failed on %s with %r"
                         % (message, e))

    message.status = Inbox.STATUS_PROCESSED
    message.Processed = Inbox.PROC_TRUE
    message.save()
示例#2
0
def handle(*args, **options):

    # Message ID in DB is provided as first argument
    # multiple ID are passed for multipart.
    # we'll only work on firt one as Inbox retrieves other parts.
    if len(args) < 2:
        logger.error(u"No message ID provided")
        sys.exit(1)
    try:
        sql_id = int(args[1])
    except:
        sql_id = None

    if not isinstance(sql_id, int):
        logger.error(u"Provided ID (%s) is not an int." % sql_id)
        sys.exit(1)

    # retrieve message from DB
    try:
        message = Inbox.filter(ID=sql_id, Processed=Inbox.PROC_FALSE).get()
    except Inbox.DoesNotExist:
        logger.warning(u"No unprocessed row in DB for ID %d" % sql_id)
        return False

    # process handler
    try:
        handler_func = import_path(nosettings.NOSMSD_HANDLER)
    except AttributeError:
        message.status = Inbox.STATUS_ERROR
        message.save()
        logger.error(u"NO SMS_HANDLER defined while receiving SMS")
    except Exception as e:
        message.status = Inbox.STATUS_ERROR
        message.save()
        logger.error(u"Unbale to call SMS_HANDLER with %r" % e)
    else:
        try:
            handler_func(message)
        except Exception as e:
            message.status = Inbox.STATUS_ERROR
            message.save()
            logger.error(u"SMS handler failed on %s with %r" % (message, e))

    message.status = Inbox.STATUS_PROCESSED
    message.Processed = Inbox.PROC_TRUE
    message.save()
示例#3
0
def handle(*args, **options):

    # args format: (sender, text)
    if len(args) != 3:
        logger.error(u"Incorrect input.\nUsage: %s FROM TEXT" % args[0])
        sys.exit(1)

    # create message object in DB
    try:
        sender, text = args[1:]
        sender = sender.strip()
        text = text.strip()
        msg = Inbox.add(sender, text)

        logger.info("Added message as ID #%d" % msg.id)

        # launch message handler
        nohandle(args[0], msg.id)

    except Exception as e:
        logger.error(u"Unable to record message:\n%r" % e)
        sys.exit(1)
示例#4
0
def handle(*args, **options):

    # args format: (sender, text)
    if len(args) != 3:
        logger.error(u"Incorrect input.\nUsage: %s FROM TEXT" % args[0])
        sys.exit(1)

    # create message object in DB
    try:
        sender, text = args[1:]
        sender = sender.strip()
        text = text.strip()
        msg = Inbox.add(sender, text)

        logger.info("Added message as ID #%d" % msg.id)

        # launch message handler
        nohandle(args[0], msg.id)

    except Exception as e:
        logger.error(u"Unable to record message:\n%r" % e)
        sys.exit(1)