File python3.patch of Package solarwolf
Author: Reiner Herrmann <reiner@reiner-h.de>
Description: Port to Python 3
Bug-Debian: https://bugs.debian.org/912486
Bug-Debian: https://bugs.debian.org/938512
Forwarded: no
--- a/solarwolf.py
+++ b/solarwolf.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""
Solarwolf, created by Pete Shinners.
"""
@@ -39,8 +39,8 @@
import game
if game.DEBUG >= 2:
import pychecker.checker
- print 'Pychecker Enabled'
- except ImportError, m:
+ print('Pychecker Enabled')
+ except ImportError as m:
pass
#run game and protect from exceptions
@@ -48,14 +48,14 @@
import main, pygame
main.main(sys.argv)
except KeyboardInterrupt:
- print 'Keyboard Interrupt (Control-C)...'
+ print('Keyboard Interrupt (Control-C)...')
except:
#must wait on any threading
if game.thread:
game.threadstop = 1
while game.thread:
pygame.time.wait(10)
- print 'waiting on thread...'
+ print('waiting on thread...')
exception_handler()
if game.DEBUG:
raise
--- a/code/game.py
+++ b/code/game.py
@@ -2,7 +2,7 @@
import os
from pygame.rect import Rect
-from cStringIO import StringIO
+from io import StringIO
@@ -105,7 +105,7 @@
home = os.environ['HOME']
fullhome = os.path.join(home, '.solarwolf')
if not os.path.isdir(fullhome):
- try: os.mkdir(fullhome, 0755)
+ try: os.mkdir(fullhome, 0o755)
except OSError: fullhome = home
filename = os.path.join(fullhome, filename)
else:
--- a/code/gamehelp.py
+++ b/code/gamehelp.py
@@ -128,7 +128,7 @@
def help(helpname, helppos):
- if not game.player.help.has_key(helpname):
+ if helpname not in game.player.help:
game.player.help[helpname] = 1
if game.help == 0:
game.handler = GameHelp(game.handler, helpname, helppos)
@@ -179,7 +179,7 @@
def drawhelp(self, name, pos):
- if Help.has_key(name):
+ if name in Help:
text = Help[name]
lines = text.splitlines()
for x in range(1, len(lines)):
@@ -193,7 +193,7 @@
self.img = fonts[0].textbox((255, 240, 200), text, 260, (50, 100, 50), 30)
r = self.img.get_rect()
- titleimg, titlepos = fonts[1].text((255, 240, 200), title, (r.width/2, 10))
+ titleimg, titlepos = fonts[1].text((255, 240, 200), title, (r.width//2, 10))
self.img.blit(titleimg, titlepos)
r.topleft = pos
r = r.clamp(game.arena)
--- a/code/gamename.py
+++ b/code/gamename.py
@@ -13,7 +13,7 @@
import gamenews
-charset = string.uppercase + '-.'
+charset = string.ascii_uppercase + '-.'
fontlookup = {}
fontimages = []
images = []
@@ -35,8 +35,8 @@
xsize, ysize = 70, 80
step = 0
for letter in charset + '<>':
- pos = xoffset+xsize*(step%10), yoffset+ysize*(step/10)
- if extraimgs.has_key(letter):
+ pos = xoffset+xsize*(step%10), yoffset+ysize*(step//10)
+ if letter in extraimgs:
img = img2 = extraimgs[letter]
r = img.get_rect()
r.center = pos
--- a/code/gamenews.py
+++ b/code/gamenews.py
@@ -32,7 +32,7 @@
images.append((img, r))
img = gfx.load('download.png')
- downimgs = gfx.animstrip(img, img.get_width()/2)
+ downimgs = gfx.animstrip(img, img.get_width()//2)
for i in ('downerror', 'newversion', 'downok'):
img = gfx.load(i+'.gif')
downimgs.append(img)
@@ -302,7 +302,7 @@
if self.downcur == 3:
img = self.downimgs[2]
else:
- self.downcur = (self.clocks / 8) % 2 + 1
+ self.downcur = (self.clocks // 8) % 2 + 1
img = self.downimgs[self.downcur-1]
return img, img.get_rect().move(self.downloadpos)
--- a/code/gamepause.py
+++ b/code/gamepause.py
@@ -30,7 +30,7 @@
self.img = fonts[0].textbox((255, 240, 200), text, 200, (50, 100, 50), 50)
r = self.img.get_rect()
- titleimg, titlepos = fonts[1].text((255, 240, 200), title, (r.width/2, 10))
+ titleimg, titlepos = fonts[1].text((255, 240, 200), title, (r.width//2, 10))
self.img.blit(titleimg, titlepos)
r.topleft = pos
r = r.clamp(game.arena)
--- a/code/gamepref.py
+++ b/code/gamepref.py
@@ -39,7 +39,7 @@
val = getattr(game, p)
f.write("%s = %d\n" % (p, int(val)))
f.close()
- except (IOError, OSError), msg:
+ except (IOError, OSError) as msg:
#print 'ERROR SAVING PREFS FILE'
pass
--- a/code/gamesetup.py
+++ b/code/gamesetup.py
@@ -80,13 +80,13 @@
def moveto(self, pos):
if self.shipdir == SHIPUP:
- self.shippos = pos[0] - (self.images[0][1].width / 2), pos[1]
+ self.shippos = pos[0] - (self.images[0][1].width // 2), pos[1]
elif self.shipdir == SHIPDOWN:
- self.shippos = pos[0] - (self.images[0][1].width / 2), pos[1] - self.images[0][1].height
+ self.shippos = pos[0] - (self.images[0][1].width // 2), pos[1] - self.images[0][1].height
elif self.shipdir == SHIPRIGHT:
- self.shippos = pos[0] - self.images[0][1].width, pos[1] - (self.images[0][1].height / 2)
+ self.shippos = pos[0] - self.images[0][1].width, pos[1] - (self.images[0][1].height // 2)
else:
- self.shippos == pos[0], pos[1] - (self.images[0][1].height / 2)
+ self.shippos == pos[0], pos[1] - (self.images[0][1].height // 2)
def displayevent(self, i):
if i.normalized != None:
@@ -152,7 +152,7 @@
def selectall(self):
snd.play('select_choose')
self.clearactionlist()
- if not input.translations.has_key(NOEVENT):
+ if NOEVENT not in input.translations:
input.translations[NOEVENT] = {}
input.translations[NOEVENT][KEYDOWN] = input.actions_order[self.currentaction]
input.translations[NOEVENT][JOYBUTTONDOWN] = input.actions_order[self.currentaction]
@@ -205,13 +205,13 @@
if currentcontrol < len(self.display[input.actions_order[self.currentaction]]):
self.currentcontrol = currentcontrol
elif i.translated == input.LEFT:
- self.currentcontrol = (self.currentcontrol - 1) % 6 + 6 * (self.currentcontrol / 6)
+ self.currentcontrol = (self.currentcontrol - 1) % 6 + 6 * (self.currentcontrol // 6)
if self.currentcontrol >= len(self.display[input.actions_order[self.currentaction]]):
self.currentcontrol = len(self.display[input.actions_order[self.currentaction]]) - 1
elif i.translated == input.RIGHT:
- self.currentcontrol = (self.currentcontrol + 1) % 6 + 6 * (self.currentcontrol / 6)
+ self.currentcontrol = (self.currentcontrol + 1) % 6 + 6 * (self.currentcontrol // 6)
if self.currentcontrol >= len(self.display[input.actions_order[self.currentaction]]):
- self.currentcontrol = 6 * (self.currentcontrol / 6)
+ self.currentcontrol = 6 * (self.currentcontrol // 6)
snd.play('select_move')
self.moveto(self.targetcontrol())
pass
@@ -257,7 +257,7 @@
global textfontheight
for l in range(16):
x = 90 + 100 * (l % 6)
- y = 36 + 22 * (l / 6)
+ y = 36 + 22 * (l // 6)
w = 100
h = textfontheight
r = pygame.Rect(x, y, w, h)
--- a/code/gfx.py
+++ b/code/gfx.py
@@ -32,8 +32,8 @@
if surface.get_bytesize() == 1:
loadpalette()
- except pygame.error, msg:
- raise pygame.error, 'Cannot Initialize Graphics'
+ except pygame.error as msg:
+ raise pygame.error('Cannot Initialize Graphics')
starobj = stars.Stars()
--- a/code/input.py
+++ b/code/input.py
@@ -158,16 +158,16 @@
global exclusivedict
thislist = str(list)
if i.translated in list:
- if not exclusivedict.has_key(thislist):
+ if thislist not in exclusivedict:
exclusivedict[thislist] = {}
table = exclusivedict[thislist]
if i.release:
- if not table.has_key(i.translated):
+ if i.translated not in table:
table[i.translated] = 0
else:
table[i.translated] -= 1
else:
- if not table.has_key(i.translated):
+ if i.translated not in table:
table[i.translated] = 1
else:
table[i.translated] += 1
@@ -207,11 +207,11 @@
dir = os.environ.get('HOME', '.')
file = 'solarwolf%02d.bmp' % ScreenshotNum
fullname = os.path.join(dir, file)
- print 'Screenshot:', fullname
+ print('Screenshot: {}'.format(fullname))
try:
pygame.image.save(pygame.display.get_surface(), fullname)
except:
- print ' Screenshot FAILED'
+ print(' Screenshot FAILED')
ScreenshotNum += 1
elif event.key not in (K_NUMLOCK, K_CAPSLOCK):
normalized = event.key
@@ -306,12 +306,12 @@
else:
direction = "+"
value = AXISMORE
- axis = str( (normalized - value) / 2 )
+ axis = str( (normalized - value) // 2 )
return 'Axis' + axis + direction
elif type == JOYHATMOTION:
value = HATSTART + normalized % 4
direction = hat_direction_text[value]
- hat = str( (normalized - value) / 4 )
+ hat = str( (normalized - value) // 4 )
return 'Hat' + hat + direction
elif type == NOEVENT:
return "*AllElse*"
@@ -321,7 +321,7 @@
display = {}
for type, table in translations.items():
for normalized, action in table.items():
- if not display.has_key(action):
+ if action not in display:
display[action] = []
if type != NOEVENT:
display[action].append((type, normalized))
@@ -343,7 +343,7 @@
for l in range(len(display[a])):
type = display[a][l][0]
normalized = display[a][l][1]
- if not translations.has_key(type):
+ if type not in translations:
translations[type] = {}
if type != NOEVENT:
translations[type][normalized] = a
@@ -374,7 +374,7 @@
p = pickle.Pickler(f, 1)
p.dump(translations)
f.close()
- except (IOError, OSError), msg:
+ except (IOError, OSError) as msg:
import messagebox
messagebox.error("Error Saving Control Data",
"There was an error saving the control data.\nCurrent player controls have been lost.\n\n%s"%msg)
--- a/code/levels.py
+++ b/code/levels.py
@@ -40,14 +40,14 @@
"returns (list, startcenter) level number"
if not initialized: init()
lev = Levels[level%len(Levels)]
- touches = level/len(Levels) + 1
+ touches = level//len(Levels) + 1
passes = (level>len(Levels) and 2) or 1
boxlist = []
size = 58, 58
corner = 106, 106
startpos = corner[0]+236, corner[1]+182
pos = [corner[0], corner[1]]
- numboxes = level/2
+ numboxes = level//2
for row in lev[2:]:
cells = list(row)
if touches == 2:
@@ -74,14 +74,14 @@
"returns (list, startcenter) level number"
if not initialized: init()
lev = Levels[level%len(Levels)]
- touches = level/len(Levels) + 1
+ touches = level//len(Levels) + 1
passes = (level>len(Levels) and 2) or 1
boxlist = []
size = 5, 5
corner = 5, 5
startpos = corner[0]+236, corner[1]+182
pos = [corner[0], corner[1]]
- numboxes = level/2
+ numboxes = level//2
img = pygame.Surface((52, 42))
img.fill((20, 20, 30))
pygame.draw.rect(img, (255, 255, 255), (0,0,51,41), 2)
--- a/code/main.py
+++ b/code/main.py
@@ -17,8 +17,8 @@
try:
gamemain(args)
except KeyboardInterrupt:
- print 'Keyboard Interrupt...'
- print 'Exiting'
+ print('Keyboard Interrupt...')
+ print('Exiting')
def gamemain(args):
@@ -42,7 +42,7 @@
input.init()
if not txt.initialize():
- raise pygame.error, "Pygame Font Module Unable to Initialize"
+ raise pygame.error("Pygame Font Module Unable to Initialize")
#create the starting game handler
from gameinit import GameInit
--- a/code/mysysfont.py
+++ b/code/mysysfont.py
@@ -35,7 +35,7 @@
#insert a font and style into the font dictionary
def _addfont(name, bold, italic, font, fontdict):
- if not fontdict.has_key(name):
+ if name not in fontdict:
fontdict[name] = {}
fontdict[name][bold, italic] = font
@@ -175,14 +175,14 @@
found = None
fname = None
for name in set:
- if Sysfonts.has_key(name):
+ if name in Sysfonts:
found = Sysfonts[name]
fname = name
break
if not found:
continue
for name in set:
- if not Sysfonts.has_key(name):
+ if name not in Sysfonts:
Sysalias[name] = found
--- a/code/objbox.py
+++ b/code/objbox.py
@@ -30,7 +30,7 @@
rboximages = gfx.animstrip(imgs)
pal = [min(g+60,255) for (r,g,b) in origpal]
- imgs.set_palette(zip(pal,pal,pal))
+ imgs.set_palette(list(zip(pal,pal,pal)))
wboximages = gfx.animstrip(imgs)
popimages = gfx.animstrip(gfx.load('popbox.png'))
--- a/code/objpopshot.py
+++ b/code/objpopshot.py
@@ -29,7 +29,7 @@
gfx.dirty(r)
def draw(self, gfx):
- img = images[self.clocks/3]
+ img = images[self.clocks//3]
r = gfx.surface.blit(img, self.rect)
gfx.dirty(r)
--- a/code/objpowerup.py
+++ b/code/objpowerup.py
@@ -196,6 +196,6 @@
def newpowerup(levelnum):
- choices = Effects[:2+(levelnum/8)]
+ choices = Effects[:2+(levelnum//8)]
effect = random.choice(choices)
return Powerup(effect)
--- a/code/objsmoke.py
+++ b/code/objsmoke.py
@@ -40,7 +40,7 @@
gfx.dirty(r.inflate(1, 2))
def draw(self, gfx):
- frame = min(self.clocks / 5, 3)
+ frame = min(self.clocks // 5, 3)
img = images[frame]
r = gfx.surface.blit(img, self.rect)
gfx.dirty(r.inflate(1, 2))
--- a/code/objwarp.py
+++ b/code/objwarp.py
@@ -43,7 +43,7 @@
gfx.dirty(r)
def draw(self, gfx):
- frame = min(int(self.clocks/CLOCK_MULTIPLIER), len(self.images)-1)
+ frame = min(int(self.clocks//CLOCK_MULTIPLIER), len(self.images)-1)
img = images[frame]
r = gfx.surface.blit(img, self.rect)
gfx.dirty2(r, self.lastrect)
--- a/code/players.py
+++ b/code/players.py
@@ -12,7 +12,7 @@
def new_guid():
- return str(random.randint(0, sys.maxint-1))
+ return str(random.randint(0, sys.maxsize-1))
def make_winner(player):
player.winner = 1
@@ -94,7 +94,7 @@
p = pickle.Pickler(f, 1)
p.dump(allplayers)
f.close()
- except (IOError, OSError), msg:
+ except (IOError, OSError) as msg:
import messagebox
messagebox.error("Error Saving Player Data",
"There was an error saving the player data.\nCurrent player data has been lost.\n\n%s"%msg)
--- a/code/snd.py
+++ b/code/snd.py
@@ -28,7 +28,7 @@
sound_cache[name] = None
return
for name in names:
- if not sound_cache.has_key(name):
+ if name not in sound_cache:
fullname = os.path.join('data', 'audio', name+'.wav')
#file = game.get_resource(name+'.wav')
try: sound = mixer.Sound(fullname)
@@ -37,7 +37,7 @@
def fetch(name):
- if not sound_cache.has_key(name):
+ if name not in sound_cache:
preload(name)
return sound_cache[name]
--- a/code/stars.py
+++ b/code/stars.py
@@ -17,7 +17,7 @@
speed = -val, val
rect = Rect(randint(0, scrwide), randint(0, scrhigh), 1, 1)
stars.append([rect, speed, color])
- half = self.maxstars / 2
+ half = self.maxstars // 2
self.stars = stars[:half], stars[half:]
self.numstars = 50
self.dead = 0
@@ -31,7 +31,7 @@
change = int((fps - 35.0) * 1.8)
change = min(change, 12) #limit how quickly they can be added
numstars = self.numstars + change
- numstars = max(min(numstars, self.maxstars/2), 0)
+ numstars = max(min(numstars, self.maxstars//2), 0)
if numstars < self.numstars:
DIRTY, BGD = gfx.dirty, self.last_background
for rect, vel, col in self.stars[self.odd][numstars:self.numstars]:
--- a/code/txt.py
+++ b/code/txt.py
@@ -21,7 +21,7 @@
class Font:
def __init__(self, name, size, bold=0, italic=0):
val = name, size
- if FontPool.has_key(val):
+ if val in FontPool:
font = FontPool[val]
else:
font = SysFont(name, size, bold, italic)