Update fetch_sources.py to Python 3

Components: Framework

Change-Id: I7f75a084e5128b1a19be7649a06a315e91a36688
(cherry picked from commit 9c4f100a056b084876e874a1b115192225b9a61a)
diff --git a/external/fetch_sources.py b/external/fetch_sources.py
index dcffe0c..4354f5c 100644
--- a/external/fetch_sources.py
+++ b/external/fetch_sources.py
@@ -87,7 +87,7 @@
 	def isArchiveUpToDate (self):
 		archiveFile = os.path.join(EXTERNAL_DIR, pkg.baseDir, pkg.archiveDir, pkg.filename)
 		if os.path.exists(archiveFile):
-			return computeChecksum(readFile(archiveFile)) == self.checksum
+			return computeChecksum(readBinaryFile(archiveFile)) == self.checksum
 		else:
 			return False
 
@@ -104,7 +104,7 @@
 
 	def storeExtractedChecksum (self, checksum):
 		checksum_bytes = checksum.encode("utf-8")
-		writeFile(self.getExtractedChecksumFilePath(), checksum_bytes)
+		writeBinaryFile(self.getExtractedChecksumFilePath(), checksum_bytes)
 
 	def connectToUrl (self, url):
 		result = None
@@ -137,7 +137,7 @@
 		if not os.path.exists(os.path.dirname(dstPath)):
 			os.mkdir(os.path.dirname(dstPath))
 
-		writeFile(dstPath, data)
+		writeBinaryFile(dstPath, data)
 
 	def extract (self):
 		print("Extracting %s to %s/%s" % (self.filename, self.baseDir, self.extractDir))
@@ -190,7 +190,8 @@
 	def isFileUpToDate (self):
 		file = os.path.join(EXTERNAL_DIR, pkg.baseDir, pkg.extractDir, pkg.filename)
 		if os.path.exists(file):
-			return computeChecksum(readFile(file)) == self.checksum
+			data = readFile(file)
+			return computeChecksum(data.encode('utf-8')) == self.checksum
 		else:
 			return False
 
@@ -225,7 +226,7 @@
 		if not os.path.exists(os.path.dirname(dstPath)):
 			os.mkdir(os.path.dirname(dstPath))
 
-		writeFile(dstPath, data)
+		writeBinaryFile(dstPath, data)
 
 class GitRepo (Source):
 	def __init__(self, httpsUrl, sshUrl, revision, baseDir, extractDir = "src", removeTags = []):
diff --git a/scripts/build/common.py b/scripts/build/common.py
index d85f610..cb17a23 100644
--- a/scripts/build/common.py
+++ b/scripts/build/common.py
@@ -87,12 +87,23 @@
 	if retcode != 0:
 		raise Exception("Failed to execute '%s', got %d" % (str(args), retcode))
 
+def readBinaryFile (filename):
+	f = open(filename, 'rb')
+	data = f.read()
+	f.close()
+	return data
+
 def readFile (filename):
 	f = open(filename, 'rt')
 	data = f.read()
 	f.close()
 	return data
 
+def writeBinaryFile (filename, data):
+	f = open(filename, 'wb')
+	f.write(data)
+	f.close()
+
 def writeFile (filename, data):
 	f = open(filename, 'wt')
 	f.write(data)