py3: Get the updater working with Python 3.
This commit is contained in:
+23
-20
@@ -105,18 +105,17 @@ init -1500 python in updater:
|
|||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
log = file(DEFERRED_UPDATE_LOG, "ab")
|
log = open(DEFERRED_UPDATE_LOG, "a")
|
||||||
except:
|
except:
|
||||||
log = io.BytesIO()
|
log = io.BytesIO()
|
||||||
|
|
||||||
with log:
|
with log:
|
||||||
with open(DEFERRED_UPDATE_FILE, "rb") as f:
|
with open(DEFERRED_UPDATE_FILE, "r") as f:
|
||||||
for l in f:
|
for l in f:
|
||||||
|
|
||||||
l = l.rstrip("\r\n")
|
l = l.rstrip("\r\n")
|
||||||
l = l.decode("utf-8")
|
|
||||||
|
|
||||||
log.write(l.encode("utf-8"))
|
log.write(l)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process_deferred_line(l)
|
process_deferred_line(l)
|
||||||
@@ -324,7 +323,7 @@ init -1500 python in updater:
|
|||||||
|
|
||||||
# The logfile that update errors are written to.
|
# The logfile that update errors are written to.
|
||||||
try:
|
try:
|
||||||
self.log = open(os.path.join(self.updatedir, "log.txt"), "wb")
|
self.log = open(os.path.join(self.updatedir, "log.txt"), "w")
|
||||||
except:
|
except:
|
||||||
self.log = None
|
self.log = None
|
||||||
|
|
||||||
@@ -358,7 +357,7 @@ init -1500 python in updater:
|
|||||||
self.log.flush()
|
self.log.flush()
|
||||||
|
|
||||||
except UpdateError as e:
|
except UpdateError as e:
|
||||||
self.message = e.message
|
self.message = e.args[0]
|
||||||
self.can_cancel = True
|
self.can_cancel = True
|
||||||
self.can_proceed = False
|
self.can_proceed = False
|
||||||
self.state = self.ERROR
|
self.state = self.ERROR
|
||||||
@@ -703,14 +702,14 @@ init -1500 python in updater:
|
|||||||
if not os.path.exists(fn):
|
if not os.path.exists(fn):
|
||||||
raise UpdateError(_("Either this project does not support updating, or the update status file was deleted."))
|
raise UpdateError(_("Either this project does not support updating, or the update status file was deleted."))
|
||||||
|
|
||||||
with open(fn, "rb") as f:
|
with open(fn, "r") as f:
|
||||||
self.current_state = json.load(f)
|
self.current_state = json.load(f)
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
fn = os.path.join(self.updatedir, "test.txt")
|
fn = os.path.join(self.updatedir, "test.txt")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(fn, "wb") as f:
|
with open(fn, "w") as f:
|
||||||
f.write("Hello, World.")
|
f.write("Hello, World.")
|
||||||
|
|
||||||
os.unlink(fn)
|
os.unlink(fn)
|
||||||
@@ -729,20 +728,24 @@ init -1500 python in updater:
|
|||||||
fn = os.path.join(self.updatedir, "updates.json")
|
fn = os.path.join(self.updatedir, "updates.json")
|
||||||
urlretrieve(self.url, fn)
|
urlretrieve(self.url, fn)
|
||||||
|
|
||||||
|
with open(fn, "r") as f:
|
||||||
|
self.updates = json.load(f)
|
||||||
|
|
||||||
with open(fn, "rb") as f:
|
with open(fn, "rb") as f:
|
||||||
updates_json = f.read()
|
updates_json = f.read()
|
||||||
self.updates = json.loads(updates_json)
|
|
||||||
|
|
||||||
if self.public_key is not None:
|
if self.public_key is not None:
|
||||||
fn = os.path.join(self.updatedir, "updates.json.sig")
|
fn = os.path.join(self.updatedir, "updates.json.sig")
|
||||||
urlretrieve(self.url + ".sig", fn)
|
urlretrieve(self.url + ".sig", fn)
|
||||||
|
|
||||||
with open(fn, "rb") as f:
|
with open(fn, "rb") as f:
|
||||||
signature = f.read().decode("base64")
|
import codecs
|
||||||
|
signature = codecs.decode(f.read(), "base64")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rsa.verify(updates_json, signature, self.public_key)
|
rsa.verify(updates_json, signature, self.public_key)
|
||||||
except:
|
except:
|
||||||
|
raise
|
||||||
raise UpdateError(_("Could not verify update signature."))
|
raise UpdateError(_("Could not verify update signature."))
|
||||||
|
|
||||||
if "monkeypatch" in self.updates:
|
if "monkeypatch" in self.updates:
|
||||||
@@ -963,7 +966,7 @@ init -1500 python in updater:
|
|||||||
break
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = file(new_fn + ".part", "rb")
|
f = open(new_fn + ".part", "rb")
|
||||||
except:
|
except:
|
||||||
self.log.write("partfile does not exist\n")
|
self.log.write("partfile does not exist\n")
|
||||||
continue
|
continue
|
||||||
@@ -1183,7 +1186,7 @@ init -1500 python in updater:
|
|||||||
# Extract regular files.
|
# Extract regular files.
|
||||||
tff = tf.extractfile(info)
|
tff = tf.extractfile(info)
|
||||||
new_path = path + ".new"
|
new_path = path + ".new"
|
||||||
with file(new_path, "wb") as f:
|
with open(new_path, "wb") as f:
|
||||||
while True:
|
while True:
|
||||||
data = tff.read(1024 * 1024)
|
data = tff.read(1024 * 1024)
|
||||||
if not data:
|
if not data:
|
||||||
@@ -1214,10 +1217,10 @@ init -1500 python in updater:
|
|||||||
self.unlink(path)
|
self.unlink(path)
|
||||||
|
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
self.log.write("could not rename file %s" % path.encode("utf-8"))
|
self.log.write("could not rename file %s" % path)
|
||||||
|
|
||||||
with open(DEFERRED_UPDATE_FILE, "ab") as f:
|
with open(DEFERRED_UPDATE_FILE, "a") as f:
|
||||||
f.write("R " + path.encode("utf-8") + "\r\n")
|
f.write("R " + path + "\r\n")
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -1261,9 +1264,9 @@ init -1500 python in updater:
|
|||||||
self.unlink(i)
|
self.unlink(i)
|
||||||
|
|
||||||
if os.path.exists(i):
|
if os.path.exists(i):
|
||||||
self.log.write("could not delete file %s" % i.encode("utf-8"))
|
self.log.write("could not delete file %s" % i)
|
||||||
with open(DEFERRED_UPDATE_FILE, "wb") as f:
|
with open(DEFERRED_UPDATE_FILE, "w") as f:
|
||||||
f.write("D " + i.encode("utf-8") + "\r\n")
|
f.write("D " + i + "\r\n")
|
||||||
|
|
||||||
for i in old_directories:
|
for i in old_directories:
|
||||||
try:
|
try:
|
||||||
@@ -1278,7 +1281,7 @@ init -1500 python in updater:
|
|||||||
|
|
||||||
fn = os.path.join(self.updatedir, "current.json")
|
fn = os.path.join(self.updatedir, "current.json")
|
||||||
|
|
||||||
with open(fn, "wb") as f:
|
with open(fn, "w") as f:
|
||||||
json.dump(self.new_state, f)
|
json.dump(self.new_state, f)
|
||||||
|
|
||||||
def clean(self, fn):
|
def clean(self, fn):
|
||||||
@@ -1328,7 +1331,7 @@ init -1500 python in updater:
|
|||||||
if not os.path.exists(fn):
|
if not os.path.exists(fn):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
with open(fn, "rb") as f:
|
with open(fn, "r") as f:
|
||||||
state = json.load(f)
|
state = json.load(f)
|
||||||
|
|
||||||
installed_state_cache = state
|
installed_state_cache = state
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
./distribute.py --fast $1
|
lib/py3-linux-x86_64/python ./distribute.py --nosign --fast $1
|
||||||
rm -Rf /tmp/renpy-$1-sdk
|
rm -Rf /tmp/renpy-$1-sdk
|
||||||
unzip -d /tmp dl/$1/renpy-$1-sdk.zip
|
unzip -d /tmp dl/$1/renpy-$1-sdk.zip
|
||||||
/tmp/renpy-$1-sdk/renpy.sh
|
/tmp/renpy-$1-sdk/renpy.sh
|
||||||
|
|||||||
Reference in New Issue
Block a user