implement get_torrent_info

This commit is contained in:
Jimmy Zelinskie 2015-12-31 14:09:50 -05:00
parent a9b7ac6b48
commit 9b0a84c02f
2 changed files with 14 additions and 1 deletions

View file

@ -8,6 +8,9 @@ class DataModelException(Exception):
class BlobDoesNotExist(DataModelException):
pass
class TorrentInfoDoesNotExist(DataModelException):
pass
class InvalidBlobUpload(DataModelException):
pass

View file

@ -2,7 +2,7 @@ import logging
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,
ImageStorageLocation, ImageStorageTransformation, ImageStorageSignature,
ImageStorageSignatureKind, Repository, Namespace, TorrentInfo)
@ -216,3 +216,13 @@ def get_storage_locations(uuid):
def save_torrent_info(storage_object, piece_length, 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