Skip to content

Commit

Permalink
Fix for handling readonly images on Windows.
Browse files Browse the repository at this point in the history
Issue #352
  • Loading branch information
jmcnamara committed May 10, 2016
1 parent a052576 commit d75d854
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions xlsxwriter/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Standard packages.
import os
import stat
import tempfile
from shutil import copy

Expand Down Expand Up @@ -584,6 +585,12 @@ def _add_image_files(self):
else:
copy(filename, os_filename)

# Allow copies of Windows readonly images to be deleted.
try:
os.chmod(os_filename,
os.stat(os_filename).st_mode | stat.S_IWRITE)
except:
pass
else:
# For in-memory mode we read the image into a stream.
if image_data:
Expand Down
Binary file added xlsxwriter/test/comparison/images/red_readonly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions xlsxwriter/test/comparison/test_image34.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
###############################################################################
#
# Tests for XlsxWriter.
#
# Copyright (c), 2013-2016, John McNamara, jmcnamara@cpan.org
#

from ..excel_comparsion_test import ExcelComparisonTest
from ...workbook import Workbook


class TestCompareXLSXFiles(ExcelComparisonTest):
"""
Test file created by XlsxWriter against a file created by Excel.
"""

def setUp(self):
self.maxDiff = None

filename = 'image34.xlsx'

test_dir = 'xlsxwriter/test/comparison/'
self.image_dir = test_dir + 'images/'
self.got_filename = test_dir + '_test_' + filename
self.exp_filename = test_dir + 'xlsx_files/' + filename

self.ignore_files = []
self.ignore_elements = {}

def test_create_file(self):
"""Test the creation of a simple XlsxWriter file with image(s)."""

workbook = Workbook(self.got_filename)

worksheet = workbook.add_worksheet()

worksheet.insert_image('E9', self.image_dir + 'red_readonly.png')

workbook.close()

self.assertExcelEqual()
Binary file not shown.

0 comments on commit d75d854

Please sign in to comment.