def signed_file_path(self): """Path to the signed archive for this version, on public storage. May not exist if the version has not been reviewed yet.""" prefix = os.path.join(settings.SIGNED_EXTENSIONS_PATH, str(self.extension.pk)) return os.path.join(prefix, nfd_str(self.filename))
def reviewer_signed_file_path(self): """Path to the reviewer-specific signed archive for this version, on private storage. May not exist if the version has not been signed for review yet.""" prefix = os.path.join(settings.EXTENSIONS_PATH, str(self.extension.pk), 'reviewers') return os.path.join(prefix, nfd_str(self.filename))
def reviewer_signed_file_path(self): """Path to the reviewer-specific signed archive for this version, on private storage. May not exist if the version has not been signed for review yet.""" prefix = os.path.join( settings.EXTENSIONS_PATH, str(self.extension.pk), 'reviewers') return os.path.join(prefix, nfd_str(self.filename))
def upload(self, name, **kwargs): if os.path.splitext(name)[-1] not in [".webapp", ".zip"]: name = name + ".zip" v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={})) fname = nfd_str(self.packaged_app_path(name)) if not storage.exists(fname): with storage.open(fname, "w") as fs: copyfileobj(open(fname), fs) data = {"path": fname, "name": name, "hash": "sha256:%s" % name, "validation": v} data.update(**kwargs) return FileUpload.objects.create(**data)
def upload(self, name): if os.path.splitext(name)[-1] not in ['.webapp', '.zip']: name = name + '.zip' v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={})) fname = nfd_str(self.packaged_app_path(name)) if not storage.exists(fname): with storage.open(fname, 'w') as fs: copyfileobj(open(fname), fs) d = dict(path=fname, name=name, hash='sha256:%s' % name, validation=v) return FileUpload.objects.create(**d)
def handle_file_operations(self, upload): """Copy the file attached to a FileUpload to the Extension instance.""" upload.path = smart_path(nfd_str(upload.path)) if private_storage.exists(self.file_path): # The filename should not exist. If it does, it means we are trying # to re-upload the same version. This should have been caught # before, so just raise an exception. raise RuntimeError( 'Trying to upload a file to a destination that already exists') # Copy file from fileupload. This uses private_storage for now as the # unreviewed, unsigned filename is private. copy_stored_file( upload.path, self.file_path, src_storage=private_storage, dst_storage=private_storage)
def handle_file_operations(self, upload): """Copy the file attached to a FileUpload to the Extension instance.""" upload.path = smart_path(nfd_str(upload.path)) if not self.slug: raise RuntimeError( 'Trying to upload a file belonging to a slugless extension') if private_storage.exists(self.file_path): # The filename should not exist. If it does, it means we are trying # to re-upload the same version. This should have been caught # before, so just raise an exception. raise RuntimeError( 'Trying to upload a file to a destination that already exists') # Copy file from fileupload. This uses private_storage for now as the # unreviewed, unsigned filename is private. copy_stored_file(upload.path, self.file_path)
def upload(self, name, **kwargs): if os.path.splitext(name)[-1] not in ['.webapp', '.zip']: name = name + '.zip' v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={})) fname = nfd_str(self.packaged_app_path(name)) if not local_storage.exists(fname): raise ValueError('The file %s does not exist :(', fname) if not private_storage.exists(fname): copy_to_storage(fname) data = { 'path': fname, 'name': name, 'hash': 'sha256:%s' % name, 'validation': v } data.update(**kwargs) return FileUpload.objects.create(**data)
def handle_file_operations(self, upload): """Handle file operations on an instance by using the FileUpload object passed to set filename, file_version on the LangPack instance, and moving the temporary file to its final destination.""" upload.path = smart_path(nfd_str(upload.path)) if not self.uuid: self.reset_uuid() if storage.exists(self.filename): # The filename should not exist. If it does, it means we are trying # to re-upload the same version. This should have been caught # before, so just raise an exception. raise RuntimeError( 'Trying to upload a file to a destination that already exists') self.file_version = self.file_version + 1 # Because we are only dealing with langpacks generated by Mozilla atm, # we can directly sign the file before copying it to its final # destination. The filename changes with the version, so when a new # file is uploaded we should still be able to serve the old one until # the new info is stored in the db. self.sign_and_move_file(upload)
def file_path(self): prefix = os.path.join(settings.ADDONS_PATH, 'extensions', str(self.pk)) return os.path.join(prefix, nfd_str(self.filename))
def signed_file_path(self): prefix = os.path.join(settings.SIGNED_EXTENSIONS_PATH, str(self.extension.pk)) return os.path.join(prefix, nfd_str(self.filename))
def file_path(self): """Path to the unsigned archive for this version, on private storage.""" prefix = os.path.join(settings.EXTENSIONS_PATH, str(self.extension.pk)) return os.path.join(prefix, nfd_str(self.filename))
def file_path(self): return os.path.join(self.path_prefix, nfd_str(self.filename))