Starting on Version 7.0 using the work done by others. Completely untested. I will be testing things, but I thought I'd get this base version up for others to give pull requests.

THIS IS ON THE MASTER BRANCH. The Master branch will be Python 3.0 from now on. While Python 2.7 support will not be deliberately broken, all efforts should now focus on Python 3.0 compatibility.

I can see a lot of work has been done. There's more to do. I've bumped the version number of everything I came across to the next major number for Python 3.0 compatibility indication.

Thanks everyone. I hope to update here at least once a week until we have a stable 7.0 release for calibre 5.0
This commit is contained in:
Apprentice Harper
2020-09-26 21:22:47 +01:00
parent 4868a7460e
commit afa4ac5716
40 changed files with 757 additions and 729 deletions

View File

@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
from __future__ import print_function
# androidkindlekey.py
# Copyright © 2013-15 by Thom and Apprentice Harper
@@ -17,14 +18,14 @@ from __future__ import with_statement
# 1.3 - added in TkInter interface, output to a file
# 1.4 - Fix some problems identified by Aldo Bleeker
# 1.5 - Fix another problem identified by Aldo Bleeker
# 2.0 - Add Python 3 compatibility
"""
Retrieve Kindle for Android Serial Number.
"""
from __future__ import print_function
__license__ = 'GPL v3'
__version__ = '1.5'
__version__ = '2.0'
import os
import sys
@@ -34,7 +35,10 @@ import tempfile
import zlib
import tarfile
from hashlib import md5
from cStringIO import StringIO
try:
from cStringIO import StringIO
except ImportError:
from io import BytesIO as StringIO
from binascii import a2b_hex, b2a_hex
# Routines common to Mac and PC
@@ -49,7 +53,7 @@ class SafeUnbuffered:
if self.encoding == None:
self.encoding = "utf-8"
def write(self, data):
if isinstance(data,unicode):
if isinstance(data,bytes):
data = data.encode(self.encoding,"replace")
self.stream.write(data)
self.stream.flush()
@@ -90,7 +94,7 @@ def unicode_argv():
# Remove Python executable and commands if present
start = argc.value - len(sys.argv)
return [argv[i] for i in
xrange(start, argc.value)]
range(start, argc.value)]
# if we don't have any arguments at all, just pass back script name
# this should never happen
return [u"kindlekey.py"]
@@ -98,7 +102,7 @@ def unicode_argv():
argvencoding = sys.stdin.encoding
if argvencoding == None:
argvencoding = "utf-8"
return [arg if (type(arg) == unicode) else unicode(arg,argvencoding) for arg in sys.argv]
return argv
class DrmException(Exception):
pass
@@ -248,7 +252,7 @@ def get_serials2(path=STORAGE2):
traceback.print_exc()
pass
tokens = list(set(tokens))
serials = []
for x in dsns:
serials.append(x)
@@ -313,7 +317,7 @@ __all__ = [ 'get_serials', 'getkey']
def getkey(outfile, inpath):
keys = get_serials(inpath)
if len(keys) > 0:
with file(outfile, 'w') as keyfileout:
with open(outfile, 'w') as keyfileout:
for key in keys:
keyfileout.write(key)
keyfileout.write("\n")
@@ -340,7 +344,7 @@ def cli_main():
try:
opts, args = getopt.getopt(argv[1:], "hb:")
except getopt.GetoptError, err:
except getopt.GetoptError as err:
usage(progname)
print(u"\nError in options or arguments: {0}".format(err.args[0]))
return 2
@@ -444,11 +448,11 @@ def gui_main():
if not os.path.exists(outfile):
break
with file(outfile, 'w') as keyfileout:
with open(outfile, 'w') as keyfileout:
keyfileout.write(key)
success = True
tkMessageBox.showinfo(progname, u"Key successfully retrieved to {0}".format(outfile))
except Exception, e:
except Exception as e:
self.status['text'] = u"Error: {0}".format(e.args[0])
return
self.status['text'] = u"Select backup.ab file"