wapt-itunes/setup.py

71 lines
2.9 KiB
Python

# -*- coding: utf-8 -*-
from setuphelpers import *
import os
uninstallkey = []
def install():
print('Installing Apple iTunes')
msi = 'iTunes64.msi' if iswin64() else 'iTunes.msi'
run(r'msiexec /qn /norestart /i%s SCHEDULE_ASUW=0' % msi,accept_returncodes=[0,3010])
for soft in installed_softwares('iTunes'):
# Only check for the exact name. Eg, not iTunes Awsome Addon
if soft['name'] == 'iTunes':
uninstallkey = soft['key']
# Disable auto updates, using the parental control
with reg_openkey_noredir(HKEY_LOCAL_MACHINE,r'SOFTWARE\Apple Computer, Inc.\iTunes\Parental Controls\Default',sam=KEY_WRITE,create_if_missing=True) as reg_key:
reg_setvalue(reg_key, 'AdminFlags', 257, REG_DWORD)
# Remove desktop shortcut
remove_desktop_shortcut('iTunes')
def uninstall():
print('Uninstalling Apple iTunes')
for soft in installed_softwares('iTunes'):
if soft['name'] == 'iTunes':
run(r'msiexec /qn /norestart /x%s' % soft['key'])
def update_package():
print('Updating iTunes package')
for arch in ['32','64']:
url = 'https://www.apple.com/itunes/download/win%s' % arch
mkdirs(makepath('temp',arch))
filename = makepath('temp', 'itunes%s' % arch)
if not isfile(filename):
print('Downloading %s' % url)
wget(url,filename)
print('Extracting %s' % filename)
run('"%s" e -y -o"%s" %s' % (makepath(programfiles,'7-Zip','7z.exe'),makepath('temp',arch),filename))
version = get_msi_properties(makepath('temp','64','iTunes64.msi'))['ProductVersion']
print('Downloaded version is %s' % version)
pe = PackageEntry();
control = pe.load_control_from_wapt('.')
if Version(version) > Version(control['version'].split('-',1)[0]):
print('New iTunes version %s' % version)
for file in ['iTunes.msi', 'iTunes64.msi']:
if isfile(file):
remove_file(file)
os.rename(makepath('temp','32','iTunes.msi'),'iTunes.msi')
os.rename(makepath('temp','64','iTunes64.msi'),'iTunes64.msi')
pe.version = version + '-0'
pe.maturity = 'PREPROD'
pe.save_control_to_wapt('.')
print('Removing temp files')
remove_tree('temp')
def audit():
is_installed = False
for soft in installed_softwares('iTunes'):
is_installed = True
if is_installed == False :
print('iTunes is not installed')
return "ERROR"
parental_control = registry_readstring(HKEY_LOCAL_MACHINE,r'SOFTWARE\Apple Computer, Inc.\iTunes\Parental Controls\Default','AdminFlags')
if not parental_control:
print('Parental control is not enabled')
return "WARNING"
elif int(parental_control) != 257:
print('Parental control settings is not 257 as expected')
return "WARNING"
return "OK"