Fetching contributors…
Cannot retrieve contributors at this time
executable file 96 lines (80 sloc) 2.69 KB
#!/usr/bin/env python
import os
import sys
import xml.dom.minidom as DOM
def migrate_guid (project):
for node in project.getElementsByTagName ('ProjectTypeGuids'):
old = node.firstChild.nodeValue
node.firstChild.nodeValue = old.replace (
return node.firstChild.nodeValue != old
def migrate_reference (project):
xammac_added = False
for ref in project.getElementsByTagName ('Reference'):
if ref.hasAttribute ('Include'):
name = ref.attributes['Include'].value.lower ()
if name == 'monomac' or name.startswith ('monomac ') or name.startswith('monomac,'):
if not xammac_added:
ref.attributes['Include'] = 'XamMac'
while ref.firstChild:
ref.removeChild (ref.firstChild)
xammac_added = True
return xammac_added
def add_linker_options (project):
options = {
'EnableCodeSigning': 'True',
'CodeSigningKey': 'Mac Developer',
'CreatePackage': 'False',
'EnablePackageSigning': 'False',
'PackageSigningKey': 'Developer ID Installer',
'IncludeMonoRuntime': 'True',
'UseSGen': 'False',
'LinkMode': 'Full'
options_updated = False
for node in project.getElementsByTagName ('PropertyGroup'):
if not node.hasAttribute ('Condition'):
cond = node.attributes['Condition'].value
if cond == " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " or \
cond == " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ":
first_append_made = False
for key, value in options.iteritems ():
children = node.getElementsByTagName (key)
if len (children) > 0:
old = children[0].nodeValue
children[0].nodeValue = value
if children[0].nodeValue != old:
options_updated = True
child = project.createElement (key)
child.appendChild (project.createTextNode (value))
if first_append_made:
node.appendChild (project.createTextNode (' '))
node.appendChild (project.createTextNode (' '))
node.appendChild (child)
node.appendChild (project.createTextNode ('\n'))
first_append_made = True
options_updated = True
if first_append_made:
node.appendChild (project.createTextNode (' '))
return options_updated
def migrate_project (path):
with open (path, 'r') as fp:
eof_newline = ().endswith ('\n')
project = DOM.parse (path)
a = migrate_guid (project)
b = migrate_reference (project)
c = add_linker_options (project)
if not a and not b and not c:
xml = project.toxml ('utf-8')
xml = xml.replace ('"utf-8"?>', '"utf-8"?>\n')
xml = xml.replace ('/>', ' />')
with open (path, 'w') as fp:
fp.write (xml)
if eof_newline:
fp.write ('\n')
migrate_project (sys.argv[1])