Skip to content

Commit

Permalink
Python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ma1co committed Dec 25, 2016
1 parent bedc97a commit 2a7b6e0
Show file tree
Hide file tree
Showing 29 changed files with 257 additions and 195 deletions.
2 changes: 1 addition & 1 deletion build.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os, shutil, subprocess, sys
excludes = ['encodings.bz2_codec', 'encodings.idna', 'Crypto.Cipher._DES', 'Crypto.Cipher._DES3', 'Crypto.Hash._SHA256', 'numpy']

# Get version from git
version = subprocess.check_output(['git', 'describe', '--always', '--tags']).strip()
version = subprocess.check_output(['git', 'describe', '--always', '--tags']).decode('ascii').strip()
with open('frozenversion.py', 'w') as f:
f.write('version = "%s"' % version)

Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def diffApps(oldApps, newApps):
oldApps = oldApps.copy()
installedApps = []
updatedApps = []
for app, version in newApps.iteritems():
for app, version in newApps.items():
if oldApps.get(app) != version:
if app not in oldApps:
installedApps.append(app)
Expand Down Expand Up @@ -335,7 +335,7 @@ def get(self):

class ApiAppsHandler(BaseHandler):
def get(self):
self.json([dict(app.dict.items() + [('release', app.release.dict if app.release else None)]) for app in AppStore().apps.itervalues()])
self.json([dict(list(app.dict.items()) + [('release', app.release.dict if app.release else None)]) for app in AppStore().apps.values()])


class ApiStatsHandler(BaseHandler):
Expand Down
2 changes: 2 additions & 0 deletions pmca-console.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def main():
args.outFile.write(spk.parse(args.inFile.read()))
elif args.command == 'firmware':
firmwareUpdateCommand(args.datFile, args.driver)
else:
parser.print_usage()


if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion pmca-console.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ input = 'pmca-console.py'
output = 'pmca-console'
console = True

execfile('build.spec')
with open('build.spec') as f:
exec(f.read())
17 changes: 10 additions & 7 deletions pmca-gui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""A simple gui interface"""
from __future__ import print_function
import sys
from tkFileDialog import *
import traceback

import config
Expand All @@ -13,7 +13,7 @@
else:
version = None

class PrintRedirector:
class PrintRedirector(object):
"""Redirect writes to a function"""
def __init__(self, func, parent=None):
self.func = func
Expand All @@ -22,6 +22,8 @@ def write(self, str):
if self.parent:
self.parent.write(str)
self.func(str)
def flush(self):
self.parent.flush()


class AppLoadTask(BackgroundTask):
Expand All @@ -31,7 +33,7 @@ def doBefore(self):

def do(self, arg):
try:
print ''
print('')
return listApps(config.appengineServer)
except Exception:
traceback.print_exc()
Expand All @@ -49,7 +51,7 @@ def doBefore(self):

def do(self, arg):
try:
print ''
print('')
infoCommand(config.appengineServer)
except Exception:
traceback.print_exc()
Expand All @@ -64,9 +66,10 @@ def doBefore(self):
self.ui.installButton.config(state=DISABLED)
return self.ui.getMode(), self.ui.getSelectedApk(), self.ui.getSelectedApp()

def do(self, (mode, apkFilename, app)):
def do(self, args):
(mode, apkFilename, app) = args
try:
print ''
print('')
if mode == self.ui.MODE_APP and app:
installCommand(config.appengineServer, None, None, app.package)
elif mode == self.ui.MODE_APK and apkFilename:
Expand All @@ -90,7 +93,7 @@ def doBefore(self):
def do(self, datFile):
try:
if datFile:
print ''
print('')
with open(datFile, 'rb') as f:
firmwareUpdateCommand(f)
except Exception:
Expand Down
3 changes: 2 additions & 1 deletion pmca-gui.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ input = 'pmca-gui.py'
output = 'pmca-gui'
console = False

execfile('build.spec')
with open('build.spec') as f:
exec(f.read())
2 changes: 1 addition & 1 deletion pmca/appstore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ def asset(self):
return self._loadAsset()

def _loadAsset(self):
return http.get(self.url).data
return http.get(self.url).raw_data
32 changes: 19 additions & 13 deletions pmca/commands/market.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
from __future__ import print_function
from getpass import getpass
import os
import re
import sys

if sys.version_info < (3,):
# Python 2
input = raw_input

from .. import marketclient
from .. import spk

def marketCommand(token=None):
if not token:
print 'Please enter your Sony Entertainment Network credentials\n'
email = raw_input('Email: ')
print('Please enter your Sony Entertainment Network credentials\n')
email = input('Email: ')
password = getpass('Password: ')
token = marketclient.login(email, password)
if token:
print 'Login successful. Your auth token (use with the -t option):\n%s\n' % token
print('Login successful. Your auth token (use with the -t option):\n%s\n' % token)
else:
print 'Login failed'
print('Login failed')
return

devices = marketclient.getDevices(token)
print '%d devices found\n' % len(devices)
print('%d devices found\n' % len(devices))

apps = []
for device in devices:
print '%s (%s)' % (device.name, device.serial)
print('%s (%s)' % (device.name, device.serial))
for app in marketclient.getApps(device.name):
if not app.price:
apps.append((device.deviceid, app.id))
print ' [%2d] %s' % (len(apps), app.name)
print ''
print(' [%2d] %s' % (len(apps), app.name))
print('')

if apps:
while True:
i = int(raw_input('Enter number of app to download (0 to exit): '))
i = int(input('Enter number of app to download (0 to exit): '))
if i == 0:
break
app = apps[i - 1]
print 'Downloading app %s' % app[1]
print('Downloading app %s' % app[1])
spkName, spkData = marketclient.download(token, app[0], app[1])
fn = re.sub('(%s)?$' % re.escape(spk.constants.extension), '.apk', spkName)
data = spk.parse(spkData)

if os.path.exists(fn):
print 'File %s exists already' % fn
print('File %s exists already' % fn)
else:
with open(fn, 'wb') as f:
f.write(data)
print 'App written to %s' % fn
print ''
print('App written to %s' % fn)
print('')
Loading

0 comments on commit 2a7b6e0

Please sign in to comment.