コード例 #1
0
ファイル: dispatcher.py プロジェクト: SMIDEC/gwibber-lc
def perform_operation((account, opname, args, transient)):
    try:
        stream = FEATURES[opname]["stream"] or opname
        logtext = "<%s:%s>" % (account["service"], opname)

        logtext = "<%s:%s>" % (account["service"], opname)
        log.logger.debug("%s Performing operation", logtext)

        args = dict((str(k), v) for k, v in args.items())
        message_data = PROTOCOLS[account["service"]].Client(account)(opname,
                                                                     **args)
        text_cleaner = re.compile(u"[: \n\t\r♻♺]+|@[^ ]+|![^ ]+|#[^ ]+"
                                  )  # signs, @nickname, !group, #tag
        new_messages = []

        if message_data is not None:
            for m in message_data:
                try:
                    if isinstance(m, dict) and m.has_key("mid"):
                        m["id"] = uuid.uuid1().hex
                        m["operation"] = opname
                        m["stream"] = stream
                        m["transient"] = transient
                        m["rtl"] = util.isRTL(
                            re.sub(text_cleaner, "",
                                   m["text"].decode('utf-8')))
                        if m.has_key("type"):
                            if m["type"] == "link": m["stream"] = "links"
                            if m["type"] == "video": m["stream"] = "videos"
                            if m["type"] == "photo": m["stream"] = "images"

                        log.logger.debug("%s Adding record", logtext)

                        new_messages.insert(
                            0,
                            (m["id"], m["mid"], m["account"],
                             account["service"], opname, transient, m["stream"]
                             or stream, m["time"], m["text"],
                             m.get("sender", {}).get("is_me", None),
                             m.get("to_me", None), m.get("sender", {}).get(
                                 "nick", None), m.get("reply", {}).get(
                                     "nick", None), json.dumps(m)))
                    elif isinstance(m, dict) and m.has_key("error"):
                        new_messages.insert(0, ("error", json.dumps(m)))
                except Exception as e:
                    if not "logtext" in locals(): logtext = "<UNKNOWN>"
                    log.logger.error("%s Operation failed", logtext)

        log.logger.debug("%s Finished operation", logtext)
        return ("Success", new_messages)
    except Exception as e:
        if not "logtext" in locals(): logtext = "<UNKNOWN>"
        log.logger.error("%s Operation failed", logtext)
        log.logger.debug("Traceback:\n%s", traceback.format_exc())
        return ("Failure", traceback.format_exc())
コード例 #2
0
ファイル: dispatcher.py プロジェクト: thnguyn2/ECE_527_MP
  def run(self):
    self.id = ''.join(random.choice(string.letters) for i in xrange(5))
    self.t_start = datetime.now()
    (account, opname, args, transient) = self.job
    try:
      stream = FEATURES[opname]["stream"] or opname
      logtext = "<%s:%s>" % (account["service"], opname)

      logtext = "<%s:%s>" % (account["service"], opname)
      logger.debug("%s Performing operation", logtext)

      args = dict((str(k), v) for k, v in args.items())
      message_data = PROTOCOLS[account["service"]].Client(account)(opname, **args)
      text_cleaner = re.compile(u"[: \n\t\r♻♺]+|@[^ ]+|![^ ]+|#[^ ]+") # signs, @nickname, !group, #tag
      new_messages = []

      if message_data is not None:
        for m in message_data:
          try:
            if isinstance(m, dict) and m.has_key("mid"):
              m["id"] = uuid.uuid1().hex
              m["operation"] = opname
              m["stream"] = m.get("stream", stream)
              m["transient"] = transient
              m["time"] = m.get("time", 0)
              if not m["text"]: m["text"] = ""
              m["rtl"] = util.isRTL(re.sub(text_cleaner, "", m["text"]))
              if m.has_key("type"):
                if m["type"] == "link": m["stream"] = "links"
                if m["type"] == "video": m["stream"] = "videos"
                if m["type"] == "photo": m["stream"] = "images"

              logger.debug("%s Adding record", logtext)
              new_messages.insert(0, (
                                  m["id"],
                                  m["mid"],
                                  m["account"],
                                  account["service"],
                                  opname,
                                  transient,
                                  m["stream"] or stream,
                                  m["time"],
                                  m["text"],
                                  m.get("sender", {}).get("is_me", None),
                                  m.get("to_me", None),
                                  m.get("sender", {}).get("nick", None),
                                  m.get("reply", {}).get("nick", None),
                                  json.dumps(m)
              ))
            elif isinstance(m, dict) and m.has_key("error"):
              new_messages.insert(0, (
                                  "error",
                                  json.dumps(m)
              ))
          except Exception as e:
            if not "logtext" in locals(): logtext = "<UNKNOWN>"
            logger.error("%s Operation failed: %s", logtext, e)
      self.callback_success(new_messages)

    except Exception as e:
      if not "logtext" in locals(): logtext = "<UNKNOWN>"
      logger.error("%s Operation failed", logtext)
      logger.debug("Traceback:\n%s", traceback.format_exc())
      self.callback_failure("Error")

    self.t_end = datetime.now()
    self.t_runtime = self.t_end - self.t_start
    logger.debug("%s Finished operation (%s)" % (logtext, str(self.t_runtime)))
コード例 #3
0
ファイル: dispatcher.py プロジェクト: Alberto-Beralix/Beralix
def perform_operation((account, opname, args, transient)):
  try:
    stream = FEATURES[opname]["stream"] or opname
    logtext = "<%s:%s>" % (account["service"], opname)

    logtext = "<%s:%s>" % (account["service"], opname)
    log.logger.debug("%s Performing operation", logtext)

    args = dict((str(k), v) for k, v in args.items())
    message_data = PROTOCOLS[account["service"]].Client(account)(opname, **args)
    text_cleaner = re.compile(u"[: \n\t\r♻♺]+|@[^ ]+|![^ ]+|#[^ ]+") # signs, @nickname, !group, #tag
    new_messages = []

    if message_data is not None:
      for m in message_data:
        try: 
          if isinstance(m, dict) and m.has_key("mid"):
            m["id"] = uuid.uuid1().hex
            m["operation"] = opname
            m["stream"] = m.get("stream", stream)
            m["transient"] = transient
            m["time"] = m.get("time", 0)
            if not m["text"]: m["text"] = ""
            m["rtl"] = util.isRTL(re.sub(text_cleaner, "", m["text"].decode('utf-8')))
            if m.has_key("type"):
              if m["type"] == "link": m["stream"] = "links"
              if m["type"] == "video": m["stream"] = "videos"
              if m["type"] == "photo": m["stream"] = "images"

            log.logger.debug("%s Adding record", logtext)

            new_messages.insert(0, (
              m["id"],
              m["mid"],
              m["account"],
              account["service"],
              opname,
              transient,
              m["stream"] or stream,
              m["time"],
              m["text"],
              m.get("sender", {}).get("is_me", None), 
              m.get("to_me", None),
              m.get("sender", {}).get("nick", None),
              m.get("reply", {}).get("nick", None),
              json.dumps(m)
            ))
          elif isinstance(m, dict) and m.has_key("error"):
            new_messages.insert(0, (
              "error",
              json.dumps(m)
            ))
        except Exception as e:
          if not "logtext" in locals(): logtext = "<UNKNOWN>"
          log.logger.error("%s Operation failed: %s", logtext, e)

    log.logger.debug("%s Finished operation", logtext)
    return ("Success", new_messages)
  except Exception as e:
    if not "logtext" in locals(): logtext = "<UNKNOWN>"
    log.logger.error("%s Operation failed", logtext)
    log.logger.debug("Traceback:\n%s", traceback.format_exc())
    return ("Failure", traceback.format_exc())
コード例 #4
0
def perform_operation((account, opname, args, transient)):
    try:
        stream = FEATURES[opname]["stream"] or opname
        logtext = "<%s:%s>" % (account["service"], opname)
        """ Dead code from merge. Do we still need this?
    if not 'failed_id' in globals():
      global failed_id
      failed_id = []

    for key, val in account.items():
      if isinstance(val, str) and val.startswith(":KEYRING:"):
        value = util.keyring.get_account_password(account["_id"])

        if value is None:
          if account["_id"] not in failed_id:
            log.logger.debug("Adding %s to failed_id global", account["_id"])
            failed_id.append(account["_id"])
            log.logger.debug("Raising error to resolve failure for %s", account["_id"])
            raise exceptions.GwibberServiceError("keyring")
          return ("Failure", 0)

        account[key] = value
    """

        logtext = "<%s:%s>" % (account["service"], opname)
        log.logger.debug("%s Performing operation", logtext)

        args = dict((str(k), v) for k, v in args.items())
        message_data = PROTOCOLS[account["service"]].Client(account)(opname,
                                                                     **args)
        text_cleaner = re.compile(u"[: \n\t\r♻♺]+|@[^ ]+|![^ ]+|#[^ ]+"
                                  )  # signs, @nickname, !group, #tag
        new_messages = []

        if message_data is not None:
            for m in message_data:
                if isinstance(m, dict) and m.has_key("mid"):
                    m["id"] = uuid.uuid1().hex
                    m["operation"] = opname
                    m["stream"] = stream
                    m["transient"] = transient
                    m["rtl"] = util.isRTL(
                        re.sub(text_cleaner, "", m["text"].decode('utf-8')))

                    log.logger.debug("%s Adding record", logtext)

                    new_messages.insert(
                        0,
                        (m["id"], m["mid"], m["account"], account["service"],
                         opname, transient, stream, m["time"], m["text"],
                         m.get("sender", {}).get("is_me", None),
                         m.get("to_me", None), m.get("sender", {}).get(
                             "nick", None), m.get("reply", {}).get(
                                 "nick", None), json.dumps(m)))

        log.logger.debug("%s Finished operation", logtext)
        return ("Success", new_messages)
    except Exception as e:
        if not "logtext" in locals(): logtext = "<UNKNOWN>"
        log.logger.error("%s Operation failed", logtext)
        log.logger.debug("Traceback:\n%s", traceback.format_exc())
        return ("Failure", traceback.format_exc())
コード例 #5
0
ファイル: dispatcher.py プロジェクト: SMIDEC/gwibber-lc
def perform_operation((account, opname, args, transient)):
  try:
    stream = FEATURES[opname]["stream"] or opname
    logtext = "<%s:%s>" % (account["service"], opname)

    """ Dead code from merge. Do we still need this?
    if not 'failed_id' in globals():
      global failed_id
      failed_id = []

    for key, val in account.items():
      if isinstance(val, str) and val.startswith(":KEYRING:"):
        value = util.keyring.get_account_password(account["_id"])

        if value is None:
          if account["_id"] not in failed_id:
            log.logger.debug("Adding %s to failed_id global", account["_id"])
            failed_id.append(account["_id"])
            log.logger.debug("Raising error to resolve failure for %s", account["_id"])
            raise exceptions.GwibberServiceError("keyring")
          return ("Failure", 0)

        account[key] = value
    """

    logtext = "<%s:%s>" % (account["service"], opname)
    log.logger.debug("%s Performing operation", logtext)

    args = dict((str(k), v) for k, v in args.items())
    message_data = PROTOCOLS[account["service"]].Client(account)(opname, **args)
    text_cleaner = re.compile(u"[: \n\t\r♻♺]+|@[^ ]+|![^ ]+|#[^ ]+") # signs, @nickname, !group, #tag
    new_messages = []

    if message_data is not None:
      for m in message_data:
        if isinstance(m, dict) and m.has_key("mid"):
          m["id"] = uuid.uuid1().hex
          m["operation"] = opname
          m["stream"] = stream
          m["transient"] = transient
          m["rtl"] = util.isRTL(re.sub(text_cleaner, "", m["text"].decode('utf-8')))

          log.logger.debug("%s Adding record", logtext)

          new_messages.insert(0, (
            m["id"],
            m["mid"],
            m["account"],
            account["service"],
            opname,
            transient,
            stream,
            m["time"],
            m["text"],
            m.get("sender", {}).get("is_me", None), 
            m.get("to_me", None),
            m.get("sender", {}).get("nick", None),
            m.get("reply", {}).get("nick", None),
            json.dumps(m)
          ))

    log.logger.debug("%s Finished operation", logtext)
    return ("Success", new_messages)
  except Exception as e:
    if not "logtext" in locals(): logtext = "<UNKNOWN>"
    log.logger.error("%s Operation failed", logtext)
    log.logger.debug("Traceback:\n%s", traceback.format_exc())
    return ("Failure", traceback.format_exc())