sbsv2/raptor/bin/fixmeta.py
author Mike Kinghan <mikek@symbian.org>
Mon, 15 Nov 2010 10:57:53 +0000
changeset 39 fa9d7d89d3d6
parent 13 c327db0664bb
permissions -rw-r--r--
A couple more small Windows compatibility fixes for romnibus.pl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
     1
#
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
     2
# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
     3
# All rights reserved.
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
     4
# This component and the accompanying materials are made available
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
     6
# which accompanies this distribution, and is available
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
     8
#
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
     9
# Initial Contributors:
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    10
# Nokia Corporation - initial contribution.
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    11
#
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    12
# Contributors:
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    13
#
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    14
# Description: 
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    15
# fixmeta
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    16
#
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    17
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    18
"""
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    19
  Correct bld.infs, mmps etc to the point where it can be read by the build system
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    20
  Currently it:
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    21
  	Corrects '\' in include statements to '/'
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    22
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    23
  Author: Tim Murphy, with a nod to Peter Harper's fixslashes.pl
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    24
"""
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    25
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    26
import sys
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    27
import os
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    28
import re
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    29
from  optparse import OptionParser
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    30
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    31
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    32
includeslash_re = re.compile('#include.*\\\\')
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    33
mmpfile_re = re.compile(".*\.mm[hp]$", re.I)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    34
bldinf_re = re.compile(".*bld\.inf$", re.I)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    35
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    36
def fixincludeslash(m):
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    37
	return m.group(0).replace('\\','/')
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    38
	
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    39
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    40
def checkconvert(dirname, filename):
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    41
	tofilename=dirname + "/" + filename+".converted"
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    42
	fromfilename = dirname + "/" + filename
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    43
	fromfile = open(fromfilename,"r")
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    44
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    45
	conversions = False
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    46
	fromtext = fromfile.read()
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    47
	(totext, subcount) = re.subn(includeslash_re, fixincludeslash, fromtext)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    48
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    49
	if subcount != 0:
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    50
		print '"%s", %d backslash includes\n' % (fromfilename, subcount)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    51
		tofile = open( tofilename,"w")
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    52
		tofile.write(totext)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    53
		tofile.close()
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    54
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    55
	fromfile.close()
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    56
	if subcount != 0:
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    57
		os.rename(fromfilename,fromfilename+".wrongslash")
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    58
		os.rename(tofilename,fromfilename)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    59
	
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    60
	
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    61
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    62
def visit(arg, dirname, names):
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    63
	#print "dir: %s\n" % (dirname)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    64
	for f in names:
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    65
		m = mmpfile_re.match(f)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    66
		b = bldinf_re.match(f)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    67
		if m != None or b != None:
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    68
			#print "\t"+f
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    69
			checkconvert(dirname, f)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    70
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    71
parser = OptionParser(prog = "fixmeta",
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    72
        usage = "%prog [-h | options] sourcepath containing files to be fixed.")
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    73
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    74
(options, args) = parser.parse_args()
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    75
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    76
if len(args) == 0:
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    77
	print "Need at least one argument: a path to the source which is to be fixed."
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    78
	sys.exit(-1)
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    79
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    80
print "Walking\n"
c327db0664bb Upgrading Raptor from 2.10 to 2.13
mikek
parents: 2
diff changeset
    81
os.path.walk(args[0],visit,None)