<commit_before>#!/usr/bin/env python
import effess
import os
import os.path as p
import re
import shutil
import string
import sys
import tempfile
import types
import uuid
import subprocess
from app import App
from xml.sax.saxutils import quoteattr

win32_dir = p.join(p.dirname(__file__), 'win32')
if p.exists(win32_dir):
	sys.path.append(win32_dir)
import PyRTF

class Win32App(App):
	def stage(self, stage_dir, bundle):
		App.stage(self, stage_dir, bundle=bundle)

		contents = self.get_contents_dir()
		self.env.log(u'Copying kboot.exe to %s' % contents);
		self.executable_path = p.join(contents, '%s.exe' % self.name)
		effess.copy(p.join(self.sdk_dir, 'kboot.exe'), self.executable_path)

		# The .installed file for Windows should always exist,
		# since we only ever install via the MSI installer.
		open(p.join(contents, '.installed'), 'a').close()

		self.set_executable_icon()

	def set_executable_icon(self):
		if not hasattr(self, 'image'):
			return

		icon_path = str(p.join(self.contents, 'Resources', self.image))
		if not p.exists(icon_path):
			return

		if not(icon_path.lower().endswith('.ico')):
			# Assume that GraphicsMagick is on the path for now. This will change
			# once the packaging server setup has been improved (running on drive C:\)
			convert = 'convert.exe'
			temp_dir = tempfile.mkdtemp()
			new_ico_file = p.join(self.contents, 'Resources', '_converted_icon.ico')
			ico_command = [convert]
			for size in [16, 32, 64, 128]:
				resolution = "%dx%d" % (size, size)
				args = [convert, icon_path, '-resize', resolution + "^",
					"-gravity", "center", "-background", "transparent",
					"-extent", resolution, "%s\\%d.png" % (temp_dir, size)]
				subprocess.check_call(args, shell=True)

				ico_command.append('%s\\%d.png' % (temp_dir, size))

			ico_command.append(new_ico_file)
			subprocess.check_call(ico_command, shell=True)

			icon_path = new_ico_file

		self.env.run('%s "%s" "%s"' % (p.join(self.sdk_dir, 'ReplaceVistaIcon.exe'), self.executable_path, icon_path))

	def package(self, package_dir, bundle):
		contents = self.get_contents_dir()
		target = p.join(package_dir, self.name + '.msi')
		wxs_path = p.join(package_dir, 'installer.wxs')
		template_args = {}<commit_msg>Win32 icon conversion should fail gracefully when MagicK is not installed.<commit_after>#!/usr/bin/env python
import effess
import os
import os.path as p
import re
import shutil
import string
import sys
import tempfile
import types
import uuid
import subprocess
from app import App
from xml.sax.saxutils import quoteattr

win32_dir = p.join(p.dirname(__file__), 'win32')
if p.exists(win32_dir):
	sys.path.append(win32_dir)
import PyRTF

class Win32App(App):
	def stage(self, stage_dir, bundle):
		App.stage(self, stage_dir, bundle=bundle)

		contents = self.get_contents_dir()
		self.env.log(u'Copying kboot.exe to %s' % contents);
		self.executable_path = p.join(contents, '%s.exe' % self.name)
		effess.copy(p.join(self.sdk_dir, 'kboot.exe'), self.executable_path)

		# The .installed file for Windows should always exist,
		# since we only ever install via the MSI installer.
		open(p.join(contents, '.installed'), 'a').close()

		self.set_executable_icon()

	def set_executable_icon(self):
		if not hasattr(self, 'image'):
			return

		icon_path = str(p.join(self.contents, 'Resources', self.image))
		if not p.exists(icon_path):
			return

		if not(icon_path.lower().endswith('.ico')):
			# Assume that GraphicsMagick is on the path for now. This will change
			# once the packaging server setup has been improved (running on drive C:\)
			convert = 'convert.exe'
			try:
				subprocess.check_call([convert, '-version'], shell=True)
			except subprocess.CalledProcessError:
				# If Magick is not installed, skip icon conversion
				print 'ImageMagick not installed, aborting icon conversion.'
				return
			temp_dir = tempfile.mkdtemp()
			new_ico_file = p.join(self.contents, 'Resources', '_converted_icon.ico')
			ico_command = [convert]
			for size in [16, 32, 64, 128]:
				resolution = "%dx%d" % (size, size)
				args = [convert, icon_path, '-resize', resolution + "^",
					"-gravity", "center", "-background", "transparent",
					"-extent", resolution, "%s\\%d.png" % (temp_dir, size)]
				subprocess.check_call(args, shell=True)

				ico_command.append('%s\\%d.png' % (temp_dir, size))

			ico_command.append(new_ico_file)
			subprocess.check_call(ico_command, shell=True)

			icon_path = new_ico_file

		self.env.run('%s "%s" "%s"' % (p.join(self.sdk_dir, 'ReplaceVistaIcon.exe'), self.executable_path, icon_path))

	def package(self, package_dir, bundle):
		contents = self.get_contents_dir()
		target = p.join(package_dir, self.name + '.msi')
		wxs_path = p.join(package_dir, 'installer.wxs')
		template_args = {}
{'fraction_non_alphanumeric': 0.13724253888188315, 'fraction_numerical': 0.008406893652795292, 'mean_word_length': 4.438857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2047423', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1627, 'n_words': 418}