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 <famz@redhat.com>
+# Paolo Bonzini <pbonzini@redhat.com>
+#
+# This work is licensed under the MIT License. Please see the LICENSE file 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=None):
+ if not name:
+ name = str(uuid.uuid4())
+ fn = 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 = 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 1753c6b..0545b80 100644
--- a/api/models.py
+++ b/api/models.py
@@ -10,39 +10,20 @@
from collections import namedtuple
-import os
import json
import datetime
import re
-import uuid
-import logging
-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
-def save_blob(data, name=None):
- if not name:
- name = str(uuid.uuid4())
- fn = 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 = 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
class Project(models.Model):
name = models.CharField(max_length=1024, db_index=True, unique=True,
--
2.17.0
_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel