summaryrefslogtreecommitdiff
blob: 62b4db2627ec5bfc14ef4501fcdf4252039422d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
--- ./build/mac/createfont_osx.py	(original)
+++ ./build/mac/createfont_osx.py	(refactored)
@@ -36,7 +36,7 @@
 
 
 def _getBitmapImageRep(size, hasAlpha=True):
-    width, height = map(int, size)
+    width, height = list(map(int, size))
     return NSBitmapImageRep.alloc().initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_(None, width, height, 8, 4, hasAlpha, False, NSDeviceRGBColorSpace, width*4, 32)
 
 
@@ -55,7 +55,7 @@
 
 def filter_range(n):
     offset = 1 # - int(n/5)
-    return range(-n/2 + offset, n/2 + offset)
+    return list(range(-n/2 + offset, n/2 + offset))
 
 
 class SysFont(object):
@@ -79,7 +79,7 @@
                 self._isBold and 'Bold' or '',
                 self._isOblique and 'Oblique' or '')
         self._font = NSFont.fontWithName_size_(name, self._size)
-        print name, self._font
+        print(name, self._font)
         if self._font is None:
             if self._isBold:
                 self._font = NSFont.boldSystemFontOfSize(self._size)
@@ -121,10 +121,10 @@
         self._isUnderline = isUnderline
         
     def size(self, text):
-        return tuple(map(int,map(math.ceil, NSString.sizeWithAttributes_(text, {
+        return tuple(map(int,list(map(math.ceil, NSString.sizeWithAttributes_(text, {
             NSFontAttributeName: self._font,
             NSUnderlineStyleAttributeName: self._isUnderline and 1.0 or 0,
-        }))))
+        })))))
         
     def advancement(self, glyph):
         return tuple(self._font.advancementForGlyph_(ord(glyph)))
@@ -196,7 +196,7 @@
                            [6,  36,  90,  120, 90,  36,  6],
                            [1,  6,   15,  20,  15,  6,   1]]
             else:
-                print "factors for filter size", filter_size, "not defined!"
+                print("factors for filter size", filter_size, "not defined!")
                 factors = 0
 
             # Filter a shadow.
@@ -269,7 +269,7 @@
 
 if __name__=='__main__':
     if len(sys.argv) < 5:
-        print "usage: " + sys.argv[0] + " (font-name) (font-size) (texture-width) (output-file)"
+        print("usage: " + sys.argv[0] + " (font-name) (font-size) (texture-width) (output-file)")
         sys.exit(0)
 
     out_filename = sys.argv[4]
@@ -286,17 +286,17 @@
     
     texture_width = int(sys.argv[3])
     font_point_height = s.get_height()
-    print "Font texture width =", texture_width
-    print "Line height =", font_point_height, "pt"
-    print "Font size =", point_size, "pt"
+    print("Font texture width =", texture_width)
+    print("Line height =", font_point_height, "pt")
+    print("Font size =", point_size, "pt")
     
     ascent = s.get_ascent()
     descent = s.get_descent()
-    print "Ascent =", ascent, "pt  Descent =", descent, "pt"
-    
-    print "Shadow filter is sized %i for this font." % s.shadow_filter_size()
+    print("Ascent =", ascent, "pt  Descent =", descent, "pt")
+    
+    print("Shadow filter is sized %i for this font." % s.shadow_filter_size())
     border_size = s.border_size()
-    print "Glyph borders are %i pixels wide." % border_size
+    print("Glyph borders are %i pixels wide." % border_size)
     
     rover = (0, 0)
     line_height = 0
@@ -304,7 +304,7 @@
     used_pixels = 0
     
     # Only the basic ASCII set, and some specific characters.
-    char_range = range(0x20, 0x7F) + [0x96, 0x97, 0xA3, 0xA4, 0xA9, 0xB0, 0xB1]
+    char_range = list(range(0x20, 0x7F)) + [0x96, 0x97, 0xA3, 0xA4, 0xA9, 0xB0, 0xB1]
     for code in char_range: 
         glyph = Glyph(code)
         try:
@@ -320,7 +320,7 @@
                 # No, move to the new row.
                 rover = (0, rover[1] + line_height)
                 texture_height += line_height
-                print "Finished a %i pixels tall line." % line_height
+                print("Finished a %i pixels tall line." % line_height)
                 line_height = 0
             
             glyph.pos = rover
@@ -332,20 +332,20 @@
             glyphs.append(glyph)
         #except Exception, x:
         except KeyboardInterrupt:
-            print "Code %i: Failed to render." % code
-            print x
-        
-    print "Finished rendering %i glyphs." % len(glyphs)
+            print("Code %i: Failed to render." % code)
+            print(x)
+        
+    print("Finished rendering %i glyphs." % len(glyphs))
     actual_line_height = glyphs[0].dims[1] - border_size*2
-    print "Actual line height is %i pixels." % actual_line_height
-    
-    print "Size of the finished texture is %i x %i." % (texture_width, texture_height)
+    print("Actual line height is %i pixels." % actual_line_height)
+    
+    print("Size of the finished texture is %i x %i." % (texture_width, texture_height))
         
     actual_height = pow2(texture_height)
     total_pixels = texture_width * actual_height
     
-    print "Unused texture area: %.2f %%" % (100*(1.0 - used_pixels/float(total_pixels)))
-    print "Writing output to file: %s" % out_filename
+    print("Unused texture area: %.2f %%" % (100*(1.0 - used_pixels/float(total_pixels))))
+    print("Writing output to file: %s" % out_filename)
     
     out = file(out_filename, 'wb')
     
@@ -365,10 +365,10 @@
     scale = float(actual_line_height) / font_point_height
     pixel_ascent = int(math.ceil(scale * ascent))
     pixel_descent = int(math.ceil(scale * descent))
-    print "    Pixel ascent/descent:", pixel_ascent, '/', pixel_descent
+    print("    Pixel ascent/descent:", pixel_ascent, '/', pixel_descent)
     
     pixel_line_height = int(scale * font_point_height)
-    print "    Pixel line height:", pixel_line_height
+    print("    Pixel line height:", pixel_line_height)
     
     # Ascent and descent.
     out.write(struct.pack('<HHH', pixel_line_height, pixel_ascent, pixel_descent))
@@ -379,7 +379,7 @@
                               g.dims[0], g.dims[1]))
 
     # Glyph map.
-    print "    Writing glyph map..."
+    print("    Writing glyph map...")
     for y in range(texture_height):
         for x in range(texture_width):
             pixel = find_pixel(glyphs, x, y)
--- ./build/scripts/packres.py	(original)
+++ ./build/scripts/packres.py	(refactored)
@@ -6,8 +6,8 @@
 import sys, os, os.path, zipfile
 
 if len(sys.argv) < 2:
-    print "Usage: %s pk3-target-dir" % sys.argv[0]
-    print "(run in build/scripts/)"
+    print("Usage: %s pk3-target-dir" % sys.argv[0])
+    print("(run in build/scripts/)")
     sys.exit(0)
 
 # Check quiet flag.
@@ -27,7 +27,7 @@
         self.files += fileNamesArray
         
     def msg(self, text):
-        if not quietMode: print text
+        if not quietMode: print(text)
         
     def create(self, name):
         full_name = os.path.join(target_dir, name)
@@ -61,7 +61,7 @@
                 process_dir(full_src, dest)
             
         # Write it out.
-        print "Created %s (with %i files)." % (os.path.normpath(full_name), len(pk3.namelist()))
+        print("Created %s (with %i files)." % (os.path.normpath(full_name), len(pk3.namelist())))
         pk3.close()
 
 # First up, doomsday.pk3.
--- ./build/scripts/wadcompiler.py	(original)
+++ ./build/scripts/wadcompiler.py	(refactored)
@@ -49,7 +49,7 @@
         self.type = self.file.read(4)
         count = struct.unpack('<I', self.file.read(4))[0]
         info_offset = struct.unpack('<I', self.file.read(4))[0]
-        print "%s, type=%s, count=%i, info_offset=%i" % (self.file_name, self.type, count, info_offset)
+        print("%s, type=%s, count=%i, info_offset=%i" % (self.file_name, self.type, count, info_offset))
         self.lumps = []
         # Read the info table.
         self.file.seek(info_offset)
@@ -68,7 +68,7 @@
             self.lumps.append( Lump(info[2], data, info[0]) )
         
     def write(self):
-        print 'writing', self.file_name
+        print('writing', self.file_name)
         self.file.truncate()
         self.file.seek(0)
         # Type.
@@ -104,17 +104,17 @@
         
     def set_type(self, new_type):
         if len(new_type) != 4:
-            print "'%s' is not a valid type. Must have 4 chars." % new_type
+            print("'%s' is not a valid type. Must have 4 chars." % new_type)
         else:
-            print 'setting type to %s' % new_type
+            print('setting type to %s' % new_type)
         self.type = new_type
         
     def list(self):
         for i in range(len(self.lumps)):
             lump = self.lumps[i]
-            print "%5i -- %-8s (at %8i, %8i bytes)" % (i, lump.name, lump.offset, 
-                                                       len(lump.data))
-        print "%i lumps total." % len(self.lumps)
+            print("%5i -- %-8s (at %8i, %8i bytes)" % (i, lump.name, lump.offset, 
+                                                       len(lump.data)))
+        print("%i lumps total." % len(self.lumps))
         
     def insert(self, at_lump, names):
         # Where to insert?
@@ -128,13 +128,13 @@
                     at = i
                     break
         if at == -1:
-            print "could not find insert point, aborting"
+            print("could not find insert point, aborting")
             return
-        print "inserting at index %i..." % at
+        print("inserting at index %i..." % at)
         
         for name in names:
             real, arch = split_name(name)
-            print "inserting %s as %s" % (real, valid_lump_name(arch))
+            print("inserting %s as %s" % (real, valid_lump_name(arch)))
             self.lumps.insert(at, Lump(valid_lump_name(arch), 
                                        file(real, 'rb').read(), 0))
     
@@ -164,28 +164,28 @@
                             break
                 else:
                     nice_name += ext
-                print "extracting", lump.name, "(%i bytes) as %s" % (len(lump.data), nice_name)
+                print("extracting", lump.name, "(%i bytes) as %s" % (len(lump.data), nice_name))
                 f = file(nice_name, 'wb')
                 f.write(lump.data)
                 f.close()
 
 
 def usage():
-    print 'Usage: %s [command] [wad] [files]' % sys.argv[0]
-    print 'command = l(ist) | c(reate PWAD) | C(reate IWAD) | x(tract) | a(ppend) | i(nsert) | t(ype)'
-    print 'Examples:'
-    print '%s l some.wad' % sys.argv[0]
-    print '%s c new.wad LUMP1 LUMP2 LUMP3' % sys.argv[0]
-    print '%s i LUMP2 some.wad LUMP5 LUMP6 LUMP7 (at LUMP2)' % sys.argv[0]
-    print '%s a existing.wad LUMP4 LUMP5' % sys.argv[0]
-    print '%s x existing.wad (extracts all lumps)' % sys.argv[0]
-    print '%s x existing.wad LUMP4 (extracts selected lumps)' % sys.argv[0]
-    print '%s t existing.wad IWAD' % sys.argv[0]
-    print 'You can specify files as realfilename@LUMPNAME.'
+    print('Usage: %s [command] [wad] [files]' % sys.argv[0])
+    print('command = l(ist) | c(reate PWAD) | C(reate IWAD) | x(tract) | a(ppend) | i(nsert) | t(ype)')
+    print('Examples:')
+    print('%s l some.wad' % sys.argv[0])
+    print('%s c new.wad LUMP1 LUMP2 LUMP3' % sys.argv[0])
+    print('%s i LUMP2 some.wad LUMP5 LUMP6 LUMP7 (at LUMP2)' % sys.argv[0])
+    print('%s a existing.wad LUMP4 LUMP5' % sys.argv[0])
+    print('%s x existing.wad (extracts all lumps)' % sys.argv[0])
+    print('%s x existing.wad LUMP4 (extracts selected lumps)' % sys.argv[0])
+    print('%s t existing.wad IWAD' % sys.argv[0])
+    print('You can specify files as realfilename@LUMPNAME.')
    
 # Call main function.
-print 'WAD Compiler by skyjake@users.sourceforge.net'
-print '$Date$'
+print('WAD Compiler by skyjake@users.sourceforge.net')
+print('$Date$')
 
 # Check the args.
 if len(sys.argv) < 3:
@@ -219,7 +219,7 @@
     try:
         wad = Wad(wad_name, mode)
     except:
-        print 'Failure to open %s.' % wad_name
+        print('Failure to open %s.' % wad_name)
         import traceback
         traceback.print_exc()
         sys.exit(2)
--- ./engine/scripts/makedmt.py	(original)
+++ ./engine/scripts/makedmt.py	(refactored)
@@ -118,7 +118,7 @@
             # Translate the type into a real C type.
             if '_s' in c_type:
                 c_type = 'struct ' + c_type
-            for symbol, real in type_replacements.items():
+            for symbol, real in list(type_replacements.items()):
                 c_type = c_type.replace(symbol, real)
             
             # Add some visual padding to align the members.