# Path: repositories/gae/blob_dataset.py
# class BlobDataset(Dataset):
# 
#     filename = ndb.StringProperty()
#     blob_key = ndb.BlobKeyProperty()
# 
#     @classmethod
#     def create(cls, blob_key, **kwargs):
# 
#         blob_key = blob_key
#         filename = kwargs.get('filename')
#         rows = kwargs.get('rows', 5)
#         bands = kwargs.get('bands', 40)
#         buckets_per_band = kwargs.get('buckets_per_band', 100)
#         shingle_type = kwargs.get('shingle_type', 'c4')
#         minhash_modulo = kwargs.get('minhash_modulo', 5000)
# 
#         max_hashes = calculate_max_hashes(rows, bands)
#         dataset = cls.get(blob_key)
# 
#         if not dataset:
#             dataset = BlobDataset(
#                               filename = filename,
#                               blob_key = blob_key,
#                               random_seeds = get_random_bits(max_hashes),
#                               rows = rows,
#                               bands = bands,
#                               buckets_per_band = buckets_per_band,
#                               shingle_type = shingle_type,
#                               minhash_modulo = minhash_modulo)
#         else:
#             dataset.filename = filename
# 
#         return dataset.put()
# 
#     @classmethod
#     def get(cls, key):
#         return Dataset.query(cls.blob_key == key).get()


import logging
from repositories.gae.blob_dataset import BlobDataset
from google.appengine.ext.webapp import blobstore_handlers

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        upload_files = self.get_uploads("file")
        blob_info = upload_files[0]
        blob_key = blob_info.key()

        logging.info('(REFACTORED) filename %s key %s', blob_info.filename, blob_key)


# Path: repositories/gae/blob_dataset.py
# class BlobDataset(Dataset):
# 
#     filename = ndb.StringProperty()
#     blob_key = ndb.BlobKeyProperty()
# 
#     @classmethod
#     def create(cls, blob_key, **kwargs):
# 
#         blob_key = blob_key
#         filename = kwargs.get('filename')
#         rows = kwargs.get('rows', 5)
#         bands = kwargs.get('bands', 40)
#         buckets_per_band = kwargs.get('buckets_per_band', 100)
#         shingle_type = kwargs.get('shingle_type', 'c4')
#         minhash_modulo = kwargs.get('minhash_modulo', 5000)
# 
#         max_hashes = calculate_max_hashes(rows, bands)
#         dataset = cls.get(blob_key)
# 
#         if not dataset:
#             dataset = BlobDataset(
#                               filename = filename,
#                               blob_key = blob_key,
#                               random_seeds = get_random_bits(max_hashes),
#                               rows = rows,
#                               bands = bands,
#                               buckets_per_band = buckets_per_band,
#                               shingle_type = shingle_type,
#                               minhash_modulo = minhash_modulo)
#         else:
#             dataset.filename = filename
# 
#         return dataset.put()
# 
#     @classmethod
#     def get(cls, key):
#         return Dataset.query(cls.blob_key == key).get()


# Path: handlers/gae/upload_handler.py
import logging
from repositories.gae.blob_dataset import BlobDataset
from google.appengine.ext.webapp import blobstore_handlers


class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        upload_files = self.get_uploads("file")
        blob_info = upload_files[0]
        blob_key = blob_info.key()

        logging.info('(REFACTORED) filename %s key %s', blob_info.filename, blob_key)


        BlobDataset.create(blob_key, filename=blob_info.filename)