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())}
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())}
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())}
def get(self): self.set_header("Content-Type", mime.guess("file.js")) self.finish(TEMPLATES["js"])
def get_content_type(self): return mime.guess(self.absolute_path)
def guess_type(self, path): return mime.guess(path)
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)