From nobody Mon Dec 15 23:28:17 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526972284851928.4556386674269; Mon, 21 May 2018 23:58:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4388D8190; Tue, 22 May 2018 06:58:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D409830BF205; Tue, 22 May 2018 06:58:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C3DE34BB78; Tue, 22 May 2018 06:58:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4M6w1YP028189 for ; Tue, 22 May 2018 02:58:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id E5C5D30BF206; Tue, 22 May 2018 06:58:01 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF12130BF205 for ; Tue, 22 May 2018 06:58:01 +0000 (UTC) Received: from mail-pg0-f43.google.com (mail-pg0-f43.google.com [74.125.83.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC38B30C0340 for ; Tue, 22 May 2018 06:57:50 +0000 (UTC) Received: by mail-pg0-f43.google.com with SMTP id d14-v6so3846348pgv.8 for ; Mon, 21 May 2018 23:57:50 -0700 (PDT) Received: from localhost.localdomain ([208.181.63.202]) by smtp.gmail.com with ESMTPSA id y2-v6sm19818676pgp.92.2018.05.21.23.57.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 May 2018 23:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=I7v7uXkGQ13Tbw/CO+Q8ukRwtCVARsA3Q80WoAyBFf4=; b=lUrWB1w0giC+aUSM6ja0rjFtnefDulMhOEQLRyS1YFEx+oX6wnU/A1jiMvJxqcN18o 696deEUT7ICTAZMWdbAORYOFa75gySbEcuH+DgFcxjG9xB9E4WSKuErXLmskAhagR+gD bL3ypH9xmnFo4h8yZoxTP+HE6mjOZ2ET/dJCmb6MYcjvfxptqTFynBnu7HdGCh4fNLM5 P1PXJIl9qgmD7XJwpCI/YZQyWjQaRAkcILiQHXjmrUSPkvnnfFHKd5fQoQcBp6GGpkyY rZrC6UjN980UbMH/rypAa7VG0UAq4CkvLJ2LL7SeCfZ9+hLRwXZeWMomLPBEAdVgR4vQ RjkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=I7v7uXkGQ13Tbw/CO+Q8ukRwtCVARsA3Q80WoAyBFf4=; b=MkMmOsejfXkA/SxVIUvGnQwBqwyotvOWwDtZ59P56/PQzmMORuZHfj0BjAgf9a7Cxk 7DZioTKpbHLY1u6LcAqkFExH4n/0wLWxXUChcWoSNp2H7fycnzrbukolNtC9F31RqwYY HRvSdCiPBc50Evyiymq67Hg+Otxo7zG/O+a7+/VnJUXJniRmvVnu2LTjEVVJXEQo4fU6 WMVdOAjhcSA7X9NvvVSp8fq7j5qaVHLDHyfUF+ryfT999iCqh1nNm8keKXiCX6xaoG8v F6nSH8g3vLfdRBFDMYnokqDaGvagme6y/1bmv7Z1CMVeUD286r6qHcYjC8+PlwUypnGD hMQg== X-Gm-Message-State: ALKqPwfHM3Flhtby6o7Ah01rmHRmBJKKuqdb6QdRrDwtOQC7Db92pWyK narkChj2Gx2B1ooUL6DcPJmEFIWH X-Google-Smtp-Source: AB8JxZqAC3rs+dqwh5P1S38LCvabKVYQoF4C9rU0oVy3vYez8jtXNZv//5l3OGtdowLscdppRoiCsg== X-Received: by 2002:a62:78c:: with SMTP id 12-v6mr22993674pfh.178.1526972269818; Mon, 21 May 2018 23:57:49 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Tue, 22 May 2018 08:57:33 +0200 Message-Id: <20180522065740.9710-6-pbonzini@redhat.com> In-Reply-To: <20180522065740.9710-1-pbonzini@redhat.com> References: <20180522065740.9710-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 22 May 2018 06:57:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 22 May 2018 06:57:50 +0000 (UTC) for IP:'74.125.83.43' DOMAIN:'mail-pg0-f43.google.com' HELO:'mail-pg0-f43.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.597 (DKIM_SIGNED, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 74.125.83.43 mail-pg0-f43.google.com 74.125.83.43 mail-pg0-f43.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 05/12] models: extract blobs functions to a separate file X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 22 May 2018 06:58:03 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" They will be used by migrations, and we don't want to import api.models there. --- api/blobs.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ api/models.py | 27 ++++----------------------- 2 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 api/blobs.py diff --git a/api/blobs.py b/api/blobs.py new file mode 100644 index 0000000..7171b71 --- /dev/null +++ b/api/blobs.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# +# Copyright 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 json +import uuid +import logging + +from django.conf import settings +import lzma + +def save_blob(data, name=3DNone): + if not name: + name =3D str(uuid.uuid4()) + fn =3D os.path.join(settings.DATA_DIR, "blob", name + ".xz") + lzma.open(fn, 'w').write(data.encode("utf-8")) + return name + +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 load_blob_json(name): + try: + return json.loads(load_blob(name)) + except json.decoder.JSONDecodeError as e: + logging.error('Failed to load blob %s: %s' %(name, e)) + return None + +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/models.py b/api/models.py index 0f25f85..497e43c 100644 --- a/api/models.py +++ b/api/models.py @@ -10,39 +10,20 @@ =20 =20 from collections import namedtuple -import os import json import datetime import re -import uuid -import logging =20 -from django.conf import settings from django.db import models from django.contrib.auth.models import User from django.urls import reverse import jsonfield -from mbox import MboxMessage -from event import emit_event, declare_event import lzma =20 -def save_blob(data, name=3DNone): - if not name: - name =3D str(uuid.uuid4()) - fn =3D os.path.join(settings.DATA_DIR, "blob", name + ".xz") - lzma.open(fn, 'w').write(data.encode("utf-8")) - return name - -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 load_blob_json(name): - try: - return json.loads(load_blob(name)) - except json.decoder.JSONDecodeError as e: - logging.error('Failed to load blob %s: %s' %(name, e)) - return None +from mbox import MboxMessage +from event import emit_event, declare_event +from .blobs import save_blob, load_blob, load_blob_json +import mod =20 class Project(models.Model): name =3D models.CharField(max_length=3D1024, db_index=3DTrue, unique= =3DTrue, --=20 2.17.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel