From dcdf2713f610cb3cfaa615ab9b8d4b9412e7a8b6 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 9 Jul 2020 10:36:06 -0400 Subject: Python3-related fixes in some of our scripts Change-Id: I8acbe43e3f27e51159a7a78fcc361476d7406cbb --- .gitignore | 3 ++- tools/talkclips.py | 58 +++++++++++++++++++++++----------------------- utils/analysis/objdiff.py | 24 +++++++++---------- utils/common/gitscraper.py | 2 +- 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index 6cdf75db70..476d0bbf8e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.so *.o *.a +__pycache__ # Intermediate language files /apps/lang/*.update @@ -126,7 +127,7 @@ /tools/database/database # /tools/rbspeex/ -/tools/rbspeex/build +/tools/rbspeex/build* /tools/rbspeex/libspeex.a /tools/rbspeex/librbspeex.a /tools/rbspeex/dep-speex diff --git a/tools/talkclips.py b/tools/talkclips.py index 425c1b12bf..7f34608f44 100755 --- a/tools/talkclips.py +++ b/tools/talkclips.py @@ -23,40 +23,40 @@ import sys # The following lines provide variables which you can modify to adjust # settings... See comments next to each line. # Start opts: -espeak = '/usr/bin/espeak' # location of easpeak binary +espeak = '/usr/bin/espeak' # location of easpeak binary rbspeexenc = './rbspeexenc' # path to rbspeexenc binary (default currentdir) -VOPTS=espeak+" -s 320 -z" # Your espeak opts -ROPTS=rbspeexenc+" -q 4 -c 10" # rbspeex opts +VOPTS=espeak+" -s 320 -z" # Your espeak opts +ROPTS=rbspeexenc+" -q 4 -c 10" # rbspeex opts logfile="/tmp/talkclips.log" # a file where output should be logged -# End opts -# Don't touch the below settings. Unless you know what your doing. -log=open(logfile, 'w') # logging leave this var alone. -USAGE="Usage: %s " % (sys.argv[0]) # usage prompt don't touch +# End opts +# Don't touch the below settings. Unless you know what your doing. +log=open(logfile, 'w') # logging leave this var alone. +USAGE="Usage: %s " % (sys.argv[0]) # usage prompt don't touch if not os.path.exists(rbspeexenc): - print "%s not found, please change your rbspeexenc path appropriately,\n"\ + print ("%s not found, please change your rbspeexenc path appropriately,\n"\ "or place the binary in %s\n"\ - % (rbspeexenc, os.path.realpath(rbspeexenc)) - print USAGE - exit (-1) # Rbspeexenc not found + % (rbspeexenc, os.path.realpath(rbspeexenc))) + print (USAGE) + exit (-1) # Rbspeexenc not found if not os.path.exists(espeak): - print "Espeak not found, please install espeak, or adjust the path of\n"\ - 'the "espeak" variable appropriately.\n' - print USAGE - exit (-1) # espeak not found + print ("Espeak not found, please install espeak, or adjust the path of\n"\ + 'the "espeak" variable appropriately.\n') + print (USAGE) + exit (-1) # espeak not found if len(sys.argv) != 2: - print USAGE + print (USAGE) exit (-1) # user failed to supply enough arguments RBDIR=sys.argv[1] # grab user input on the command line (don't touch) if not os.path.exists(sys.argv[1]): - print "The path %s doesn't exist, please try again.\n\n%s"\ - % (sys.argv[1], USAGE) + print ("The path %s doesn't exist, please try again.\n\n%s"\ + % (sys.argv[1], USAGE)) exit(-1) # path doesn't exist else: # check if it's a dir if not os.path.isdir(sys.argv[1]): # a file - print "This script only currently works for directories.\n\n%s" % (USAGE) - exit (-1) # not a dir + print ("This script only currently works for directories.\n\n%s" % (USAGE)) + exit (-1) # not a dir def gentalkclip(clipname, fullpath, isdir): """Generate an individual talk clip. @@ -65,23 +65,23 @@ def gentalkclip(clipname, fullpath, isdir): synth, and encoder, and save accordingly.""" if isdir: # directory - output=os.path.join(fullpath, "_dirname.talk") # dir clip name + output=os.path.join(fullpath, "_dirname.talk") # dir clip name if os.path.exists(output): return True # no need to create again try: # Don't let the script stop if bash raises filename errors os.system('%s "%s" -w "%s"' % (VOPTS, clipname, output+".tmp")) os.system('%s "%s" "%s"' % (ROPTS, output+".tmp", output)) - os.remove(output+".tmp") # delete the old wav file + os.remove(output+".tmp") # delete the old wav file except OSError: - log.write('Failed to create clip for directory: "%s"\n' % (clipname)) - return False + log.write('Failed to create clip for directory: "%s"\n' % (clipname)) + return False log.write( 'Created clip for directory: "%s"\n' % (clipname)) # log - return True + return True else: # file output=fullpath+".talk" if os.path.exists(output): return True # no need to create again - try: + try: os.system('%s "%s" -w "%s"' % (VOPTS, clipname, output+".tmp")) os.system('%s "%s" "%s"' % (ROPTS, output+".tmp", output)) os.remove (output+".tmp") @@ -89,7 +89,7 @@ def gentalkclip(clipname, fullpath, isdir): log.write('Failed to create clip for file: "%s"\n' % (clipname)) return False # something failed, so continue with next file log.write('Created clip for file: "%s"\n' % (clipname)) # logging - return True # clips created + return True # clips created def istalkclip(file): """Is file a talkclip? @@ -110,12 +110,12 @@ def walker(directory): for item in os.listdir(directory): # get subdirs and files if os.path.isdir(os.path.join(directory, item)): gentalkclip (item, os.path.join(directory, item), True) # its a dir - walker(os.path.join(directory, item)) # go down into this sub dir + walker(os.path.join(directory, item)) # go down into this sub dir continue else: # a file if istalkclip (item): continue # is a talk clip - else: # create clip + else: # create clip gentalkclip(item, os.path.join(directory, item), False) # a file continue diff --git a/utils/analysis/objdiff.py b/utils/analysis/objdiff.py index dc51441bfa..29f703e52a 100755 --- a/utils/analysis/objdiff.py +++ b/utils/analysis/objdiff.py @@ -3,10 +3,10 @@ import sys from subprocess import Popen, PIPE if len(sys.argv) != 3: - print """%s usage: + print ("""%s usage: %s obj1 obj2 Calculate per-symbol and total size differences between obj1 and obj2, - which may be any files that nm can read""" % ((sys.argv[0],)*2) + which may be any files that nm can read""" % ((sys.argv[0],)*2)) sys.exit(2) obj1 = sys.argv[1] @@ -16,8 +16,8 @@ def getsyms(obj): proc = Popen(args=['nm', '-S', '-t', 'd', obj], stdout=PIPE, stderr=PIPE) out, err = proc.communicate() if err: - print "nm reported an error:\n" - print err + print ("nm reported an error:\n") + print (err) sys.exit(1) d = {} for l in out.splitlines(): @@ -32,23 +32,23 @@ d1 = getsyms(obj1) d2 = getsyms(obj2) l = [(k,v) for k,v in sorted(d1.items()) if k not in d2] if l: - print "only in %s" % obj1 - print ''.join(" %6d %s\n" % (v,k) for k,v in l) + print ("only in %s" % obj1) + print (''.join(" %6d %s\n" % (v,k)) for k,v in l) diff -= sum(v for k,v in l) l = [(k,v) for k,v in sorted(d2.items()) if k not in d1] if l: - print "only in %s" % obj2 - print ''.join("%6d %s\n" % (v,k) for k,v in l) + print ("only in %s" % obj2) + print (''.join("%6d %s\n" % (v,k)) for k,v in l) diff += sum(v for k,v in l) l = [(k,v,d2[k]) for k,v in sorted(d1.items()) if k in d2 and d2[k] != v] if l: - print "different sizes in %s and %s:" %(obj1, obj2) - print ''.join(" %6d %6d %s\n" % (v1,v2,k) for k,v1,v2 in l) + print ("different sizes in %s and %s:" %(obj1, obj2)) + print (''.join(" %6d %6d %s\n" % (v1,v2,k)) for k,v1,v2 in l) diff += sum(v2-v1 for k,v1,v2 in l) if diff: - print "total size difference: %+d" % diff + print ("total size difference: %+d" % diff) else: - print "total size difference: 0" + print ("total size difference: 0") diff --git a/utils/common/gitscraper.py b/utils/common/gitscraper.py index 496d32bce3..c7a2c3a563 100755 --- a/utils/common/gitscraper.py +++ b/utils/common/gitscraper.py @@ -212,7 +212,7 @@ def archive_files(repo, treehash, filelist, basename, tmpfolder=None, temp_remove = False workfolder = scrape_files( repo, treehash, filelist, os.path.join(tmpfolder, basename))[0] - if basename is "": + if basename == "": return "" print("Archiving files from repository") if archive == "7z": -- cgit v1.2.3