mirror of
https://github.com/munki/munki.git
synced 2026-05-07 04:49:28 -05:00
Move common icon installation code to a function.
This commit is contained in:
+26
-39
@@ -231,14 +231,6 @@ def iconExistsInRepo(pkginfo):
|
||||
def generate_png_from_copy_from_dmg_item(dmg_path, pkginfo):
|
||||
'''Generates a product icon from a copy_from_dmg item
|
||||
and uploads to the repo'''
|
||||
destination_path = os.path.join(REPO_PATH, 'icons')
|
||||
if not os.path.exists(destination_path):
|
||||
try:
|
||||
os.makedirs(destination_path)
|
||||
except OSError, errmsg:
|
||||
print >> sys.stderr, ('Could not create %s: %s' %
|
||||
(destination_path, errmsg))
|
||||
|
||||
mountpoints = munkicommon.mountdmg(dmg_path)
|
||||
if mountpoints:
|
||||
mountpoint = mountpoints[0]
|
||||
@@ -248,14 +240,7 @@ def generate_png_from_copy_from_dmg_item(dmg_path, pkginfo):
|
||||
app_path = os.path.join(mountpoint, apps[0]['source_item'])
|
||||
icon_path = iconutils.findIconForApp(app_path)
|
||||
if icon_path:
|
||||
png_path = os.path.join(
|
||||
destination_path, pkginfo['name'] + u'.png')
|
||||
result = iconutils.convertIconToPNG(icon_path, png_path)
|
||||
if result:
|
||||
print 'Created icon: %s' % png_path
|
||||
else:
|
||||
print >> sys.stderr, (
|
||||
u'\tError converting %s to png.' % icon_path)
|
||||
convert_and_install_icon(pkginfo, icon_path)
|
||||
else:
|
||||
print 'No application icons found.'
|
||||
else:
|
||||
@@ -266,14 +251,6 @@ def generate_png_from_copy_from_dmg_item(dmg_path, pkginfo):
|
||||
def generate_pngs_from_installer_pkg(item_path, pkginfo):
|
||||
'''Generates a product icon (or candidate icons) from
|
||||
an installer pkg and uploads to the repo'''
|
||||
destination_path = os.path.join(REPO_PATH, 'icons')
|
||||
if not os.path.exists(destination_path):
|
||||
try:
|
||||
os.makedirs(destination_path)
|
||||
except OSError, errmsg:
|
||||
print >> sys.stderr, ('Could not create %s: %s' %
|
||||
(destination_path, errmsg))
|
||||
|
||||
icon_paths = []
|
||||
mountpoint = None
|
||||
pkg_path = None
|
||||
@@ -302,29 +279,39 @@ def generate_pngs_from_installer_pkg(item_path, pkginfo):
|
||||
munkicommon.unmountdmg(mountpoint)
|
||||
|
||||
if len(icon_paths) == 1:
|
||||
png_path = os.path.join(
|
||||
destination_path, pkginfo['name'] + u'.png')
|
||||
result = iconutils.convertIconToPNG(icon_paths[0], png_path)
|
||||
if result:
|
||||
print 'Created icon: %s' % png_path
|
||||
else:
|
||||
print >> sys.stderr, u'Error converting %s to png.' % icon_paths[0]
|
||||
convert_and_install_icon(pkginfo, icon_paths[0])
|
||||
elif len(icon_paths) > 1:
|
||||
index = 1
|
||||
for icon_path in icon_paths:
|
||||
png_path = os.path.join(
|
||||
destination_path,
|
||||
pkginfo['name'] + '_' + str(index) + u'.png')
|
||||
result = iconutils.convertIconToPNG(icon_path, png_path)
|
||||
if result:
|
||||
print 'Created icon: %s' % png_path
|
||||
else:
|
||||
print >> sys.stderr, u'Error converting %s to png.' % icon_path
|
||||
convert_and_install_icon(pkginfo, icon_path, index=index)
|
||||
index += 1
|
||||
else:
|
||||
print 'No application icons found.'
|
||||
|
||||
|
||||
def convert_and_install_icon(pkginfo, icon_path, index=None):
|
||||
destination_path = os.path.join(REPO_PATH, 'icons')
|
||||
if not os.path.exists(destination_path):
|
||||
try:
|
||||
os.makedirs(destination_path)
|
||||
except OSError, errmsg:
|
||||
print >> sys.stderr, ('Could not create %s: %s' %
|
||||
(destination_path, errmsg))
|
||||
|
||||
if index is not None:
|
||||
destination_name = pkginfo['name'] + '_' + str(index)
|
||||
else:
|
||||
destination_name = pkginfo['name']
|
||||
|
||||
png_path = os.path.join(
|
||||
destination_path, destination_name + u'.png')
|
||||
result = iconutils.convertIconToPNG(icon_path, png_path)
|
||||
if result:
|
||||
print 'Created icon: %s' % png_path
|
||||
else:
|
||||
print >> sys.stderr, u'Error converting %s to png.' % icon_path
|
||||
|
||||
|
||||
def copyIconToRepo(iconpath):
|
||||
"""Saves a product icon to the repo"""
|
||||
destination_path = os.path.join(REPO_PATH, 'icons')
|
||||
|
||||
Reference in New Issue
Block a user