implement get_torrent_info
This commit is contained in:
parent
a9b7ac6b48
commit
9b0a84c02f
2 changed files with 14 additions and 1 deletions
|
@ -8,6 +8,9 @@ class DataModelException(Exception):
|
||||||
class BlobDoesNotExist(DataModelException):
|
class BlobDoesNotExist(DataModelException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class TorrentInfoDoesNotExist(DataModelException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class InvalidBlobUpload(DataModelException):
|
class InvalidBlobUpload(DataModelException):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -2,7 +2,7 @@ import logging
|
||||||
|
|
||||||
from peewee import JOIN_LEFT_OUTER, fn, SQL
|
from peewee import JOIN_LEFT_OUTER, fn, SQL
|
||||||
|
|
||||||
from data.model import config, db_transaction, InvalidImageException
|
from data.model import config, db_transaction, InvalidImageException, TorrentInfoDoesNotExist
|
||||||
from data.database import (ImageStorage, Image, DerivedStorageForImage, ImageStoragePlacement,
|
from data.database import (ImageStorage, Image, DerivedStorageForImage, ImageStoragePlacement,
|
||||||
ImageStorageLocation, ImageStorageTransformation, ImageStorageSignature,
|
ImageStorageLocation, ImageStorageTransformation, ImageStorageSignature,
|
||||||
ImageStorageSignatureKind, Repository, Namespace, TorrentInfo)
|
ImageStorageSignatureKind, Repository, Namespace, TorrentInfo)
|
||||||
|
@ -216,3 +216,13 @@ def get_storage_locations(uuid):
|
||||||
|
|
||||||
def save_torrent_info(storage_object, piece_length, pieces):
|
def save_torrent_info(storage_object, piece_length, pieces):
|
||||||
TorrentInfo.create(storage=storage_object, piece_length=piece_length, pieces=pieces)
|
TorrentInfo.create(storage=storage_object, piece_length=piece_length, pieces=pieces)
|
||||||
|
|
||||||
|
def get_torrent_info(blob):
|
||||||
|
try:
|
||||||
|
return (TorrentInfo
|
||||||
|
.select()
|
||||||
|
.join(ImageStorage)
|
||||||
|
.where(blob.id == ImageStorage.id)
|
||||||
|
.get())
|
||||||
|
except TorrentInfo.DoesNotExist:
|
||||||
|
raise TorrentInfoDoesNotExist
|
||||||
|
|
Reference in a new issue