Beispiel #1
0
    def manifest_updated(self, manifest, upload):
        """The manifest has updated, update the version and file.

        This is intended to be used for hosted apps only, which have only a
        single version and a single file.
        """
        data = parse_addon(upload, self)
        version = self.versions.latest()
        version.update(version=data['version'])
        path = smart_path(nfd_str(upload.path))
        file = version.files.latest()
        file.filename = file.generate_filename(extension='.webapp')
        file.size = int(max(1, round(storage.size(path) / 1024, 0)))
        file.hash = (file.generate_hash(path) if
                     waffle.switch_is_active('file-hash-paranoia') else
                     upload.hash)
        log.info('Updated file hash to %s' % file.hash)
        file.save()

        # Move the uploaded file from the temp location.
        copy_stored_file(path, os.path.join(version.path_prefix,
                                            nfd_str(file.filename)))
        log.info('[Webapp:%s] Copied updated manifest to %s' % (
            self, version.path_prefix))

        amo.log(amo.LOG.MANIFEST_UPDATED, self)
Beispiel #2
0
    def manifest_updated(self, manifest, upload):
        """The manifest has updated, update the version and file.

        This is intended to be used for hosted apps only, which have only a
        single version and a single file.
        """
        data = parse_addon(upload, self)
        version = self.versions.latest()
        version.update(version=data['version'])
        path = smart_path(nfd_str(upload.path))
        file = version.files.latest()
        file.filename = file.generate_filename(extension='.webapp')
        file.size = storage.size(path)
        file.hash = (file.generate_hash(path)
                     if waffle.switch_is_active('file-hash-paranoia') else
                     upload.hash)
        log.info('Updated file hash to %s' % file.hash)
        file.save()

        # Move the uploaded file from the temp location.
        copy_stored_file(
            path, os.path.join(version.path_prefix, nfd_str(file.filename)))
        log.info('[Webapp:%s] Copied updated manifest to %s' %
                 (self, version.path_prefix))

        amo.log(amo.LOG.MANIFEST_UPDATED, self)
Beispiel #3
0
 def upload(self, name):
     v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={}))
     fname = nfd_str(self.xpi_path(name))
     if not storage.exists(fname):
         with storage.open(fname, 'w') as fs:
             copyfileobj(open(fname), fs)
     d = dict(path=fname, name='%s.xpi' % name,
              hash='sha256:%s' % name, validation=v)
     return FileUpload.objects.create(**d)
Beispiel #4
0
    def upload(self, name):
        if os.path.splitext(name)[-1] not in ['.xml', '.xpi', '.jar']:
            name = name + '.xpi'

        v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={}))
        fname = nfd_str(self.xpi_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)
Beispiel #5
0
    def upload(self, name):
        if os.path.splitext(name)[-1] not in [".xml", ".xpi", ".jar"]:
            name = name + ".xpi"

        v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={}))
        fname = nfd_str(self.xpi_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)
Beispiel #6
0
    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)
Beispiel #7
0
    def manifest_updated(self, manifest, upload):
        """The manifest has updated, update the version and file.

        This is intended to be used for hosted apps only, which have only a
        single version and a single file.
        """
        data = parse_addon(upload, self)
        version = self.versions.latest()
        version.update(version=data["version"])
        path = smart_path(nfd_str(upload.path))
        file = version.files.latest()
        file.filename = file.generate_filename(extension=".webapp")
        file.size = storage.size(path)
        file.hash = file.generate_hash(path)
        log.info("Updated file hash to %s" % file.hash)
        file.save()

        # Move the uploaded file from the temp location.
        copy_stored_file(path, os.path.join(version.path_prefix, nfd_str(file.filename)))
        log.info("[Webapp:%s] Copied updated manifest to %s" % (self, version.path_prefix))

        amo.log(amo.LOG.MANIFEST_UPDATED, self)
Beispiel #8
0
    def upload(self, name):
        if os.path.splitext(name)[-1] not in ['.xml', '.xpi', '.jar']:
            name = name + '.xpi'

        v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={},
                            signing_summary={'trivial': 0, 'low': 0,
                                             'medium': 0, 'high': 0},
                            passed_auto_validation=1))
        fname = nfd_str(self.xpi_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)
Beispiel #9
0
def replace_xpi(file_, new_xpi, version):
    old_filename = file_.filename
    old_filepath = file_.file_path
    # Now that we have a new version, make a new filename.
    file_.filename = file_.generate_filename(extension='.xpi')
    file_.hash = file_.generate_hash(new_xpi)
    file_.size = int(max(1, round(new_xpi.size / 1024, 0)))  # kB
    file_.save()
    destinations = [path.path(version.path_prefix)]
    if file_.status in amo.MIRROR_STATUSES:
        destinations.append(path.path(version.mirror_path_prefix))
    for dest in destinations:
        if not dest.exists():
            dest.makedirs()
        file_dest = dest / nfd_str(file_.filename)
        if os.path.exists(file_dest):
            backup_file(file_dest)
        new_xpi.copyfile(file_dest)
        _log('file: %s [%s] at %s -> %s at %s' %
             (old_filename, file_.pk, old_filepath, file_.filename, file_dest))
Beispiel #10
0
def replace_xpi(file_, new_xpi, version):
    old_filename = file_.filename
    old_filepath = file_.file_path
    # Now that we have a new version, make a new filename.
    file_.filename = file_.generate_filename(extension='.xpi')
    file_.hash = file_.generate_hash(new_xpi)
    file_.size = int(max(1, round(new_xpi.size / 1024, 0)))  # kB
    file_.save()
    destinations = [path.path(version.path_prefix)]
    if file_.status in amo.MIRROR_STATUSES:
        destinations.append(path.path(version.mirror_path_prefix))
    for dest in destinations:
        if not dest.exists():
            dest.makedirs()
        file_dest = dest / nfd_str(file_.filename)
        if os.path.exists(file_dest):
            backup_file(file_dest)
        new_xpi.copyfile(file_dest)
        _log('file: %s [%s] at %s -> %s at %s' % (old_filename,
                                                  file_.pk, old_filepath,
                                                  file_.filename,
                                                  file_dest))