def upload(self, addon, path): """Create FileUpload instance from local file.""" self.info('Creating FileUpload...') package_file = open(path) package_size = os.stat(path).st_size upload = FileUpload() upload.user = addon.authors.all()[0] upload.add_file(package_file.read(), 'marketplace-package.zip', package_size, is_webapp=True) self.info('Created FileUpload %s.' % upload) return upload
chunks = [] size = 0 for chunk in req.iter_content(settings.LANGPACK_MAX_SIZE): size += len(chunk) # `requests` doesn't respect the Content-Length header # so we need to check twice. if size > settings.LANGPACK_MAX_SIZE: raise Exception('Response to big') chunks.append(chunk) except Exception, e: log.error('[@None] Error fetching "%s" language pack: %s' % (xpi, e)) continue upload = FileUpload() upload.add_file(chunks, xpi, size) # Activate the correct locale for the language pack so it # will be used as the add-on's default locale if available. translation.activate(lang) guid = '*****@*****.**' % lang try: addon = Addon.objects.get(guid=guid) except Addon.DoesNotExist: addon = None try: data = parse_addon(upload, addon) if data['guid'] != guid: