def _save_attachments(self, db, attachments, new_bug_id): """ Save bug attachments to the database. Expects list of `attachments` and ID of the bug as `new_bug_id`. """ total = len(attachments) for num, attachment in enumerate(attachments): self.log_debug("Processing attachment {0}/{1}".format(num + 1, total)) if queries.get_bz_attachment(db, attachment["id"]): self.log_debug("Skipping existing attachment #{0}".format( attachment["id"])) continue user_email = attachment["attacher"] user = queries.get_bz_user(db, user_email) if not user: self.log_debug("Attachment from 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 = BzAttachment() new.id = attachment["id"] new.bug_id = new_bug_id new.mimetype = attachment["content_type"] new.description = attachment["description"] new.filename = attachment["file_name"] new.is_private = bool(attachment["is_private"]) new.is_patch = bool(attachment["is_patch"]) new.is_obsolete = bool(attachment["is_obsolete"]) new.creation_time = self._convert_datetime( attachment["creation_time"]) new.last_change_time = self._convert_datetime( attachment["last_change_time"]) new.user = user db.session.add(new) self._connect() data = self.bz.openattachment(attachment["id"]) # save_lob is inherited method which cannot be seen by pylint # because of sqlalchemy magic # pylint: disable=E1101 new.save_lob("content", data, truncate=True, overwrite=True) data.close() db.session.flush()
def _save_attachments(self, db, attachments, new_bug_id): """ Save bug attachments to the database. Expects list of `attachments` and ID of the bug as `new_bug_id`. """ total = len(attachments) for num, attachment in enumerate(attachments): self.log_debug("Processing attachment {0}/{1}".format(num + 1, total)) if queries.get_bz_attachment(db, attachment["id"]): self.log_debug("Skipping existing attachment #{0}".format( attachment["id"])) continue user_email = attachment["attacher"] user = queries.get_bz_user(db, user_email) if not user: self.log_debug("Attachment from 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 = BzAttachment() new.id = attachment["id"] new.bug_id = new_bug_id new.mimetype = attachment["content_type"] new.description = attachment["description"] new.filename = attachment["file_name"] new.is_private = bool(attachment["is_private"]) new.is_patch = bool(attachment["is_patch"]) new.is_obsolete = bool(attachment["is_obsolete"]) new.creation_time = self._convert_datetime( attachment["creation_time"]) new.last_change_time = self._convert_datetime( attachment["last_change_time"]) new.user = user db.session.add(new) self.connect() data = self.bz.openattachment(attachment["id"]) # save_lob is inherited method which cannot be seen by pylint # because of sqlalchemy magic # pylint: disable=E1101 new.save_lob("content", data, truncate=True, overwrite=True) data.close() 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"], 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()