application/sis/increment_buildno.py
author Sebastian Brannstrom <sebastianb@symbian.org>
Fri, 19 Nov 2010 22:51:53 +0000
branchsymbian1
changeset 378 b3487e8973c7
parent 355 075b3a49cb55
permissions -rw-r--r--
Spanish language sync
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
86
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
     1
import os;
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
     2
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
     3
BUILDNO_FILE = 'buildno.txt'
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
     4
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
     5
PKG_FILE_UDEB_TEMPLATE = 'podcatcher_udeb_template.pkg'
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
     6
PKG_FILE_UDEB = 'podcatcher_udeb.pkg'
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
     7
PKG_FILE_UREL_TEMPLATE = 'podcatcher_urel_template.pkg'
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
     8
PKG_FILE_UREL = 'podcatcher_urel.pkg'
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
     9
HEADER_FILE = '..\\inc\\buildno.h'
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    10
BUILDNO_TAG = 'BUILDNO'
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    11
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    12
def update_buildno(buildno_file):
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    13
	#read previous build number
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    14
	f = open(buildno_file, 'r')
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    15
	buildno = int(f.read())
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    16
	f.close()
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    17
	
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    18
	# increment build number and write it back to the file
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    19
	buildno = buildno + 1
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    20
	buildno_str = '%d' % buildno
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    21
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    22
	print 'New build number is %d' % buildno
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    23
	
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    24
	f = open(buildno_file, 'w')
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    25
	f.write(buildno_str)
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    26
	f.close()
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    27
	return buildno
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    28
	
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    29
def update_pkg(pkg_template, pkg_file, buildno):
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    30
	print 'Writing %s' % pkg_file
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    31
	#update 'build' number in PKG file
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    32
	f = open (pkg_template, 'r')
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    33
	g = open (pkg_file, 'w')
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    34
	
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    35
	buildno_str = '%d' % buildno
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    36
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    37
	for line in f:
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    38
		line = line.replace(BUILDNO_TAG, buildno_str)
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    39
		g.write(line)
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    40
		
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    41
def update_header(header_file, buildno):
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    42
	print 'Writing %s' % header_file
355
075b3a49cb55 Fixed more usability issues; Updated version to 1.10
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 86
diff changeset
    43
	buildno_str = '// Build number generated by increment_buildno.py, do not edit manually\r\n#define BUILD_NO %d\r\n' % buildno
86
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    44
	
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    45
	f = open(header_file, 'w')
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    46
	f.write(buildno_str)
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    47
	f.close()
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    48
	return buildno
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    49
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    50
new_buildno = update_buildno(BUILDNO_FILE)
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    51
update_pkg(PKG_FILE_UDEB_TEMPLATE, PKG_FILE_UDEB, new_buildno)
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    52
update_pkg(PKG_FILE_UREL_TEMPLATE, PKG_FILE_UREL, new_buildno)
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    53
update_header(HEADER_FILE, new_buildno)
a9d05a49b7cd Added build number generator
teknolog
parents:
diff changeset
    54
print 'Remember to rebuild to get the build number into the about dialog!'