From 177b960ea44f146bb6b9e3c7be87bd3669b0d823 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 16 Oct 2011 11:53:27 +0200 Subject: [PATCH] Fix python 3.x incompatibilities. * gentpl.py: Put brackets around print strings. * util/import_gcry.py: Open explicitly as utf-8. Use in instead of has_key. --- ChangeLog | 8 ++++++++ gentpl.py | 40 ++++++++++++++++++++-------------------- util/import_gcry.py | 28 +++++++++++++++------------- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index abe19dc78..d5fbffcd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-10-16 Vladimir Serbinenko + + Fix python 3.x incompatibilities. + + * gentpl.py: Put brackets around print strings. + * util/import_gcry.py: Open explicitly as utf-8. + Use in instead of has_key. + 2011-10-16 Vladimir Serbinenko * grub-core/fs/xfs.c (grub_xfs_inode): New field fork_offset. diff --git a/gentpl.py b/gentpl.py index cb6b663d9..af210a040 100644 --- a/gentpl.py +++ b/gentpl.py @@ -568,28 +568,28 @@ f = script_rules() g = data_rules() z = global_variable_initializers() -print "[+ AutoGen5 template +]\n" +print ("[+ AutoGen5 template +]\n") for p in GRUB_PLATFORMS: - print define_macro_for_platform_sources(p) - print define_macro_for_platform_nodist_sources(p) + print (define_macro_for_platform_sources(p)) + print (define_macro_for_platform_nodist_sources(p)) # print define_macro_for_platform_dependencies(p) - print define_macro_for_platform_startup(p) - print define_macro_for_platform_cflags(p) - print define_macro_for_platform_ldadd(p) - print define_macro_for_platform_ldflags(p) - print define_macro_for_platform_cppflags(p) - print define_macro_for_platform_ccasflags(p) - print define_macro_for_platform_stripflags(p) - print define_macro_for_platform_objcopyflags(p) + print (define_macro_for_platform_startup(p)) + print (define_macro_for_platform_cflags(p)) + print (define_macro_for_platform_ldadd(p)) + print (define_macro_for_platform_ldflags(p)) + print (define_macro_for_platform_cppflags(p)) + print (define_macro_for_platform_ccasflags(p)) + print (define_macro_for_platform_stripflags(p)) + print (define_macro_for_platform_objcopyflags(p)) - print define_macro_for_platform_conditionals_if_statement(p) - print define_macro_for_platform_conditionals_endif_statement(p) + print (define_macro_for_platform_conditionals_if_statement(p)) + print (define_macro_for_platform_conditionals_endif_statement(p)) # print z # initializer for all vars -print a -print b -print c -print d -print e -print f -print g +print (a) +print (b) +print (c) +print (d) +print (e) +print (f) +print (g) diff --git a/util/import_gcry.py b/util/import_gcry.py index ee75b1b8e..720f19303 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -20,6 +20,7 @@ import re import sys import os import datetime +import codecs if len (sys.argv) < 3: print ("Usage: %s SOURCE DESTINATION" % sys.argv[0]) @@ -40,9 +41,9 @@ except: print ("WARNING: %s already exists" % cipher_dir_out) cipher_files = os.listdir (cipher_dir_in) -conf = open (os.path.join ("grub-core", "Makefile.gcry.def"), "w") +conf = codecs.open (os.path.join ("grub-core", "Makefile.gcry.def"), "w", "utf-8") conf.write ("AutoGen definitions Makefile.tpl;\n\n") -confutil = open ("Makefile.utilgcry.def", "w") +confutil = codecs.open ("Makefile.utilgcry.def", "w", "utf-8") confutil.write ("AutoGen definitions Makefile.tpl;\n\n") confutil.write ("library = {\n"); confutil.write (" name = libgrubgcry.a;\n"); @@ -69,7 +70,7 @@ mdblocksizes = {"_gcry_digest_spec_crc32" : 64, "_gcry_digest_spec_tiger" : 64, "_gcry_digest_spec_whirlpool" : 64} -cryptolist = open (os.path.join (cipher_dir_out, "crypto.lst"), "w") +cryptolist = codecs.open (os.path.join (cipher_dir_out, "crypto.lst"), "w", "utf-8") # rijndael is the only cipher using aliases. So no need for mangling, just # hardcode it @@ -98,8 +99,8 @@ for cipher_file in cipher_files: nch = False if re.match (".*\.[ch]$", cipher_file): isc = re.match (".*\.c$", cipher_file) - f = open (infile, "r") - fw = open (outfile, "w") + f = codecs.open (infile, "r", "utf-8") + fw = codecs.open (outfile, "w", "utf-8") fw.write ("/* This file was automatically imported with \n") fw.write (" import_gcry.py. Please don't modify it */\n") fw.write ("#include \n") @@ -125,6 +126,7 @@ for cipher_file in cipher_files: isglue = True modname = "gcry_%s" % modname for line in f: + line = line if skip_statement: if not re.search (";", line) is None: skip_statement = False @@ -151,7 +153,7 @@ for cipher_file in cipher_files: fw.write (" .modname = \"%s\",\n" % modname); fw.write ("#endif\n"); if ismd: - if not mdblocksizes.has_key (mdname): + if not (mdname in mdblocksizes): print ("ERROR: Unknown digest blocksize: %s\n" % mdname) exit (1) @@ -324,28 +326,28 @@ cryptolist.close () chlog = "%s * crypto.lst: New file.\n" % chlog outfile = os.path.join (cipher_dir_out, "types.h") -fw=open (outfile, "w") +fw=codecs.open (outfile, "w", "utf-8") fw.write ("#include \n") fw.write ("#include \n") chlog = "%s * types.h: New file.\n" % chlog fw.close () outfile = os.path.join (cipher_dir_out, "memory.h") -fw=open (outfile, "w") +fw=codecs.open (outfile, "w", "utf-8") fw.write ("#include \n") chlog = "%s * memory.h: New file.\n" % chlog fw.close () outfile = os.path.join (cipher_dir_out, "cipher.h") -fw=open (outfile, "w") +fw=codecs.open (outfile, "w", "utf-8") fw.write ("#include \n") fw.write ("#include \n") chlog = "%s * cipher.h: Likewise.\n" % chlog fw.close () outfile = os.path.join (cipher_dir_out, "g10lib.h") -fw=open (outfile, "w") +fw=codecs.open (outfile, "w", "utf-8") fw.write ("#include \n") chlog = "%s * g10lib.h: Likewise.\n" % chlog fw.close () @@ -355,7 +357,7 @@ outfile = os.path.join (cipher_dir_out, "ChangeLog") conf.close (); -initfile = open (os.path.join (cipher_dir_out, "init.c"), "w") +initfile = codecs.open (os.path.join (cipher_dir_out, "init.c"), "w", "utf-8") for module in modules: initfile.write ("extern void grub_%s_init (void);\n" % module) initfile.write ("extern void grub_%s_fini (void);\n" % module) @@ -380,8 +382,8 @@ confutil.write ("};\n"); confutil.close (); -f=open (infile, "r") -fw=open (outfile, "w") +f=codecs.open (infile, "r", "utf-8") +fw=codecs.open (outfile, "w", "utf-8") dt = datetime.date.today () fw.write ("%04d-%02d-%02d Automatic import tool\n" % \ (dt.year,dt.month, dt.day))