From nobody Mon Dec 15 03:23:04 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 1527761039150426.17462840135204; Thu, 31 May 2018 03:03:59 -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 1323BC05D409; Thu, 31 May 2018 10:03:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0488B309128B; Thu, 31 May 2018 10:03:58 +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 EC0A318005D1; Thu, 31 May 2018 10:03:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4VA3vkp024927 for ; Thu, 31 May 2018 06:03:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 055C7308BDA8; Thu, 31 May 2018 10:03:57 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F1AD8308BDA6 for ; Thu, 31 May 2018 10:03:55 +0000 (UTC) Received: from mail-wr0-f178.google.com (mail-wr0-f178.google.com [209.85.128.178]) (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 8FBEEF44CC for ; Thu, 31 May 2018 10:03:43 +0000 (UTC) Received: by mail-wr0-f178.google.com with SMTP id o12-v6so1329465wrm.12 for ; Thu, 31 May 2018 03:03:43 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-189-60.clienti.tiscali.it. [78.12.189.60]) by smtp.gmail.com with ESMTPSA id g16-v6sm3520664wro.86.2018.05.31.03.03.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 May 2018 03:03:40 -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=JmIi7opMOrAIYYTcMtINCnje7CDPaURVvXU+yKPqAIM=; b=SGDKbDSn3euJc7oi+eWmR9UI4r+ccBHhAHbGdAKjloLbELy5nPDXqXlQbmqSlDEFRZ ylFP8Cinmu5b2glUA1x4gvJpJpXUGp52U6dS2yb57K/Qv2jlR1rBbyYenN4SwJ/UgHTz Texqz9xBROCWWEae0XkrXuDi8h9ECmwOZVVKJ3F4yzz9Ta1i0/dZox8gTSx770gYmNga XEcbeIqeyW5xcuC4IiNVaRqUgb1TnKVc3R+S4InBX9gYtNktKvs+3I8cv7JSVSp2dpYO Io1CrcV9vwnTue0evM+2e/z40v/IS7XMPrA52AI8GOkkzGoq6aAOwd2SDpDEx9qDahVa 7CHg== 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=JmIi7opMOrAIYYTcMtINCnje7CDPaURVvXU+yKPqAIM=; b=Ob4clqJcZPbkecCL7KBwpyDYKvxY7cHHICy5sr2jOpHxxcY3V76QCem7ffARFuhIpb LV5Q1HMx932PSYrFvrLKdD8qjQwtoEBDXkldQrAYVMUbaG9sJeB1ZVVlposnsEsJsWZd OyUH+FSnDotTWLLvG3M6wqsDH4bYlaXXHZwHJFbZ/+PU3B30IIWltsWBR0PLRhXEVyMo CIuqtlIwF8on2/P97KVqCY6tz9Zya40g8VfnN6uQ+EvlrF7uTdAlhDHAvEMAxoSQewGI 8tl45q0iF4yFSug+K3bc++oThHE7nFTPNAp73/rko8gOYHzqNqdqEWh9bhghS8wjgfXl tMhQ== X-Gm-Message-State: ALKqPwdO66zlWGw7xHWfKRrjg2oqulW0wVrJkcj2yoGnPHNs/pnBPtD4 HIEOiJMbJ3hFXztH0vKtZZy1wSAW X-Google-Smtp-Source: ADUXVKIgh7Sg0wmYw6aJ1kzTunXlrhmEsbCdGK1B9j7og5MNHe2DbLuEJGxDf+0vBWFbZTCFDnPnCA== X-Received: by 2002:adf:eb12:: with SMTP id s18-v6mr5232053wrn.174.1527761021888; Thu, 31 May 2018 03:03:41 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Thu, 31 May 2018 12:03:26 +0200 Message-Id: <20180531100334.2249-3-pbonzini@redhat.com> In-Reply-To: <20180531100334.2249-1-pbonzini@redhat.com> References: <20180531100334.2249-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 31 May 2018 10:03:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 31 May 2018 10:03:43 +0000 (UTC) for IP:'209.85.128.178' DOMAIN:'mail-wr0-f178.google.com' HELO:'mail-wr0-f178.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -1.1 (DKIM_SIGNED, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.128.178 mail-wr0-f178.google.com 209.85.128.178 mail-wr0-f178.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 02/10] 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.32]); Thu, 31 May 2018 10:03:58 +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 | 37 +++++++++++++++++++++++++++++++++++++ api/models.py | 27 ++++----------------------- 2 files changed, 41 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..b1c7d34 --- /dev/null +++ b/api/blobs.py @@ -0,0 +1,37 @@ +#!/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 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 diff --git a/api/models.py b/api/models.py index 2ed4e8f..96798a6 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