Ejemplo n.º 1
0
    def upload(self, bucket):

        self.lastUpload = 0
        headers = {'Cache-Control': 'max-age=%s' % self.CACHE_EXPIRATION}

        if self.shouldCompress():
            headers['Content-Encoding'] = 'gzip'

        changed = self.checksum() != self.remoteChecksum()

        if changed:

            # Show progress if the file size is big
            progressCallback = None
            progressCallbackCount = int(len(self.payload()) / (1024 * 1024))

            if len(self.payload()) > self.PROGRESS_MIN_SIZE:

                def progressCallback(current, total):
                    if current > self.lastUpload:
                        uploadPercentage = (float(current) /
                                            float(total)) * 100
                        logging.info('+ %s upload progress %.1f%%' %
                                     (self.path, uploadPercentage))
                        self.lastUpload = current

            # Create a new key from the file path and guess the mime type
            key = bucket.new_key(self.path)
            mimeType = mime.guess(self.path)

            if mimeType:
                key.content_type = mimeType

            # Upload the data
            key.set_contents_from_string(self.payload(),
                                         headers,
                                         policy='public-read',
                                         cb=progressCallback,
                                         num_cb=progressCallbackCount)

        op1 = '+' if changed else '-'
        op2 = ' (%s compressed)' % (fileSize(len(
            self.payload()))) if self.shouldCompress() else ''

        logging.info('%s %s - %s%s' %
                     (op1, self.path, fileSize(len(self.data())), op2))

        return {'changed': changed, 'size': len(self.payload())}
Ejemplo n.º 2
0
	def upload(self, bucket):
		
		self.lastUpload = 0
		headers = {'Cache-Control': 'max-age=%s' % self.CACHE_EXPIRATION}
		
		if self.shouldCompress():
			headers['Content-Encoding'] = 'gzip'
		
		changed = self.checksum() != self.remoteChecksum()
		
		if changed:
		
			# Show progress if the file size is big
			progressCallback = None
			progressCallbackCount = int(len(self.payload()) / (1024 * 1024))
		
			if len(self.payload()) > self.PROGRESS_MIN_SIZE:
				def progressCallback(current, total):
					if current > self.lastUpload:
						uploadPercentage = (float(current) / float(total)) * 100
						logging.info('+ %s upload progress %.1f%%' % (self.path, uploadPercentage))
						self.lastUpload = current
			
			# Create a new key from the file path and guess the mime type
			key = bucket.new_key(self.path)
			mimeType = mime.guess(self.path)
			
			if mimeType:
				key.content_type = mimeType
			
			# Upload the data
			key.set_contents_from_string(self.payload(), headers, 
				policy='public-read',
				cb=progressCallback,
				num_cb=progressCallbackCount)
 		
		op1 = '+' if changed else '-'
		op2 = ' (%s compressed)' % (fileSize(len(self.payload()))) if self.shouldCompress() else ''
		
		logging.info('%s %s - %s%s' % (op1, self.path, fileSize(len(self.data())), op2))
		
		return {'changed': changed, 'size': len(self.payload())}
		
		
Ejemplo n.º 3
0
Archivo: file.py Proyecto: hzdg/Cactus
    def upload(self, bucket):

        headers = {'Cache-Control': 'max-age=%s' % self.CACHE_EXPIRATION}

        if self.shouldCompress():
            headers['Content-Encoding'] = 'gzip'

        changed = self.checksum() != self.remoteChecksum()

        if changed:
            key = bucket.new_key(self.path)
            mimeType = mime.guess(self.path)
            if mimeType: key.content_type = mimeType
            key.set_contents_from_string(self.payload(), headers, policy='public-read')

        op1 = '+' if changed else '-'
        op2 = ' (%s compressed)' % (fileSize(len(self.payload()))) if self.shouldCompress() else ''

        logging.info('%s %s - %s%s' % (op1, self.path, fileSize(len(self.data())), op2))

        return {'changed': changed, 'size': len(self.payload())}
Ejemplo n.º 4
0
 def get(self):
     self.set_header("Content-Type", mime.guess("file.js"))
     self.finish(TEMPLATES["js"])
Ejemplo n.º 5
0
 def get_content_type(self):
     return mime.guess(self.absolute_path)
Ejemplo n.º 6
0
 def get(self):
     self.set_header("Content-Type", mime.guess("file.js"))
     self.finish(TEMPLATES["js"])
Ejemplo n.º 7
0
 def get_content_type(self):
     return mime.guess(self.absolute_path)
Ejemplo n.º 8
0
 def guess_type(self, path):
     return mime.guess(path)
Ejemplo n.º 9
0
 def guess_type(self, path):
     return mime.guess(path)
Ejemplo n.º 10
0
    def get_content_type(self):
        # beaufour: total hack to support my paths without ending /
        if self.absolute_path is None or self.path.find(".") == -1:
            return "text/html"

        return mime.guess(self.absolute_path)