def _save_comments(self, db, comments, new_bug_id): """ Save bug comments to the database. Expects list of `comments` and ID of the bug as `new_bug_id`. """ total = len(comments) for num, comment in enumerate(comments): self.log_debug("Processing comment {0}/{1}".format(num + 1, total)) if queries.get_bz_comment(db, comment["id"]): self.log_debug("Skipping existing comment #{0}".format( comment["id"])) continue self.log_debug("Downloading comment #{0}".format(comment["id"])) user_email = comment["creator"] user = queries.get_bz_user(db, user_email) if not user: self.log_debug("History changed by unknown user #{0}".format( user_email)) downloaded = self._download_user(user_email) if not downloaded: self.log_error("Unable to download user, skipping.") continue user = self._save_user(db, downloaded) new = BzComment() new.id = comment["id"] new.bug_id = new_bug_id new.creation_time = self._convert_datetime(comment["time"]) new.is_private = comment["is_private"] if "attachment_id" in comment: attachment = queries.get_bz_attachment( db, comment["attachment_id"]) if attachment: new.attachment = attachment else: self.log_warn("Comment is referencing an attachment" " which is not accessible.") new.number = num new.user = user db.session.add(new) if not isinstance(comment["text"], six.string_types): comment["text"] = str(comment["text"]) # save_lob is inherited method which cannot # be seen by pylint because of sqlalchemy magic # pylint: disable=E1101 new.save_lob("content", comment["text"].encode("utf-8"), overwrite=True) db.session.flush()
def _save_comments(self, db, comments, new_bug_id): """ Save bug comments to the database. Expects list of `comments` and ID of the bug as `new_bug_id`. """ total = len(comments) for num, comment in enumerate(comments): self.log_debug("Processing comment {0}/{1}".format(num + 1, total)) if queries.get_bz_comment(db, comment["id"]): self.log_debug("Skipping existing comment #{0}".format( comment["id"])) continue self.log_debug("Downloading comment #{0}".format(comment["id"])) user_email = comment["creator"] user = queries.get_bz_user(db, user_email) if not user: self.log_debug("History changed by unknown user #{0}".format( user_email)) downloaded = self._download_user(user_email) if not downloaded: self.log_error("Unable to download user, skipping.") continue user = self._save_user(db, downloaded) new = BzComment() new.id = comment["id"] new.bug_id = new_bug_id new.creation_time = self._convert_datetime(comment["time"]) new.is_private = comment["is_private"] if "attachment_id" in comment: attachment = queries.get_bz_attachment( db, comment["attachment_id"]) if attachment: new.attachment = attachment else: self.log_warn("Comment is referencing an attachment" " which is not accessible.") new.number = num new.user = user db.session.add(new) if not isinstance(comment["text"], str): comment["text"] = str(comment["text"]) # save_lob is inherited method which cannot # be seen by pylint because of sqlalchemy magic # pylint: disable=E1101 new.save_lob("content", comment["text"].encode("utf-8"), overwrite=True) db.session.flush()