Change in ...osmocom-bb[master]: fb_tools/bdf_to_c.py: make it compatible with python3

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

lynxis lazus gerrit-no-reply at lists.osmocom.org
Fri Aug 9 13:33:17 UTC 2019


lynxis lazus has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/osmocom-bb/+/14758 )

Change subject: fb_tools/bdf_to_c.py: make it compatible with python3
......................................................................

fb_tools/bdf_to_c.py: make it compatible with python3

This would break python2 compatibility.

Change-Id: Iaa20dd0aafa20e36186cf8dfe4d0ac9ab638f235
---
M src/host/fb_tools/bdf_to_c.py
1 file changed, 33 insertions(+), 33 deletions(-)

Approvals:
  fixeria: Looks good to me, approved
  pespin: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/host/fb_tools/bdf_to_c.py b/src/host/fb_tools/bdf_to_c.py
index 86be6a6..ebeb7f9 100755
--- a/src/host/fb_tools/bdf_to_c.py
+++ b/src/host/fb_tools/bdf_to_c.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 '''
@@ -133,7 +133,7 @@
 				arr = l.split(None,1)
 				if len(arr) < 2 and \
 				    arr[0].lower() != 'STARTCHAR' :
-					print >>sys.stderr,'Not start of glyph: %s'%(l)
+					print('Not start of glyph: %s'%(l), file=sys.stderr)
 					continue
 				inchar = unique_name(arr[1],self.glyphs)
 				continue
@@ -159,7 +159,7 @@
 				continue
 
 			if len(arr) < 2 :
-				print >>sys.stderr,'Bad line in font: %s'%(l)
+				print('Bad line in font: %s'%(l), file=sys.stderr)
 				continue
 			data[arr[0].lower()] = arr[1]
 
@@ -183,40 +183,40 @@
 
 	if opts.firstchar == None :
 		opts.firstchar = min(font.enc)
-		print 'First character in font: %d, %s'%(opts.firstchar,
-			font.enc[opts.firstchar])
+		print('First character in font: %d, %s'%(opts.firstchar,
+			font.enc[opts.firstchar]))
 
 	if opts.lastchar == None :
 		opts.lastchar = max(font.enc)
-		print 'Last character in font: %d, %s'%(opts.lastchar,
-			font.enc[opts.lastchar])
+		print('Last character in font: %d, %s'%(opts.lastchar,
+			font.enc[opts.lastchar]))
 
 	if opts.base == None :
 		opts.base = 'font_'+os.path.basename(args[0])
 		if opts.base[-4:] == '.bdf' :
 			opts.base = opts.base[:-4]
-		print >>sys.stderr,'Guessing symbol prefix to be %s.'%(opts.base)
+		print('Guessing symbol prefix to be %s.'%(opts.base), file=sys.stderr)
 
 	if opts.out == None :
 		opts.out = os.path.basename(args[0])
 		if opts.out[-4:] == '.bdf' :
 			opts.out = opts.out[:-4]
 		opts.out = opts.out + '.c'
-		print >>sys.stderr,'Guessing output filename to be %s.'%(opts.out)
+		print('Guessing output filename to be %s.'%(opts.out), file=sys.stderr)
 
 		if os.path.exists(opts.out) :
-			print >>sys.stderr,'Will *NOT* overwrite existing file when guessing output!'
+			print('Will *NOT* overwrite existing file when guessing output!', file=sys.stderr)
 			sys.exit(1)
 
 	of = file(opts.out,'w')
 	
-	print >>of,'#include <fb/font.h>'
-	print >>of,'/* file autogenerated by %s */'%(sys.argv[0])
+	print('#include <fb/font.h>', file=of)
+	print('/* file autogenerated by %s */' %(sys.argv[0]), file=of)
 
 	offsets = list()
 	glyphnames = list()
 
-	print >>of,'static const uint8_t %s_data[] = {'%(opts.base)
+	print('static const uint8_t %s_data[] = {'%(opts.base), file=of)
 
 	pos = 0
 
@@ -236,8 +236,8 @@
 		bitmap = glyph['bitmap']
 
 		if bbx[1] != len(bitmap) :
-			print >>sys.stderr,'ERROR: glyph',charname,'has wrong number of lines of data!'
-			print >>sys.stderr,' want: ',bbx[1],'but have',len(bitmap)
+			print('ERROR: glyph',charname,'has wrong number of lines of data!', file=sys.stderr)
+			print(' want: ',bbx[1],'but have',len(bitmap), file=sys.stderr)
 			sys.exit(1)
 
 		removedrows = 0
@@ -254,40 +254,40 @@
 			bitmap = bitmap[:-1]
 
 		if removedrows > 0 :
-			print "Glyph %s: removed %d rows."%(charname,removedrows)
+			print("Glyph %s: removed %d rows."%(charname,removedrows))
 
 		w = int(glyph['dwidth'].split(None,1)[0])
 
-		print >>of,'/* --- new character %s %s starting at offset 0x%04x --- */'%(
-				charname,ascii_charnum(i),pos)
-		print >>of,'\t/*%04x:*/\t%d, %d, %d, %d, %d, /* width and bbox (w,h,x,y) */'%(
-			pos,w,bbx[0],bbx[1],bbx[2],bbx[3])
+		print('/* --- new character %s %s starting at offset 0x%04x --- */'%(
+				charname,ascii_charnum(i),pos), file=of)
+		print('\t/*%04x:*/\t%d, %d, %d, %d, %d, /* width and bbox (w,h,x,y) */'%(
+			pos,w,bbx[0],bbx[1],bbx[2],bbx[3]), file=of)
 
 		pos += 5
 
 		for k,l in enumerate(bitmap) :
 			bytes = [ int(l[i:i+2],16) for i in range(0,len(l),2) ]
 			if len(bytes) != (bbx[0]+7)/8 :
-				print >>sys.stderr,'ERROR: glyph',charname,'has wrong # of bytes'
-				print >>sys.stderr,' per line. Want',(bbx[0]+7)/8,'have',len(bytes)
+				print('ERROR: glyph',charname,'has wrong # of bytes', file=sys.stderr)
+				print(' per line. Want',(bbx[0]+7)/8,'have',len(bytes), file=sys.stderr)
 				sys.exit(1)
 			cdata = ','.join([ '0x%02x'%v for v in bytes ])
 			comment = ''.join([ byte_to_bits(b) for b in bytes ])
-			print >>of,'\t/*%04x:*/\t'%(pos)+cdata+',  /* '+comment+' */'
+			print('\t/*%04x:*/\t'%(pos)+cdata+',  /* '+comment+' */', file=of)
 			pos += len(bytes)
 
-	print >>of,"};"
+	print("};", file=of)
 
 	x = ',\n\t'.join(['0x%04x /* %s */'%(w,n) for w,n in zip(offsets,glyphnames)])
-	print >>of,'static const uint16_t %s_offsets[] = {\n\t%s\n};'%(opts.base,x)
+	print('static const uint16_t %s_offsets[] = {\n\t%s\n};'%(opts.base,x), file=of)
 
 	height = font.ascent + font.descent
 
-	print >>of,'const struct fb_font %s = {'%(opts.base)
-	print >>of,'\t.height = %d,'%(height)
-	print >>of,'\t.ascent = %d,'%(font.ascent)
-	print >>of,'\t.firstchar = %d, /* %s */'%(opts.firstchar,font.enc.get(opts.firstchar,"?"))
-	print >>of,'\t.lastchar = %d, /* %s */'%(opts.lastchar,font.enc.get(opts.lastchar,"?"))
-	print >>of,'\t.chardata = %s_data,'%(opts.base)
-	print >>of,'\t.charoffs = %s_offsets,'%(opts.base)
-	print >>of,'};'
+	print('const struct fb_font %s = {'%(opts.base), file=of)
+	print('\t.height = %d,'%(height), file=of)
+	print('\t.ascent = %d,'%(font.ascent), file=of)
+	print('\t.firstchar = %d, /* %s */'%(opts.firstchar,font.enc.get(opts.firstchar,"?")), file=of)
+	print('\t.lastchar = %d, /* %s */'%(opts.lastchar,font.enc.get(opts.lastchar,"?")), file=of)
+	print('\t.chardata = %s_data,'%(opts.base), file=of)
+	print('\t.charoffs = %s_offsets,'%(opts.base), file=of)
+	print('};', file=of)

-- 
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/14758
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Iaa20dd0aafa20e36186cf8dfe4d0ac9ab638f235
Gerrit-Change-Number: 14758
Gerrit-PatchSet: 5
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190809/f3a1050e/attachment.htm>


More information about the gerrit-log mailing list