diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-07-09 10:36:06 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-07-09 14:39:27 +0000 |
commit | dcdf2713f610cb3cfaa615ab9b8d4b9412e7a8b6 (patch) | |
tree | e0b581aa203158e9dab01398f38a0b1a82adc6ee | |
parent | 278a76b3a6dbf658bd0d3ad67ad7f15d8b8fa32a (diff) | |
download | rockbox-dcdf2713f610cb3cfaa615ab9b8d4b9412e7a8b6.tar.gz rockbox-dcdf2713f610cb3cfaa615ab9b8d4b9412e7a8b6.zip |
Python3-related fixes in some of our scripts
Change-Id: I8acbe43e3f27e51159a7a78fcc361476d7406cbb
-rw-r--r-- | .gitignore | 3 | ||||
-rwxr-xr-x | tools/talkclips.py | 58 | ||||
-rwxr-xr-x | utils/analysis/objdiff.py | 24 | ||||
-rwxr-xr-x | 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 @@ | |||
7 | *.so | 7 | *.so |
8 | *.o | 8 | *.o |
9 | *.a | 9 | *.a |
10 | __pycache__ | ||
10 | 11 | ||
11 | # Intermediate language files | 12 | # Intermediate language files |
12 | /apps/lang/*.update | 13 | /apps/lang/*.update |
@@ -126,7 +127,7 @@ | |||
126 | /tools/database/database | 127 | /tools/database/database |
127 | 128 | ||
128 | # /tools/rbspeex/ | 129 | # /tools/rbspeex/ |
129 | /tools/rbspeex/build | 130 | /tools/rbspeex/build* |
130 | /tools/rbspeex/libspeex.a | 131 | /tools/rbspeex/libspeex.a |
131 | /tools/rbspeex/librbspeex.a | 132 | /tools/rbspeex/librbspeex.a |
132 | /tools/rbspeex/dep-speex | 133 | /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 | |||
23 | # The following lines provide variables which you can modify to adjust | 23 | # The following lines provide variables which you can modify to adjust |
24 | # settings... See comments next to each line. | 24 | # settings... See comments next to each line. |
25 | # Start opts: | 25 | # Start opts: |
26 | espeak = '/usr/bin/espeak' # location of easpeak binary | 26 | espeak = '/usr/bin/espeak' # location of easpeak binary |
27 | rbspeexenc = './rbspeexenc' # path to rbspeexenc binary (default currentdir) | 27 | rbspeexenc = './rbspeexenc' # path to rbspeexenc binary (default currentdir) |
28 | VOPTS=espeak+" -s 320 -z" # Your espeak opts | 28 | VOPTS=espeak+" -s 320 -z" # Your espeak opts |
29 | ROPTS=rbspeexenc+" -q 4 -c 10" # rbspeex opts | 29 | ROPTS=rbspeexenc+" -q 4 -c 10" # rbspeex opts |
30 | logfile="/tmp/talkclips.log" # a file where output should be logged | 30 | logfile="/tmp/talkclips.log" # a file where output should be logged |
31 | # End opts | 31 | # End opts |
32 | # Don't touch the below settings. Unless you know what your doing. | 32 | # Don't touch the below settings. Unless you know what your doing. |
33 | log=open(logfile, 'w') # logging leave this var alone. | 33 | log=open(logfile, 'w') # logging leave this var alone. |
34 | USAGE="Usage: %s <directory>" % (sys.argv[0]) # usage prompt don't touch | 34 | USAGE="Usage: %s <directory>" % (sys.argv[0]) # usage prompt don't touch |
35 | if not os.path.exists(rbspeexenc): | 35 | if not os.path.exists(rbspeexenc): |
36 | print "%s not found, please change your rbspeexenc path appropriately,\n"\ | 36 | print ("%s not found, please change your rbspeexenc path appropriately,\n"\ |
37 | "or place the binary in %s\n"\ | 37 | "or place the binary in %s\n"\ |
38 | % (rbspeexenc, os.path.realpath(rbspeexenc)) | 38 | % (rbspeexenc, os.path.realpath(rbspeexenc))) |
39 | print USAGE | 39 | print (USAGE) |
40 | exit (-1) # Rbspeexenc not found | 40 | exit (-1) # Rbspeexenc not found |
41 | if not os.path.exists(espeak): | 41 | if not os.path.exists(espeak): |
42 | print "Espeak not found, please install espeak, or adjust the path of\n"\ | 42 | print ("Espeak not found, please install espeak, or adjust the path of\n"\ |
43 | 'the "espeak" variable appropriately.\n' | 43 | 'the "espeak" variable appropriately.\n') |
44 | print USAGE | 44 | print (USAGE) |
45 | exit (-1) # espeak not found | 45 | exit (-1) # espeak not found |
46 | 46 | ||
47 | if len(sys.argv) != 2: | 47 | if len(sys.argv) != 2: |
48 | print USAGE | 48 | print (USAGE) |
49 | exit (-1) # user failed to supply enough arguments | 49 | exit (-1) # user failed to supply enough arguments |
50 | 50 | ||
51 | RBDIR=sys.argv[1] # grab user input on the command line (don't touch) | 51 | RBDIR=sys.argv[1] # grab user input on the command line (don't touch) |
52 | if not os.path.exists(sys.argv[1]): | 52 | if not os.path.exists(sys.argv[1]): |
53 | print "The path %s doesn't exist, please try again.\n\n%s"\ | 53 | print ("The path %s doesn't exist, please try again.\n\n%s"\ |
54 | % (sys.argv[1], USAGE) | 54 | % (sys.argv[1], USAGE)) |
55 | exit(-1) # path doesn't exist | 55 | exit(-1) # path doesn't exist |
56 | else: # check if it's a dir | 56 | else: # check if it's a dir |
57 | if not os.path.isdir(sys.argv[1]): # a file | 57 | if not os.path.isdir(sys.argv[1]): # a file |
58 | print "This script only currently works for directories.\n\n%s" % (USAGE) | 58 | print ("This script only currently works for directories.\n\n%s" % (USAGE)) |
59 | exit (-1) # not a dir | 59 | exit (-1) # not a dir |
60 | 60 | ||
61 | def gentalkclip(clipname, fullpath, isdir): | 61 | def gentalkclip(clipname, fullpath, isdir): |
62 | """Generate an individual talk clip. | 62 | """Generate an individual talk clip. |
@@ -65,23 +65,23 @@ def gentalkclip(clipname, fullpath, isdir): | |||
65 | synth, and encoder, and save accordingly.""" | 65 | synth, and encoder, and save accordingly.""" |
66 | 66 | ||
67 | if isdir: # directory | 67 | if isdir: # directory |
68 | output=os.path.join(fullpath, "_dirname.talk") # dir clip name | 68 | output=os.path.join(fullpath, "_dirname.talk") # dir clip name |
69 | if os.path.exists(output): | 69 | if os.path.exists(output): |
70 | return True # no need to create again | 70 | return True # no need to create again |
71 | try: # Don't let the script stop if bash raises filename errors | 71 | try: # Don't let the script stop if bash raises filename errors |
72 | os.system('%s "%s" -w "%s"' % (VOPTS, clipname, output+".tmp")) | 72 | os.system('%s "%s" -w "%s"' % (VOPTS, clipname, output+".tmp")) |
73 | os.system('%s "%s" "%s"' % (ROPTS, output+".tmp", output)) | 73 | os.system('%s "%s" "%s"' % (ROPTS, output+".tmp", output)) |
74 | os.remove(output+".tmp") # delete the old wav file | 74 | os.remove(output+".tmp") # delete the old wav file |
75 | except OSError: | 75 | except OSError: |
76 | log.write('Failed to create clip for directory: "%s"\n' % (clipname)) | 76 | log.write('Failed to create clip for directory: "%s"\n' % (clipname)) |
77 | return False | 77 | return False |
78 | log.write( 'Created clip for directory: "%s"\n' % (clipname)) # log | 78 | log.write( 'Created clip for directory: "%s"\n' % (clipname)) # log |
79 | return True | 79 | return True |
80 | else: # file | 80 | else: # file |
81 | output=fullpath+".talk" | 81 | output=fullpath+".talk" |
82 | if os.path.exists(output): | 82 | if os.path.exists(output): |
83 | return True # no need to create again | 83 | return True # no need to create again |
84 | try: | 84 | try: |
85 | os.system('%s "%s" -w "%s"' % (VOPTS, clipname, output+".tmp")) | 85 | os.system('%s "%s" -w "%s"' % (VOPTS, clipname, output+".tmp")) |
86 | os.system('%s "%s" "%s"' % (ROPTS, output+".tmp", output)) | 86 | os.system('%s "%s" "%s"' % (ROPTS, output+".tmp", output)) |
87 | os.remove (output+".tmp") | 87 | os.remove (output+".tmp") |
@@ -89,7 +89,7 @@ def gentalkclip(clipname, fullpath, isdir): | |||
89 | log.write('Failed to create clip for file: "%s"\n' % (clipname)) | 89 | log.write('Failed to create clip for file: "%s"\n' % (clipname)) |
90 | return False # something failed, so continue with next file | 90 | return False # something failed, so continue with next file |
91 | log.write('Created clip for file: "%s"\n' % (clipname)) # logging | 91 | log.write('Created clip for file: "%s"\n' % (clipname)) # logging |
92 | return True # clips created | 92 | return True # clips created |
93 | 93 | ||
94 | def istalkclip(file): | 94 | def istalkclip(file): |
95 | """Is file a talkclip? | 95 | """Is file a talkclip? |
@@ -110,12 +110,12 @@ def walker(directory): | |||
110 | for item in os.listdir(directory): # get subdirs and files | 110 | for item in os.listdir(directory): # get subdirs and files |
111 | if os.path.isdir(os.path.join(directory, item)): | 111 | if os.path.isdir(os.path.join(directory, item)): |
112 | gentalkclip (item, os.path.join(directory, item), True) # its a dir | 112 | gentalkclip (item, os.path.join(directory, item), True) # its a dir |
113 | walker(os.path.join(directory, item)) # go down into this sub dir | 113 | walker(os.path.join(directory, item)) # go down into this sub dir |
114 | continue | 114 | continue |
115 | else: # a file | 115 | else: # a file |
116 | if istalkclip (item): | 116 | if istalkclip (item): |
117 | continue # is a talk clip | 117 | continue # is a talk clip |
118 | else: # create clip | 118 | else: # create clip |
119 | gentalkclip(item, os.path.join(directory, item), False) # a file | 119 | gentalkclip(item, os.path.join(directory, item), False) # a file |
120 | continue | 120 | continue |
121 | 121 | ||
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 | |||
3 | from subprocess import Popen, PIPE | 3 | from subprocess import Popen, PIPE |
4 | 4 | ||
5 | if len(sys.argv) != 3: | 5 | if len(sys.argv) != 3: |
6 | print """%s usage: | 6 | print ("""%s usage: |
7 | %s obj1 obj2 | 7 | %s obj1 obj2 |
8 | Calculate per-symbol and total size differences between obj1 and obj2, | 8 | Calculate per-symbol and total size differences between obj1 and obj2, |
9 | which may be any files that nm can read""" % ((sys.argv[0],)*2) | 9 | which may be any files that nm can read""" % ((sys.argv[0],)*2)) |
10 | sys.exit(2) | 10 | sys.exit(2) |
11 | 11 | ||
12 | obj1 = sys.argv[1] | 12 | obj1 = sys.argv[1] |
@@ -16,8 +16,8 @@ def getsyms(obj): | |||
16 | proc = Popen(args=['nm', '-S', '-t', 'd', obj], stdout=PIPE, stderr=PIPE) | 16 | proc = Popen(args=['nm', '-S', '-t', 'd', obj], stdout=PIPE, stderr=PIPE) |
17 | out, err = proc.communicate() | 17 | out, err = proc.communicate() |
18 | if err: | 18 | if err: |
19 | print "nm reported an error:\n" | 19 | print ("nm reported an error:\n") |
20 | print err | 20 | print (err) |
21 | sys.exit(1) | 21 | sys.exit(1) |
22 | d = {} | 22 | d = {} |
23 | for l in out.splitlines(): | 23 | for l in out.splitlines(): |
@@ -32,23 +32,23 @@ d1 = getsyms(obj1) | |||
32 | d2 = getsyms(obj2) | 32 | d2 = getsyms(obj2) |
33 | l = [(k,v) for k,v in sorted(d1.items()) if k not in d2] | 33 | l = [(k,v) for k,v in sorted(d1.items()) if k not in d2] |
34 | if l: | 34 | if l: |
35 | print "only in %s" % obj1 | 35 | print ("only in %s" % obj1) |
36 | print ''.join(" %6d %s\n" % (v,k) for k,v in l) | 36 | print (''.join(" %6d %s\n" % (v,k)) for k,v in l) |
37 | diff -= sum(v for k,v in l) | 37 | diff -= sum(v for k,v in l) |
38 | 38 | ||
39 | l = [(k,v) for k,v in sorted(d2.items()) if k not in d1] | 39 | l = [(k,v) for k,v in sorted(d2.items()) if k not in d1] |
40 | if l: | 40 | if l: |
41 | print "only in %s" % obj2 | 41 | print ("only in %s" % obj2) |
42 | print ''.join("%6d %s\n" % (v,k) for k,v in l) | 42 | print (''.join("%6d %s\n" % (v,k)) for k,v in l) |
43 | diff += sum(v for k,v in l) | 43 | diff += sum(v for k,v in l) |
44 | 44 | ||
45 | l = [(k,v,d2[k]) for k,v in sorted(d1.items()) if k in d2 and d2[k] != v] | 45 | l = [(k,v,d2[k]) for k,v in sorted(d1.items()) if k in d2 and d2[k] != v] |
46 | if l: | 46 | if l: |
47 | print "different sizes in %s and %s:" %(obj1, obj2) | 47 | print ("different sizes in %s and %s:" %(obj1, obj2)) |
48 | print ''.join(" %6d %6d %s\n" % (v1,v2,k) for k,v1,v2 in l) | 48 | print (''.join(" %6d %6d %s\n" % (v1,v2,k)) for k,v1,v2 in l) |
49 | diff += sum(v2-v1 for k,v1,v2 in l) | 49 | diff += sum(v2-v1 for k,v1,v2 in l) |
50 | 50 | ||
51 | if diff: | 51 | if diff: |
52 | print "total size difference: %+d" % diff | 52 | print ("total size difference: %+d" % diff) |
53 | else: | 53 | else: |
54 | print "total size difference: 0" | 54 | 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, | |||
212 | temp_remove = False | 212 | temp_remove = False |
213 | workfolder = scrape_files( | 213 | workfolder = scrape_files( |
214 | repo, treehash, filelist, os.path.join(tmpfolder, basename))[0] | 214 | repo, treehash, filelist, os.path.join(tmpfolder, basename))[0] |
215 | if basename is "": | 215 | if basename == "": |
216 | return "" | 216 | return "" |
217 | print("Archiving files from repository") | 217 | print("Archiving files from repository") |
218 | if archive == "7z": | 218 | if archive == "7z": |