示例#1
0
    def receive_data_chunk(self, raw_data, start):
        '''
        Receives a "chunk" of data from the file upload.
        
        ``raw_data is`` a byte string containing the uploaded data.
        
        ``start`` is the position in the file where this raw_data chunk begins.

        The data you return will get fed into the subsequent upload handlers'
        receive_data_chunk methods. In this way, one handler can be a "filter"
        for other handlers.
        
        Return None from receive_data_chunk to sort-circuit remaining upload
        handlers from getting this chunk.. This is useful if you're storing
        the uploaded data yourself and don't want future handlers to store
        a copy of the data.
        
        If you raise a StopUpload or a SkipFile exception, the upload will
        abort or the file will be completely skipped.

        '''
        self.progress += self.chunk_size
        if self.cach_key:
            try:
                percent = min(100, int(100 * self.progress / self.length))
                cache.incr(self.cach_key, percent)
                if settings.DEBUG:
                    logging.debug('uploaded proceeded for %s and filename %s @ %s'
                          % (self.cach_key, self.name, ctime.ctime()))
            except ValueError, e:
                logging.error('Tried to increment a non-existing cache-key;\
                              %s %s' % (self.cach_key, e)) 
示例#2
0
 def _ffmpeg(self, in_file, out_file):
     '''**ffmpeg one-pass CRF**:
     .. code-block:: bash
     
         $ ffmpeg -i input.mov -acodec libfaac -ab 128k -ac 2 -vcodec libx264 \
         -vpre slow -crf 22 -threads 0 output.mp4
     
     **ffmpeg two-pass fast**:
     .. code-block:: bash
     
         ffmpeg -i input.avi -pass 1 -vcodec libx264 -vpre fast_firstpass \
         -b 512k -bt 512k -threads 0 -f rawvideo -an -y /dev/null
         
         ffmpeg -i input.avi -pass 2 -acodec libfaac -ab 128k -ac 2 \
         -vcodec libx264 -vpre fast -b 512k -bt 512k -threads 0 output.mp4
     '''
     ffmpeg = ['ffmpeg',
               '-i', in_file,
               '-acodec', 'libfaac',
               '-ab', '128k',
               '-ac', '2',
               '-vcodec', 'libx264',
               '-vpre', 'slow',
               '-crf', '22',
               '-threads', '0',
               out_file]
     ret = subprocess.call(ffmpeg)
     if ret != 0 or not os.path.exists(out_file):
         logging.error('Conversion error, ffmpeg returned %s' % ret)
         raise OSError()
     return out_file
示例#3
0
def outdate_ranking(sender, **kwargs):
	try:
		server = Server.objects.get()
	except MultipleObjectsReturned:
		if logging:
			logging.error("Multiple servers found")
	except ObjectDoesNotExist:
		if logging:
			logging.error("No configured server")
	else:
		server.ranking_outdated = True
		server.save()
示例#4
0
 def jsonify(*arg, **kw):
     status = 200
     try:
         res = fn(*arg, **kw)
         if res is None:
             res = {}
     except Exception, e:
         status = 500
         traceback.print_exc()
         res = {'error': {'type': sys.modules[type(e).__module__].__name__ + "." + type(e).__name__,
                          'description': str(e),
                          'traceback': traceback.format_exc()}}
         logging.error("%s: %s" % (str(e), res['error']['type']))