# Path: OGRgeoConverter/filesystem/filemanager.py
# def store_uploaded_file(job_id, file_data, file_name):
# def rename_file(folder_path, old_file_name, new_file_name):
# def create_job_folders(job_id):
# def remove_old_folders():
# def get_file_count(folder_path):
# def get_conversion_job_folder():
# def get_folder_path(job_id):
# def get_upload_folder_path(job_id):
# def get_extract_folder_path(job_id):
# def get_output_folder_path(job_id):
# def get_download_folder_path(job_id):
# def get_download_file_path(job_id):
# def download_file_exists(job_id):
# 
# Path: OGRgeoConverter/models.py
# class DownloadItem(models.Model):
#     job_identifier = models.ForeignKey(JobIdentifier)
# 
#     download_caption = models.CharField(max_length=100)
#     is_downloaded = models.BooleanField()
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_download_items'
# 
#     @staticmethod
#     def get_download_item(job_identifier):
#         return DownloadItem.objects.filter(job_identifier=job_identifier)
# 
#     @staticmethod
#     def get_download_items(session_key):
#         return DownloadItem.objects.filter(
#             job_identifier__session_key=session_key).order_by(
#             'job_identifier__creation_time').reverse()


import os
from django.core.servers.basehttp import FileWrapper
from OGRgeoConverter.filesystem import filemanager
from OGRgeoConverter.models import DownloadItem
    def remove_download_item(self):
        download_item = self.__get_download_item_query_set()
        download_item.delete()

    def get_download_file_information(self):
        '''
        Returns a download file in a wrapper and its name and size
        '''

        file_path = filemanager.get_download_file_path(
            self.__job_identifier.job_id)

        if self.download_file_exists():
            wrapper = FileWrapper(open(file_path, 'rb'))
            file_name = os.path.split(file_path)[1]
            file_size = os.path.getsize(file_path)
            return wrapper, file_name, file_size
        else:
            return None

    def get_download_file_size(self):
        file_path = filemanager.get_download_file_path(
            self.__job_identifier.job_id)

        if self.download_file_exists():
            return os.path.getsize(file_path)
        else:
            return -1

    def download_file_exists(self):

# Path: OGRgeoConverter/filesystem/filemanager.py
# def store_uploaded_file(job_id, file_data, file_name):
# def rename_file(folder_path, old_file_name, new_file_name):
# def create_job_folders(job_id):
# def remove_old_folders():
# def get_file_count(folder_path):
# def get_conversion_job_folder():
# def get_folder_path(job_id):
# def get_upload_folder_path(job_id):
# def get_extract_folder_path(job_id):
# def get_output_folder_path(job_id):
# def get_download_folder_path(job_id):
# def get_download_file_path(job_id):
# def download_file_exists(job_id):
# 
# Path: OGRgeoConverter/models.py
# class DownloadItem(models.Model):
#     job_identifier = models.ForeignKey(JobIdentifier)
# 
#     download_caption = models.CharField(max_length=100)
#     is_downloaded = models.BooleanField()
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_download_items'
# 
#     @staticmethod
#     def get_download_item(job_identifier):
#         return DownloadItem.objects.filter(job_identifier=job_identifier)
# 
#     @staticmethod
#     def get_download_items(session_key):
#         return DownloadItem.objects.filter(
#             job_identifier__session_key=session_key).order_by(
#             'job_identifier__creation_time').reverse()


# Path: OGRgeoConverter/modelhandlers/downloadhandler.py
import os
from django.core.servers.basehttp import FileWrapper
from OGRgeoConverter.filesystem import filemanager
from OGRgeoConverter.models import DownloadItem

    def remove_download_item(self):
        download_item = self.__get_download_item_query_set()
        download_item.delete()

    def get_download_file_information(self):
        '''
        Returns a download file in a wrapper and its name and size
        '''

        file_path = filemanager.get_download_file_path(
            self.__job_identifier.job_id)

        if self.download_file_exists():
            wrapper = FileWrapper(open(file_path, 'rb'))
            file_name = os.path.split(file_path)[1]
            file_size = os.path.getsize(file_path)
            return wrapper, file_name, file_size
        else:
            return None

    def get_download_file_size(self):
        file_path = filemanager.get_download_file_path(
            self.__job_identifier.job_id)

        if self.download_file_exists():
            return os.path.getsize(file_path)
        else:
            return -1

    def download_file_exists(self):

        return filemanager.download_file_exists(self.__job_identifier.job_id)