コード例 #1
0
ファイル: tasks.py プロジェクト: piyushmittal25/addons-server
def approve_rereview(theme):
    """Replace original theme with pending theme on filesystem."""
    # If reuploaded theme, replace old theme design.
    storage = LocalFileStorage()
    rereview = theme.rereviewqueuetheme_set.all()
    reupload = rereview[0]

    if reupload.header_path != reupload.theme.header_path:
        create_persona_preview_images(
            src=reupload.header_path,
            full_dst=[
                reupload.theme.thumb_path,
                reupload.theme.icon_path],
            set_modified_on=reupload.theme.addon.serializable_reference())

        if not reupload.theme.is_new():
            # Legacy themes also need a preview_large.jpg.
            # Modern themes use preview.png for both thumb and preview so there
            # is no problem there.
            copy_stored_file(reupload.theme.thumb_path,
                             reupload.theme.preview_path, storage=storage)

        move_stored_file(
            reupload.header_path, reupload.theme.header_path, storage=storage)

    theme = reupload.theme
    rereview.delete()
    theme_checksum(theme)
    theme.addon.increment_theme_version_number()
コード例 #2
0
def repack_fileupload(upload_pk):
    log.info('Starting task to repackage FileUpload %s', upload_pk)
    upload = FileUpload.objects.get(pk=upload_pk)
    # When a FileUpload is created and a file added to it, if it's a xpi/zip,
    # it should be move to upload.path, and it should have a .xpi extension,
    # so we only need to care about that extension here.
    # We don't trust upload.name: it's the original filename as used by the
    # developer, so it could be something else.
    if upload.path.endswith('.xpi'):
        try:
            tempdir = extract_zip(upload.path)
        except Exception:
            # Something bad happened, maybe we couldn't parse the zip file.
            # This task should have a on_error attached when called by
            # Validator(), so we can just raise and the developer will get a
            # generic error message.
            log.exception('Could not extract upload %s for repack.', upload_pk)
            raise
        log.info('Zip from upload %s extracted, repackaging', upload_pk)
        file_ = tempfile.NamedTemporaryFile(suffix='.zip', delete=False)
        shutil.make_archive(os.path.splitext(file_.name)[0], 'zip', tempdir)
        with open(file_.name, 'rb') as f:
            upload.hash = 'sha256:%s' % get_sha256(f)
        log.info('Zip from upload %s repackaged, moving file back', upload_pk)
        move_stored_file(file_.name, upload.path)
        upload.save()
    else:
        log.info('Not repackaging upload %s, it is not a xpi file.', upload_pk)
コード例 #3
0
def approve_rereview(theme):
    """Replace original theme with pending theme on filesystem."""
    # If reuploaded theme, replace old theme design.
    storage = LocalFileStorage()
    rereview = theme.rereviewqueuetheme_set.all()
    reupload = rereview[0]

    if reupload.header_path != reupload.theme.header_path:
        create_persona_preview_images(
            src=reupload.header_path,
            full_dst=[reupload.theme.thumb_path, reupload.theme.icon_path],
            set_modified_on=reupload.theme.addon.serializable_reference())

        if not reupload.theme.is_new():
            # Legacy themes also need a preview_large.jpg.
            # Modern themes use preview.png for both thumb and preview so there
            # is no problem there.
            copy_stored_file(reupload.theme.thumb_path,
                             reupload.theme.preview_path,
                             storage=storage)

        move_stored_file(reupload.header_path,
                         reupload.theme.header_path,
                         storage=storage)

    theme = reupload.theme
    rereview.delete()
    theme_checksum(theme)
    theme.addon.increment_theme_version_number()
コード例 #4
0
    def move_file(self, source_path, destination_path, log_message):
        """Move a file from `source_path` to `destination_path` and delete the
        source directory if it's empty once the file has been successfully
        moved.

        Meant to move files from/to the guarded file path as they are disabled
        or re-enabled.

        IOError and UnicodeEncodeError are caught and logged."""
        log_message = force_str(log_message)
        try:
            if storage.exists(source_path):
                source_parent_path = os.path.dirname(source_path)
                log.info(
                    log_message.format(source=source_path,
                                       destination=destination_path))
                move_stored_file(source_path, destination_path)
                # Now that the file has been deleted, remove the directory if
                # it exists to prevent the main directory from growing too
                # much (#11464)
                remaining_dirs, remaining_files = storage.listdir(
                    source_parent_path)
                if len(remaining_dirs) == len(remaining_files) == 0:
                    storage.delete(source_parent_path)
        except (UnicodeEncodeError, IOError):
            msg = 'Move Failure: {} {}'.format(source_path, destination_path)
            log.exception(msg)
コード例 #5
0
ファイル: models.py プロジェクト: mozilla/addons-server
    def move_file(self, source_path, destination_path, log_message):
        """Move a file from `source_path` to `destination_path` and delete the
        source directory if it's empty once the file has been successfully
        moved.

        Meant to move files from/to the guarded file path as they are disabled
        or re-enabled.

        IOError and UnicodeEncodeError are caught and logged."""
        log_message = force_text(log_message)
        try:
            if storage.exists(source_path):
                source_parent_path = os.path.dirname(source_path)
                log.info(log_message.format(
                    source=source_path, destination=destination_path))
                move_stored_file(source_path, destination_path)
                # Now that the file has been deleted, remove the directory if
                # it exists to prevent the main directory from growing too
                # much (#11464)
                remaining_dirs, remaining_files = storage.listdir(
                    source_parent_path)
                if len(remaining_dirs) == len(remaining_files) == 0:
                    storage.delete(source_parent_path)
        except (UnicodeEncodeError, IOError):
            msg = u'Move Failure: {} {}'.format(source_path, destination_path)
            log.exception(msg)
コード例 #6
0
ファイル: models.py プロジェクト: darktrojan/addons-server
 def mv(cls, src, dst, msg):
     """Move a file from src to dst."""
     try:
         if storage.exists(src):
             log.info(msg % (src, dst))
             move_stored_file(src, dst)
     except UnicodeEncodeError:
         log.error('Move Failure: %s %s' % (smart_str(src), smart_str(dst)))
コード例 #7
0
 def mv(cls, src, dst, msg):
     """Move a file from src to dst."""
     try:
         if storage.exists(src):
             log.info(msg % (src, dst))
             move_stored_file(src, dst)
     except UnicodeEncodeError:
         log.error('Move Failure: %s %s' % (smart_str(src), smart_str(dst)))
コード例 #8
0
ファイル: models.py プロジェクト: mstriemer/olympia
 def mv(cls, src, dst, msg):
     """Move a file from src to dst."""
     try:
         if storage.exists(src):
             log.info(msg % (src, dst))
             move_stored_file(src, dst)
     except UnicodeEncodeError:
         msg = 'Move Failure: %s %s' % (force_bytes(src), force_bytes(dst))
         log.error(msg)
コード例 #9
0
 def mv(cls, src, dst, msg):
     """Move a file from src to dst."""
     try:
         if storage.exists(src):
             log.info(msg % (src, dst))
             move_stored_file(src, dst)
     except UnicodeEncodeError:
         msg = 'Move Failure: %s %s' % (force_bytes(src), force_bytes(dst))
         log.error(msg)
コード例 #10
0
ファイル: models.py プロジェクト: kumar303/addons-server
 def move_file(self, source, destination, log_message):
     """Move a file from `source` to `destination`."""
     log_message = force_text(log_message)
     try:
         if storage.exists(source):
             log.info(
                 log_message.format(source=source, destination=destination))
             move_stored_file(source, destination)
     except (UnicodeEncodeError, IOError):
         msg = u'Move Failure: {} {}'.format(source, destination)
         log.exception(msg)
コード例 #11
0
ファイル: models.py プロジェクト: diox/olympia
 def move_file(self, source, destination, log_message):
     """Move a file from `source` to `destination`."""
     log_message = force_text(log_message)
     try:
         if storage.exists(source):
             log.info(log_message.format(
                 source=source, destination=destination))
             move_stored_file(source, destination)
     except (UnicodeEncodeError, IOError):
         msg = u'Move Failure: {} {}'.format(source, destination)
         log.exception(msg)
コード例 #12
0
ファイル: models.py プロジェクト: eviljeff/olympia
    def move_file(self, source, destination, log_message):
        """Move a file from `source` to `destination`."""
        # Make sure we are passing bytes to Python's io system.
        source, destination = force_bytes(source), force_bytes(destination)

        try:
            if storage.exists(source):
                log.info(log_message.format(
                    source=source, destination=destination))
                move_stored_file(source, destination)
        except (UnicodeEncodeError, IOError):
            msg = 'Move Failure: {} {}'.format(
                force_bytes(source), force_bytes(destination))
            log.exception(msg)
コード例 #13
0
ファイル: models.py プロジェクト: thundernest/addons-server
    def move_file(self, source, destination, log_message):
        """Move a file from `source` to `destination`."""
        # Make sure we are passing bytes to Python's io system.
        source, destination = force_bytes(source), force_bytes(destination)

        try:
            if storage.exists(source):
                log.info(
                    log_message.format(source=source, destination=destination))
                move_stored_file(source, destination)
        except (UnicodeEncodeError, IOError):
            msg = 'Move Failure: {} {}'.format(force_bytes(source),
                                               force_bytes(destination))
            log.exception(msg)
コード例 #14
0
def repack_fileupload(results, upload_pk):
    log.info('Starting task to repackage FileUpload %s', upload_pk)
    upload = FileUpload.objects.get(pk=upload_pk)
    # When a FileUpload is created and a file added to it, if it's a xpi/zip,
    # it should be move to upload.path, and it should have a .xpi extension,
    # so we only need to care about that extension here.
    # We don't trust upload.name: it's the original filename as used by the
    # developer, so it could be something else.
    if upload.path.endswith('.xpi'):
        timer = StopWatch('files.tasks.repack_fileupload.')
        timer.start()
        # tempdir must *not* be on TMP_PATH, we want local fs instead. It will be
        # deleted automatically once we exit the context manager.
        with tempfile.TemporaryDirectory(prefix='repack_fileupload_extract') as tempdir:
            try:
                extract_zip(upload.path, tempdir=tempdir)
            except Exception as exc:
                # Something bad happened, maybe we couldn't parse the zip file.
                # @validation_task should ensure the exception is caught and
                # transformed in a generic error message for the developer, so we
                # just log it and re-raise.
                log.exception(
                    'Could not extract upload %s for repack.', upload_pk, exc_info=exc
                )
                raise
            timer.log_interval('1.extracted')
            log.info('Zip from upload %s extracted, repackaging', upload_pk)
            # We'll move the file to its final location below with move_stored_file(),
            # so don't let tempfile delete it.
            file_ = tempfile.NamedTemporaryFile(suffix='.zip', delete=False)
            shutil.make_archive(os.path.splitext(file_.name)[0], 'zip', tempdir)
        with open(file_.name, 'rb') as f:
            upload.hash = 'sha256:%s' % get_sha256(f)
        timer.log_interval('2.repackaged')
        log.info('Zip from upload %s repackaged, moving file back', upload_pk)
        move_stored_file(file_.name, upload.path)
        timer.log_interval('3.moved')
        upload.save()
        timer.log_interval('4.end')
    else:
        log.info('Not repackaging upload %s, it is not a xpi file.', upload_pk)
    return results
コード例 #15
0
ファイル: tasks.py プロジェクト: tsl143/addons-server
def approve_rereview(theme):
    """Replace original theme with pending theme on filesystem."""
    # If reuploaded theme, replace old theme design.
    storage = LocalFileStorage()
    rereview = theme.rereviewqueuetheme_set.all()
    reupload = rereview[0]

    if reupload.header_path != reupload.theme.header_path:
        create_persona_preview_images(
            src=reupload.header_path,
            full_dst=[
                reupload.theme.thumb_path,
                reupload.theme.icon_path],
            set_modified_on=[reupload.theme.addon])

        if not reupload.theme.is_new():
            # Legacy themes also need a preview_large.jpg.
            # Modern themes use preview.png for both thumb and preview so there
            # is no problem there.
            copy_stored_file(reupload.theme.thumb_path,
                             reupload.theme.preview_path, storage=storage)

        move_stored_file(
            reupload.header_path, reupload.theme.header_path, storage=storage)

    theme = reupload.theme
    footer_path = theme.footer_path
    if reupload.footer_path != footer_path:
        if not footer_path:
            dst_root = os.path.join(user_media_path('addons'),
                                    str(theme.addon.id))
            footer_path = os.path.join(dst_root, 'footer.png')
            theme.footer = 'footer.png'
            theme.save()

        move_stored_file(
            reupload.footer_path, footer_path, storage=storage)
    rereview.delete()

    theme.addon.increment_theme_version_number()
コード例 #16
0
def approve_rereview(theme):
    """Replace original theme with pending theme on filesystem."""
    # If reuploaded theme, replace old theme design.
    storage = LocalFileStorage()
    rereview = theme.rereviewqueuetheme_set.all()
    reupload = rereview[0]

    if reupload.header_path != reupload.theme.header_path:
        create_persona_preview_images(
            src=reupload.header_path,
            full_dst=[
                reupload.theme.thumb_path,
                reupload.theme.icon_path],
            set_modified_on=[reupload.theme.addon])

        if not reupload.theme.is_new():
            # Legacy themes also need a preview_large.jpg.
            # Modern themes use preview.png for both thumb and preview so there
            # is no problem there.
            copy_stored_file(reupload.theme.thumb_path,
                             reupload.theme.preview_path, storage=storage)

        move_stored_file(
            reupload.header_path, reupload.theme.header_path, storage=storage)

    theme = reupload.theme
    footer_path = theme.footer_path
    if reupload.footer_path != footer_path:
        if not footer_path:
            dst_root = os.path.join(user_media_path('addons'),
                                    str(theme.addon.id))
            footer_path = os.path.join(dst_root, 'footer.png')
            theme.footer = 'footer.png'
            theme.save()

        move_stored_file(
            reupload.footer_path, footer_path, storage=storage)
    rereview.delete()

    theme.addon.increment_theme_version_number()
コード例 #17
0
 def test_move_chunking(self):
     src = self.newfile('src.txt', '<contents>')
     dest = self.path('somedir/dest.txt')
     move_stored_file(src, dest, chunk_size=1)
     assert self.contents(dest) == '<contents>'
     assert not storage.exists(src)
コード例 #18
0
 def test_move_chunking(self):
     src = self.newfile('src.txt', '<contents>')
     dest = self.path('somedir/dest.txt')
     move_stored_file(src, dest, chunk_size=1)
     assert self.contents(dest) == '<contents>'
     assert not storage.exists(src)
コード例 #19
0
 def test_move(self):
     src = self.newfile("src.txt", "<contents>")
     dest = self.path("somedir/dest.txt")
     move_stored_file(src, dest)
     eq_(self.contents(dest), "<contents>")
     eq_(storage.exists(src), False)
コード例 #20
0
 def test_move(self):
     src = self.newfile('src.txt', '<contents>')
     dest = self.path('somedir/dest.txt')
     move_stored_file(src, dest)
     assert self.contents(dest) == '<contents>'
     assert storage.exists(src) == False