From nobody Thu Oct 24 04:20:51 2024 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=patchew-devel-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1649321262; cv=none; d=zohomail.com; s=zohoarc; b=dkP1aYKfk9gTaG7eaV08UCpZpzwa0Nlgci+YyIsPIopWXoq5TsRovqsMSsA5vYVPLbqzc+VSwTTmTjwl6XJ5n05QsoYdDyjgqlpSQVxC5a7VKek+gPBZc5kYvlT7nqhaSqCh0iT5eRLXJaJ1KDQOtN5Uz0/1zZUvkX8IHRhb15Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649321262; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=G0HbkJC/oZiwTRkr5VqHwfPV/AbL9hEQoHLsZ9YrSRs=; b=AAX62lHuWaCTmH0oFFIminiSkdjW2GLbGdoqNyZHWiVWOTv2d7Ch9iF5r2kC4hMX/FWUj507dFNX/WlVju9Yms1Bz9SDjgwvIkArs3S5/rn5pTYA3NZraE85PpdL3vHhhag1V5ZKztfMPzUpt5BqAdHLQkLS/KVsYeiQvq6Fvmc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1649321262457874.367178668946; Thu, 7 Apr 2022 01:47:42 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-340-xqfjDgxNN02J8H09OdshHQ-1; Thu, 07 Apr 2022 04:47:40 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 24293899EC4; Thu, 7 Apr 2022 08:47:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18FBC432721; Thu, 7 Apr 2022 08:47:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D1294194034B; Thu, 7 Apr 2022 08:47:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CABDA194034F for ; Thu, 7 Apr 2022 08:47:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 533672024CC2; Thu, 7 Apr 2022 08:47:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EFAF2024CC5 for ; Thu, 7 Apr 2022 08:47:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8DE31833959 for ; Thu, 7 Apr 2022 08:47:23 +0000 (UTC) Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-225-5FP8KCTOMKadvbdjzMxrLA-2; Thu, 07 Apr 2022 04:47:11 -0400 Received: by mail-ej1-f48.google.com with SMTP id n6so9280711ejc.13 for ; Thu, 07 Apr 2022 01:47:11 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r22-20020a17090638d600b006d584aaa9c9sm7453703ejd.133.2022.04.07.01.47.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 01:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649321261; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=G0HbkJC/oZiwTRkr5VqHwfPV/AbL9hEQoHLsZ9YrSRs=; b=TwLAOTFC2Ko56TAealcujgMtG4l8rm4DmxB8w6x9rAc0ijIKtMauYxOeWbxMzo2o9YhyHs sVTzB3LcDAtBSjabQk8W71C0V4g78VOP7LTQMEqK7y74WjWveZJy/hSwpbcluIxISmVCv2 0r3sLI72edI9tvgNlMuBA2VApL6fcmk= X-MC-Unique: xqfjDgxNN02J8H09OdshHQ-1 X-Original-To: patchew-devel@listman.corp.redhat.com X-MC-Unique: 5FP8KCTOMKadvbdjzMxrLA-2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=pZtpfkqxr1icpdW7ThUniXs3vRzDZf2nkx7eisOdTpc=; b=qYmlO2OGJ5NJJ8UyeRlrdjvm4HkDJcdjwE62Q9XJ95I9/FSUnQEea6EYlQPYH2L6xF VsXav69LVZY7tWBZkHqk1gIAxLXu44S5NdABeYyKircnmfJkFQJul/aXd8sdFc0BSo7j s6vKNVtsVSBSWg50aQ1gSST7g2bGjv6YVZHWkqV7dyDDnDH4lS7Ot6JuftXM7cnaF+OQ uLoMMMO3Epj8dxGBqSPzQEhEK+87+/QxtdlXrkloQZ+/Byvl1NlfWoQEtES4vKPrjP7N 2HdkOCVQBJAxffSqQvcEooE4OQILSbiyk55l7facHUKvbBstODYTTP0KSWL+sg4hk/gy UnnA== X-Gm-Message-State: AOAM533xa/TdtpTSwl+LNmBqZoeCg3VDuP0dgMY2F172ny0crDU+EOfE jYfzBQ7d7pRCVlMxXKnIBM8e1rejYkRx3Q== X-Google-Smtp-Source: ABdhPJxxYFDCXSq4OFCSUOD6bXFjGPsaYI2qqEJ2GhgGtLWfo7EEtnm2R7IWq2Ig/oBJzynjeMgbAQ== X-Received: by 2002:a17:906:d10c:b0:6cd:4aa2:cd62 with SMTP id b12-20020a170906d10c00b006cd4aa2cd62mr12210587ejz.229.1649321231092; Thu, 07 Apr 2022 01:47:11 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Thu, 7 Apr 2022 10:47:02 +0200 Message-Id: <20220407084704.78533-4-pbonzini@redhat.com> In-Reply-To: <20220407084704.78533-1-pbonzini@redhat.com> References: <20220407084704.78533-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Subject: [Patchew-devel] [PATCH 3/5] models: confine blob handling to migrations X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchew-devel-bounces@redhat.com Sender: "Patchew-devel" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=patchew-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1649321263881100001 Content-Type: text/plain; charset="utf-8" Blobs are not used anymore by api.models except for migrating historical databases. Move the api.blobs code into the api.migrations package. Signed-off-by: Paolo Bonzini --- api/blobs.py | 30 ------------------------ api/migrations/0030_deblob_properties.py | 4 ++-- api/migrations/0062_deblob_messages.py | 6 ++--- api/migrations/__init__.py | 24 +++++++++++++++---- api/models.py | 16 +++---------- 5 files changed, 28 insertions(+), 52 deletions(-) delete mode 100644 api/blobs.py diff --git a/api/blobs.py b/api/blobs.py deleted file mode 100644 index 502076e..0000000 --- a/api/blobs.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright 2016, 2018 Red Hat, Inc. -# -# Authors: -# Fam Zheng -# Paolo Bonzini -# -# This work is licensed under the MIT License. Please see the LICENSE fil= e or -# http://opensource.org/licenses/MIT. - - -import os -import uuid - -from django.conf import settings -import lzma - - -def load_blob(name): - fn =3D os.path.join(settings.DATA_DIR, "blob", name + ".xz") - return lzma.open(fn, "r").read().decode("utf-8") - - -def delete_blob(name): - fn =3D os.path.join(settings.DATA_DIR, "blob", name + ".xz") - try: - os.remove(fn) - except FileNotFoundError: - pass diff --git a/api/migrations/0030_deblob_properties.py b/api/migrations/0030= _deblob_properties.py index 5fca390..826bf68 100644 --- a/api/migrations/0030_deblob_properties.py +++ b/api/migrations/0030_deblob_properties.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals =20 from django.db import migrations =20 -from api import blobs +from . import load_blob =20 =20 def deblob_properties(apps, schema_editor): @@ -12,7 +12,7 @@ def deblob_properties(apps, schema_editor): for obj in objects: obj.blob =3D False if obj.value is not None: - obj.value =3D blobs.load_blob(obj.value) + obj.value =3D load_blob(obj.value) obj.save() =20 # We can't import the models directly as they may be a newer diff --git a/api/migrations/0062_deblob_messages.py b/api/migrations/0062_d= eblob_messages.py index 22ee12f..47894fa 100644 --- a/api/migrations/0062_deblob_messages.py +++ b/api/migrations/0062_deblob_messages.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals =20 from django.db import migrations, transaction =20 -from api import blobs +from . import load_blob, delete_blob =20 def deblob_messages(apps, schema_editor): Project =3D apps.get_model("api", "Project") @@ -19,10 +19,10 @@ def deblob_messages(apps, schema_editor): q =3D Message.objects.filter(project=3Dp, date__lte=3Dfirs= t_date, mbox_bytes=3DNone).order_by("-date")[:1000] for msg in q: try: - mbox_decoded =3D blobs.load_blob(msg.message_id) + mbox_decoded =3D load_blob(msg.message_id) msg.mbox_bytes =3D mbox_decoded.encode("utf-8") msg.save() - blobs.delete_blob(msg.message_id) + delete_blob(msg.message_id) done +=3D 1 except Exception as e: print(msg, type(e)) diff --git a/api/migrations/__init__.py b/api/migrations/__init__.py index 02f4c63..35b5483 100644 --- a/api/migrations/__init__.py +++ b/api/migrations/__init__.py @@ -1,22 +1,38 @@ #!/usr/bin/env python3 # -# Copyright 2018 Red Hat, Inc. +# Copyright 2016, 2018 Red Hat, Inc. # # Authors: +# Fam Zheng # Paolo Bonzini # # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 +from django.conf import settings from django.db import migrations =20 import json -from api import blobs +import lzma +import os +import uuid =20 =20 +def load_blob(name): + fn =3D os.path.join(settings.DATA_DIR, "blob", name + ".xz") + return lzma.open(fn, "r").read().decode("utf-8") + + +def delete_blob(name): + fn =3D os.path.join(settings.DATA_DIR, "blob", name + ".xz") + try: + os.remove(fn) + except FileNotFoundError: + pass + def load_blob_json_safe(name): try: - return json.loads(blobs.load_blob(name)) + return json.loads(load_blob(name)) except Exception as e: return "Failed to load blob %s: %s" % (name, e) =20 @@ -44,7 +60,7 @@ def get_property(model, name, **kwargs): def delete_property_blob(model, name, **kwargs): mp =3D get_property_raw(model, name, **kwargs) if hasattr(mp, "blob") and mp.blob: - blobs.delete_blob(mp.value) + delete_blob(mp.value) =20 =20 def set_property(model, name, value, **kwargs): diff --git a/api/models.py b/api/models.py index ce38913..7bf8021 100644 --- a/api/models.py +++ b/api/models.py @@ -22,7 +22,6 @@ import lzma from mbox import MboxMessage, decode_payload from patchew.tags import lines_iter from event import emit_event, declare_event -from .blobs import delete_blob, load_blob import mod =20 =20 @@ -493,7 +492,7 @@ class MessageManager(models.Manager): msg.is_patch =3D m.is_patch() msg.patch_num =3D m.get_num()[0] msg.project =3D project - msg.save_mbox(mbox) + msg.mbox_bytes =3D mbox.encode("utf-8") msg.save() emit_event("MessageAdded", message=3Dmsg) self.update_series(msg) @@ -533,7 +532,7 @@ class MessageManager(models.Manager): msg.project =3D p if self.filter(message_id=3Dmsgid, project__name=3Dp.name).fir= st(): raise self.DuplicateMessageError(msgid) - msg.save_mbox(mbox) + msg.mbox_bytes =3D mbox.encode("utf-8") msg.save() emit_event("MessageAdded", message=3Dmsg) self.update_series(msg) @@ -654,12 +653,6 @@ class Message(models.Model): maintainers =3D jsonfield.JSONField(blank=3DTrue, default=3D[]) properties =3D jsonfield.JSONField(default=3D{}) =20 - def save_mbox(self, mbox): - mbox_bytes =3D mbox.encode("utf-8") - if self.mbox_bytes is None: - delete_blob(self.message_id) - self.mbox_bytes =3D mbox_bytes - def get_mbox_obj(self): if not hasattr(self, "_mbox_obj"): self._mbox_obj =3D MboxMessage(self.mbox) @@ -667,10 +660,7 @@ class Message(models.Model): =20 def get_mbox(self): if not hasattr(self, "_mbox_decoded"): - if self.mbox_bytes: - self._mbox_decoded =3D str(self.mbox_bytes, "utf-8") - else: - self._mbox_decoded =3D load_blob(self.message_id) + self._mbox_decoded =3D str(self.mbox_bytes, "utf-8") return self._mbox_decoded =20 mbox =3D property(get_mbox) --=20 2.35.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://listman.redhat.com/mailman/listinfo/patchew-devel