Beispiel #1
0
def online_decoding_single(lan='ENGLISH'):
    
    lattice  = None    

    # get File from the request list
    wavef = request.files['wave']
    wavefm = FileManager(wavef)

    ext = ', '.join(FileManager.ALLOWED_EXTENSIONS)
    fileNames = wavef.filename

    #save file in local app/tmp directory
    wavefm.save_tmp_tarfile()

    print '\ndecoding in progress\n'

    if not wavefm.isValid:
        return ( 'Invalid file extension error. \n' \
        + 'Only the following extensions are valid: [ {0} ] \n' \
        + 'File names = [ {1} ] \n' \
        + 'language = [ {2} ]' ).format(ext, fileNames, lan)

    '''Here we youd recive a file that will be sent back to the user'''
    lattice = onlineDecoding( [wavefm] , lan )

    print 'File ready at dir: ' + lattice + '\n'
    
    

    return  getFile(lattice)
Beispiel #2
0
def saveFile():
    file = request.files['save']

    savefm = FileManager(file)
    savefm.save_tmp_file()
    #file.save('/home/dev/' + savefm.filename)
    return 'File saved!'
Beispiel #3
0
def online_decoding_single_verbose(lan='ENGLISH'):

    lattice  = None

    arkf = request.files['ark']
    scpf = request.files['scp']
    wavef = request.files['wave']

    arkfm = FileManager(arkf)
    scpfm = FileManager(scpf)
    wavefm = FileManager(wavef)

    ext = ', '.join(FileManager.ALLOWED_EXTENSIONS)
    fileNames = ', '.join([arkf.filename, scpf.filename, wavef.filename])

    arkfm.save_tmp_file()
    scpfm.save_tmp_file()
    wavefm.save_tmp_tarfile()

    print '\ndecoding in progress\n'

    if not arkfm.isValid or not scpfm.isValid or not wavefm.isValid:
        return ( 'Invalid file extension error. \n' \
        + 'Only the following extensions are valid: [ {0} ] \n' \
        + 'File names = [ {1} ] \n' \
        + 'language = [ {2} ]' ).format(ext, fileNames, lan)

    '''Here we youd recive a file that will be sent back to the user'''
    lattice = onlineDecoding(arkfm, scpfm, wavefm, lan)

    print lattice

    return getFile(lattice)
Beispiel #4
0
 def _delete_files(self, item):
     for file_col in self.get_file_column_list():
         if self.is_file(file_col):
             if getattr(item, file_col):
                 fm = FileManager()
                 fm.delete_file(getattr(item, file_col))
     for file_col in self.get_image_column_list():
         if self.is_image(file_col):
             if getattr(item, file_col):
                 im = ImageManager()
                 im.delete_file(getattr(item, file_col))
Beispiel #5
0
 def _add_files(self, this_request, item):
     fm = FileManager()
     im = ImageManager()
     for file_col in this_request.files:
         if self.is_file(file_col):
             fm.save_file(this_request.files[file_col],
                          getattr(item, file_col))
     for file_col in this_request.files:
         if self.is_image(file_col):
             im.save_file(this_request.files[file_col],
                          getattr(item, file_col))
Beispiel #6
0
def online_decode_bulk(lan='ENGLISH'):
    
    wavef = request.files['wave']
    wavefm = FileManager(wavef)
   
    ext = ', '.join(FileManager.ALLOWED_EXTENSIONS)
    fileNames = ', '.join([wavef.filename])

    '''Save tar file and uncompress=True'''
    files =  wavefm.save_tmp_tarfile(True)

    print '\ndecoding in progress\n'

    if not wavefm.isValid:
        return ( 'Invalid file extension error. \n' \
        + 'Only the following extensions are valid: [ {0} ] \n' \
        + 'File names = [ {1} ] \n' \
        + 'language = [ {2} ]' ).format(ext, fileNames, lan)      
        
    '''Here we youd recive a file that will be sent back to the user'''    
    tarfile = onlineDecoding( files, lan)    
       
    return getFile(tarfile)
Beispiel #7
0
    def __init__(self,
                 label=None,
                 validators=None,
                 filemanager=None,
                 **kwargs):
        """
            Constructor.

            :param label:
                Display label
            :param validators:
                Validators
        """

        self.filemanager = filemanager or FileManager()
        self._should_delete = False

        super(FileUploadField, self).__init__(label, validators, **kwargs)