Python3-related fixes in some of our scripts

Change-Id: I8acbe43e3f27e51159a7a78fcc361476d7406cbb
This commit is contained in:
Solomon Peachy 2020-07-09 10:36:06 -04:00
parent 278a76b3a6
commit dcdf2713f6
4 changed files with 44 additions and 43 deletions

3
.gitignore vendored
View File

@ -7,6 +7,7 @@
*.so *.so
*.o *.o
*.a *.a
__pycache__
# Intermediate language files # Intermediate language files
/apps/lang/*.update /apps/lang/*.update
@ -126,7 +127,7 @@
/tools/database/database /tools/database/database
# /tools/rbspeex/ # /tools/rbspeex/
/tools/rbspeex/build /tools/rbspeex/build*
/tools/rbspeex/libspeex.a /tools/rbspeex/libspeex.a
/tools/rbspeex/librbspeex.a /tools/rbspeex/librbspeex.a
/tools/rbspeex/dep-speex /tools/rbspeex/dep-speex

View File

@ -33,29 +33,29 @@ logfile="/tmp/talkclips.log" # a file where output should be logged
log=open(logfile, 'w') # logging leave this var alone. log=open(logfile, 'w') # logging leave this var alone.
USAGE="Usage: %s <directory>" % (sys.argv[0]) # usage prompt don't touch USAGE="Usage: %s <directory>" % (sys.argv[0]) # usage prompt don't touch
if not os.path.exists(rbspeexenc): 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"\ "or place the binary in %s\n"\
% (rbspeexenc, os.path.realpath(rbspeexenc)) % (rbspeexenc, os.path.realpath(rbspeexenc)))
print USAGE print (USAGE)
exit (-1) # Rbspeexenc not found exit (-1) # Rbspeexenc not found
if not os.path.exists(espeak): if not os.path.exists(espeak):
print "Espeak not found, please install espeak, or adjust the path of\n"\ print ("Espeak not found, please install espeak, or adjust the path of\n"\
'the "espeak" variable appropriately.\n' 'the "espeak" variable appropriately.\n')
print USAGE print (USAGE)
exit (-1) # espeak not found exit (-1) # espeak not found
if len(sys.argv) != 2: if len(sys.argv) != 2:
print USAGE print (USAGE)
exit (-1) # user failed to supply enough arguments exit (-1) # user failed to supply enough arguments
RBDIR=sys.argv[1] # grab user input on the command line (don't touch) RBDIR=sys.argv[1] # grab user input on the command line (don't touch)
if not os.path.exists(sys.argv[1]): if not os.path.exists(sys.argv[1]):
print "The path %s doesn't exist, please try again.\n\n%s"\ print ("The path %s doesn't exist, please try again.\n\n%s"\
% (sys.argv[1], USAGE) % (sys.argv[1], USAGE))
exit(-1) # path doesn't exist exit(-1) # path doesn't exist
else: # check if it's a dir else: # check if it's a dir
if not os.path.isdir(sys.argv[1]): # a file if not os.path.isdir(sys.argv[1]): # a file
print "This script only currently works for directories.\n\n%s" % (USAGE) print ("This script only currently works for directories.\n\n%s" % (USAGE))
exit (-1) # not a dir exit (-1) # not a dir
def gentalkclip(clipname, fullpath, isdir): def gentalkclip(clipname, fullpath, isdir):

View File

@ -3,10 +3,10 @@ import sys
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
if len(sys.argv) != 3: if len(sys.argv) != 3:
print """%s usage: print ("""%s usage:
%s obj1 obj2 %s obj1 obj2
Calculate per-symbol and total size differences between obj1 and 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) sys.exit(2)
obj1 = sys.argv[1] obj1 = sys.argv[1]
@ -16,8 +16,8 @@ def getsyms(obj):
proc = Popen(args=['nm', '-S', '-t', 'd', obj], stdout=PIPE, stderr=PIPE) proc = Popen(args=['nm', '-S', '-t', 'd', obj], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate() out, err = proc.communicate()
if err: if err:
print "nm reported an error:\n" print ("nm reported an error:\n")
print err print (err)
sys.exit(1) sys.exit(1)
d = {} d = {}
for l in out.splitlines(): for l in out.splitlines():
@ -32,23 +32,23 @@ d1 = getsyms(obj1)
d2 = getsyms(obj2) d2 = getsyms(obj2)
l = [(k,v) for k,v in sorted(d1.items()) if k not in d2] l = [(k,v) for k,v in sorted(d1.items()) if k not in d2]
if l: if l:
print "only in %s" % obj1 print ("only in %s" % obj1)
print ''.join(" %6d %s\n" % (v,k) for k,v in l) print (''.join(" %6d %s\n" % (v,k)) for k,v in l)
diff -= sum(v 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] l = [(k,v) for k,v in sorted(d2.items()) if k not in d1]
if l: if l:
print "only in %s" % obj2 print ("only in %s" % obj2)
print ''.join("%6d %s\n" % (v,k) for k,v in l) print (''.join("%6d %s\n" % (v,k)) for k,v in l)
diff += sum(v 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] l = [(k,v,d2[k]) for k,v in sorted(d1.items()) if k in d2 and d2[k] != v]
if l: if l:
print "different sizes in %s and %s:" %(obj1, obj2) 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 (''.join(" %6d %6d %s\n" % (v1,v2,k)) for k,v1,v2 in l)
diff += sum(v2-v1 for k,v1,v2 in l) diff += sum(v2-v1 for k,v1,v2 in l)
if diff: if diff:
print "total size difference: %+d" % diff print ("total size difference: %+d" % diff)
else: else:
print "total size difference: 0" print ("total size difference: 0")

View File

@ -212,7 +212,7 @@ def archive_files(repo, treehash, filelist, basename, tmpfolder=None,
temp_remove = False temp_remove = False
workfolder = scrape_files( workfolder = scrape_files(
repo, treehash, filelist, os.path.join(tmpfolder, basename))[0] repo, treehash, filelist, os.path.join(tmpfolder, basename))[0]
if basename is "": if basename == "":
return "" return ""
print("Archiving files from repository") print("Archiving files from repository")
if archive == "7z": if archive == "7z":