diff --git a/gui.py b/gui.py index d14324e..8246aeb 100755 --- a/gui.py +++ b/gui.py @@ -7,12 +7,12 @@ """Graphical user-interface for mymc.""" -_SCCS_ID = "@(#) mymc gui.py 1.8 22/02/05 19:20:59\n" +_SCCS_ID = "@(#) mymc gui.py 1.9 23/07/06 19:35:21\n" import os import sys import struct -import cStringIO +from io import BytesIO import time from functools import partial @@ -101,7 +101,7 @@ def single_title(title): def _get_icon_resource_as_images(name): ico = guires.resources[name] images = [] - f = cStringIO.StringIO(ico) + f = BytesIO(ico) count = struct.unpack(" 0: if os.path.isabs(dir): self.config.set_savefile_dir(dir) @@ -819,7 +819,7 @@ def evt_cmd_export(self, event): def _do_import(self, fn): sf = ps2save.ps2_save_file() - f = file(fn, "rb") + f = open(fn, "rb") try: ft = ps2save.detect_file_type(f) f.seek(0) @@ -868,8 +868,8 @@ def evt_cmd_import(self, event): try: self._do_import(fn) success = fn - except EnvironmentError, value: - self.mc_error(value, fn) + except EnvironmentError as e: + self.mc_error(e, fn) if success != None: dir = os.path.dirname(success) @@ -904,8 +904,8 @@ def evt_cmd_delete(self, event): for dn in dirnames: try: mc.rmdir("/" + dn) - except EnvironmentError, value: - self.mc_error(value, dn) + except EnvironmentError as e: + self.mc_error(e, dn) mc.check() self.refresh() @@ -934,13 +934,13 @@ def run(filename = None): run("test.ps2") - gc.collect() - for o in gc.garbage: - print - print o - if type(o) == ps2mc.ps2mc_file: + gc.collect() + for o in gc.garbage: + print() + print(o) + if type(o) == ps2mc.ps2mc_file: for m in dir(o): - print m, getattr(o, m) + print(m, getattr(o, m)) # while True: @@ -954,7 +954,7 @@ def run(filename = None): # or m == "__dict__" # or m == "__weakref__"): # continue -# print m +# print(m) # setattr(o, m, None) # o = None # break diff --git a/guires.py b/guires.py index 3ae4438..b40e334 100755 --- a/guires.py +++ b/guires.py @@ -1,185 +1,187 @@ +import base64 + resources = { - "mc4.ico": ( - "AAABAAIAICAQAAAAAADoAgAAJgAAADAwAAEAAAAAqA4AAA4D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AAAAIAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAgAAAAICAAIAAAACAAIAAgIAAAMDAwADA\n" - "3MAA8MqmAAAgQAAAIGAAACCAAAAgoAAAIMAAACDgAABAAAAAQCAAAEBAAABAYAAAQIAAAECgAABA\n" - "wAAAQOAAAGAAAABgIAAAYEAAAGBgAABggAAAYKAAAGDAAABg4AAAgAAAAIAgAACAQAAAgGAAAICA\n" - "AACAoAAAgMAAAIDgAACgAAAAoCAAAKBAAACgYAAAoIAAAKCgAACgwAAAoOAAAMAAAADAIAAAwEAA\n" - "AMBgAADAgAAAwKAAAMDAAADA4AAA4AAAAOAgAADgQAAA4GAAAOCAAADgoAAA4MAAAODgAEAAAABA\n" - "ACAAQABAAEAAYABAAIAAQACgAEAAwABAAOAAQCAAAEAgIABAIEAAQCBgAEAggABAIKAAQCDAAEAg\n" - "4ABAQAAAQEAgAEBAQABAQGAAQECAAEBAoABAQMAAQEDgAEBgAABAYCAAQGBAAEBgYABAYIAAQGCg\n" - "AEBgwABAYOAAQIAAAECAIABAgEAAQIBgAECAgABAgKAAQIDAAECA4ABAoAAAQKAgAECgQABAoGAA\n" - "QKCAAECgoABAoMAAQKDgAEDAAABAwCAAQMBAAEDAYABAwIAAQMCgAEDAwABAwOAAQOAAAEDgIABA\n" - "4EAAQOBgAEDggABA4KAAQODAAEDg4ACAAAAAgAAgAIAAQACAAGAAgACAAIAAoACAAMAAgADgAIAg\n" - "AACAICAAgCBAAIAgYACAIIAAgCCgAIAgwACAIOAAgEAAAIBAIACAQEAAgEBgAIBAgACAQKAAgEDA\n" - "AIBA4ACAYAAAgGAgAIBgQACAYGAAgGCAAIBgoACAYMAAgGDgAICAAACAgCAAgIBAAICAYACAgIAA\n" - "gICgAICAwACAgOAAgKAAAICgIACAoEAAgKBgAICggACAoKAAgKDAAICg4ACAwAAAgMAgAIDAQACA\n" - "wGAAgMCAAIDAoACAwMAAgMDgAIDgAACA4CAAgOBAAIDgYACA4IAAgOCg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AAD39/f+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v739/cAAAAAAAAAAAD3+/v79/f3\n" - "9/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/cAAAAAAAAAAAD30NDQ9/f39/f39/f39/f3\n" - "9/f39/f39/f39/f39/f396SkpKSk9/cAAAAAAAAAAAD3+ff59/f39/f39/f39/f39/f39/f39/f3\n" - "9/f39/f39/f39/f39/cAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///////wAA////\n" - "////AAD//h////8AAP/8D////wAA//gP////AAD/8Af///8AAP/gAAAP/wAA/8AAAD//AAD/gAAB\n" - "//8AAP8AAAH//wAA/gAAAAADAAD8AAAAAAMAAPgAAAAAAwAA8AAAAAADAADgAAAAAAMAAMAAAAAA\n" - "AwAAgAAAAAADAACAAAAAAAMAAIAAAAAAAwAAgAAAAAADAADAAAAAAAMAAPAAAAAAAwAA+AAAAAAD\n" - "AAD8AAAAAAMAAP4AAAAAAwAA/gAAAAADAAD+AAAAAAMAAP4AAAAAAwAA/gAAAAADAAD+AAAAAAMA\n" - "AP4AAAAAAwAA/gAAAAADAAD+AAAAAAMAAP4AAAAAAwAA/gAAAAADAAD+AAAAAAMAAP4AAAAAAwAA\n" - "/gAAAAADAAD+AAAAAAMAAP4AAAAAAwAA/gAAAAADAAD+AAAAAAMAAP4AAAAAAwAA/gAAAAADAAD+\n" - "AAAAAAMAAP///////wAA////////AAD///////8AAA==\n" - ).decode("base64_codec"), - "mc5b.ico": ( - "AAABAAEAICAQAAAAAADoAgAAFgAAACgAAAAgAAAAQAAAAAEABAAAAAAAgAIAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAgICAAMDAwAAAAP8AAP8AAAD//wD/AAAA\n" - "/wD/AP//AAD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABwAAAAAAAAAAAAAAAABwAAAAAAAAAAAAAAAAAA\n" - "AHAAYAAAAAAAAAAAAAAAAAcABmYAAAAAAAAAAAAAAKBwAGZmYABwAAAAAAAAAACqAAZmZmYABwAA\n" - "AAAAAAAAqqBmZmZgAABwAAAAAAAAB6qqZmZmAAAABwAACqqqqqqiqqZmYAAAAABwAAqqqqqqoiqq\n" - "ZgBwcAAABwAKoiIiIiIiqqAHBwAAAABwCqIiIiIiIiqqcHBwAAAABwqiIiIiIiIqqgcHBwAAAAAK\n" - "oiIiIiIiqqBwcHAABAAACqqqqqqiKqoHB3cAAEAAAAqqqqqqoqqgAAB3AAwAAAcAAAAAAKqqAAAA\n" - "AABAAABwAAAAAACqpwAAAAAMAHAHAAAAAAAAqgBwAAAAAAdwcAAAAAAAAKAABwAAxAAABwAAAAAA\n" - "AAAAAABwAEzAAHAAAAAAAAAAAAAABwAAwAcAAAAAAAAAAAAAAABwAABwAAAAAAAAAAAAAAAABwAH\n" - "AAAAAAAAAAAAAAAAAABwcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAAD///////////////////////8H///+B////AP///gB///QAH//wAA//8AAH/+A\n" - "AA+AAAAHgAAAA4AAAAGAAAAAgAAAAIAAAACAAAAAgAAAAP/AAAH/wAAD/8wAB//eAA///wAf//+A\n" - "P///wH///+D////x/////////////////w==\n" - ).decode("base64_codec"), - "mc2.ico": ( - "AAABAAEAMDAAAQAAAACoDgAAFgAAACgAAAAwAAAAYAAAAAEACAAAAAAAgAoAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAwMDAAMDcwADwyqYAACBAAAAgYAAAIIAA\n" - "ACCgAAAgwAAAIOAAAEAAAABAIAAAQEAAAEBgAABAgAAAQKAAAEDAAABA4AAAYAAAAGAgAABgQAAA\n" - "YGAAAGCAAABgoAAAYMAAAGDgAACAAAAAgCAAAIBAAACAYAAAgIAAAICgAACAwAAAgOAAAKAAAACg\n" - "IAAAoEAAAKBgAACggAAAoKAAAKDAAACg4AAAwAAAAMAgAADAQAAAwGAAAMCAAADAoAAAwMAAAMDg\n" - "AADgAAAA4CAAAOBAAADgYAAA4IAAAOCgAADgwAAA4OAAQAAAAEAAIABAAEAAQABgAEAAgABAAKAA\n" - "QADAAEAA4ABAIAAAQCAgAEAgQABAIGAAQCCAAEAgoABAIMAAQCDgAEBAAABAQCAAQEBAAEBAYABA\n" - "QIAAQECgAEBAwABAQOAAQGAAAEBgIABAYEAAQGBgAEBggABAYKAAQGDAAEBg4ABAgAAAQIAgAECA\n" - "QABAgGAAQICAAECAoABAgMAAQIDgAECgAABAoCAAQKBAAECgYABAoIAAQKCgAECgwABAoOAAQMAA\n" - "AEDAIABAwEAAQMBgAEDAgABAwKAAQMDAAEDA4ABA4AAAQOAgAEDgQABA4GAAQOCAAEDgoABA4MAA\n" - "QODgAIAAAACAACAAgABAAIAAYACAAIAAgACgAIAAwACAAOAAgCAAAIAgIACAIEAAgCBgAIAggACA\n" - "IKAAgCDAAIAg4ACAQAAAgEAgAIBAQACAQGAAgECAAIBAoACAQMAAgEDgAIBgAACAYCAAgGBAAIBg\n" - "YACAYIAAgGCgAIBgwACAYOAAgIAAAICAIACAgEAAgIBgAICAgACAgKAAgIDAAICA4ACAoAAAgKAg\n" - "AICgQACAoGAAgKCAAICgoACAoMAAgKDgAIDAAACAwCAAgMBAAIDAYACAwIAAgMCgAIDAwACAwOAA\n" - "gOAAAIDgIACA4EAAgOBgAIDggACA4KAAgODAAIDg4ADA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AAAAKSkpKSkpKSk9/f39/f39/cA\n" - "9/f39/ekpKSkpPf396SkpKSkpKSkAAAAAAAAAAAAAKSkpKSkpKSk9/f39/f39/f39/f39/ekpKSk\n" - "pPf396SkpKSkpKSkAAAAAAAAAAAAAKSkpKSkpKSk9/f39/f39/f39/f39/ekpKSkpPf396SkpKSk\n" - "pKQAAAAAAAAAAAAAAKSkpKSkpKSk9/f39/f39/f39/f39/ekpKSkpPf396SkpKSkpAAA9gAAAAAA\n" - "AAAAAACkpKSkpKSk9/f39/f39/f39/f39/f39/f39/f396SkpKSkAAAAAAAAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////////AAD///////8AAP///////wAA////////\n" - "AAD//w////8AAP8AAAAADwAA/gAAAAAHAAD+AAAAAAcAAP4AAAAABwAA/gAAAAAHAAD+AAAAAAcA\n" - "AP4AAAAABwAA/gAAAAAHAAD+AAAAAAcAAPwAAAAABwAA+AAAAAAHAADwAAAAAAcAAOAAAAAABwAA\n" - "wAAAAAAHAADAAAAAAAcAAMAAAAAABwAAwAAAAAAHAADgAAAAAAcAAPgAAAAABwAA/AAAAAAHAAD+\n" - "AAAAAAcAAP4AAAAABwAA/gAAAAAHAAD+AAAAAAcAAP4AAAAABwAA/gAAAAAHAAD+AAAAAAcAAP4A\n" - "AAAABwAA/gAAAAAHAAD+AAAAAAcAAP4AAAAABwAA/gAAAAAHAAD+AAAAAAcAAP4AAAAABwAA/gAA\n" - "AAAHAAD+AAAAAAcAAP4AAAAABwAA/gAAAAAHAAD+AAAAAA8AAP4AAAAAGwAA/wAAAAA/AAD/////\n" - "//sAAP///////wAA\n" - ).decode("base64_codec"), - "mc6a.ico": ( - "AAABAAEAICAQAAAAAADoAgAAFgAAACgAAAAgAAAAQAAAAAEABAAAAAAAgAIAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAgICAAMDAwAAAAP8AAP8AAAD//wD/AAAA\n" - "/wD/AP//AAD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAHAAAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAAAAAAcABg\n" - "AAAAAAAAAAAAAAAABwAGZgAAAAAAAAAAAAAAAHAAZmZgAHAAAACgAAAAAAcABmZmZgAHAAAAqgAA\n" - "AABwAGZmZmAAAHAAAKqgAAAHAAZmZmYAAAAHAACqqgAAcABmZmZgAAqqqqqqoqqgAAAGZmZmAHB6\n" - "qqqqqqIqqgAAZmZmYAcHCqIiIiIiIqqgAAZmZgBwcHqiIiIiIiIqqnAAZmAHBwcKoiIiIiIiKqoA\n" - "AAYAAHBweqIiIiIiIqqgAAAAAAcHdwqqqqqqoiqqAAAAAAAAAHcKqqqqqqKqoAAAAHAAAAAAAEAA\n" - "AHCqqgAAAAAHAAAAAAwAcAcAqqAAAAAAAHAAAAAAB3BwAKoAAAAAAAAHAADEAAAHAACgAAAAAAAA\n" - "AHAATMAAcAAAAAAAAAAAAAAHAADABwAAAAAAAAAAAAAAAHAAAHAAAAAAAAAAAAAAAAAHAAcAAAAA\n" - "AAAAAAAAAAAAAHBwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" - "AAAAAAAAAAAAAAD//////////////////////wf///4H///8A///+AH///AAf3/gAD8/wAAfH4AA\n" - "Dw8AAAAHAAAAAwAAAAEAAAAAAAAAAMAAAAHgAAAD8AAAB/AAAQ/4AAMf/AAHP/4AD3//AB///4A/\n" - "///Af///4P////H//////////////////w==\n" - ).decode("base64_codec"), + "mc4.ico": base64.b64decode( + "AAABAAIAICAQAAAAAADoAgAAJgAAADAwAA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AAAABAAgA" \ + "AAAAAIAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAgAAAAICAAIAAAACAAIAAgIAAAMDAwADA" \ + "3MAA8MqmAAAgQAAAIGAAACCAAAAgoAAAIMAAACDgAABAAAAAQCAAAEBAAABAYAAAQIAAAECgAABA" \ + "wAAAQOAAAGAAAABgIAAAYEAAAGBgAABggAAAYKAAAGDAAABg4AAAgAAAAIAgAACAQAAAgGAAAICA" \ + "AACAoAAAgMAAAIDgAACgAAAAoCAAAKBAAACgYAAAoIAAAKCgAACgwAAAoOAAAMAAAADAIAAAwEAA" \ + "AMBgAADAgAAAwKAAAMDAAADA4AAA4AAAAOAgAADgQAAA4GAAAOCAAADgoAAA4MAAAODgAEAAAABA" \ + "ACAAQABAAEAAYABAAIAAQACgAEAAwABAAOAAQCAAAEAgIABAIEAAQCBgAEAggABAIKAAQCDAAEAg" \ + "4ABAQAAAQEAgAEBAQABAQGAAQECAAEBAoABAQMAAQEDgAEBgAABAYCAAQGBAAEBgYABAYIAAQGCg" \ + "AEBgwABAYOAAQIAAAECAIABAgEAAQIBgAECAgABAgKAAQIDAAECA4ABAoAAAQKAgAECgQABAoGAA" \ + "QKCAAECgoABAoMAAQKDgAEDAAABAwCAAQMBAAEDAYABAwIAAQMCgAEDAwABAwOAAQOAAAEDgIABA" \ + "4EAAQOBgAEDggABA4KAAQODAAEDg4ACAAAAAgAAgAIAAQACAAGAAgACAAIAAoACAAMAAgADgAIAg" \ + "AACAICAAgCBAAIAgYACAIIAAgCCgAIAgwACAIOAAgEAAAIBAIACAQEAAgEBgAIBAgACAQKAAgEDA" \ + "AIBA4ACAYAAAgGAgAIBgQACAYGAAgGCAAIBgoACAYMAAgGDgAICAAACAgCAAgIBAAICAYACAgIAA" \ + "gICgAICAwACAgOAAgKAAAICgIACAoEAAgKBgAICggACAoKAAgKDAAICg4ACAwAAAgMAgAIDAQACA" \ + "wGAAgMCAAIDAoACAwMAAgMDgAIDgAACA4CAAgOBAA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AAAAAAAAA" \ + "AAD39/f+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v739/cAAAAAAAAAAAD3+/v79/f3" \ + "9/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/cAAAAAAAAAAAD30NDQ9/f39/f39/f39/f3" \ + "9/f39/f39/f39/f39/f396SkpKSk9/cAAAAAAAAAAAD3+ff59/f39/f39/f39/f39/f39/f39/f3" \ + "9/f39/f39/f39/f39/cAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///////wAA////" \ + "////AAD//h////8AAP/8D////wAA//gP////AAD/8Af///8AAP/gAAAP/wAA/8AAAD//AAD/gAAB" \ + "//8AAP8AAAH//wAA/gAAAAADAAD8AAAAAAMAAPgAAAAAAwAA8AAAAAADAADgAAAAAAMAAMAAAAAA" \ + "AwAAgAAAAAADAACAAAAAAAMAAIAAAAAAAwAAgAAAAAADAADAAAAAAAMAAPAAAAAAAwAA+AAAAAAD" \ + "AAD8AAAAAAMAAP4AAAAAAwAA/gAAAAADAAD+AAAAAAMAAP4AAAAAAwAA/gAAAAADAAD+AAAAAAMA" \ + "AP4AAAAAAwAA/gAAAAADAAD+AAAAAAMAAP4AAAAAAwAA/gAAAAADAAD+AAAAAAMAAP4AAAAAAwAA" \ + "/gAAAAADAAD+AAAAAAMAAP4AAAAAAwAA/gAAAAADAAD+AAAAAAMAAP4AAAAAAwAA/gAAAAADAAD+" \ + "AAAAAAMAAP///////wAA////////AAD///////8AAA==" + ), + "mc5b.ico": base64.b64decode( + "AAABAAEAICAQAAAAAADoAgAAFgAAACgAAAAgAAAAQAAAAAEABAAAAAAAgAIAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAgICAAMDAwAAAAP8AAP8AAAD//wD/AAAA" \ + "/wD/AP//AAD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABwAAAAAAAAAAAAAAAABwAAAAAAAAAAAAAAAAAA" \ + "AHAAYAAAAAAAAAAAAAAAAAcABmYAAAAAAAAAAAAAAKBwAGZmYABwAAAAAAAAAACqAAZmZmYABwAA" \ + "AAAAAAAAqqBmZmZgAABwAAAAAAAAB6qqZmZmAAAABwAACqqqqqqiqqZmYAAAAABwAAqqqqqqoiqq" \ + "ZgBwcAAABwAKoiIiIiIiqqAHBwAAAABwCqIiIiIiIiqqcHBwAAAABwqiIiIiIiIqqgcHBwAAAAAK" \ + "oiIiIiIiqqBwcHAABAAACqqqqqqiKqoHB3cAAEAAAAqqqqqqoqqgAAB3AAwAAAcAAAAAAKqqAAAA" \ + "AABAAABwAAAAAACqpwAAAAAMAHAHAAAAAAAAqgBwAAAAAAdwcAAAAAAAAKAABwAAxAAABwAAAAAA" \ + "AAAAAABwAEzAAHAAAAAAAAAAAAAABwAAwAcAAAAAAAAAAAAAAABwAABwAAAAAAAAAAAAAAAABwAH" \ + "AAAAAAAAAAAAAAAAAABwcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAAD///////////////////////8H///+B////AP///gB///QAH//wAA//8AAH/+A" \ + "AA+AAAAHgAAAA4AAAAGAAAAAgAAAAIAAAACAAAAAgAAAAP/AAAH/wAAD/8wAB//eAA///wAf//+A" \ + "P///wH///+D////x/////////////////w==" + ), + "mc2.ico": base64.b64decode( + "AAABAAEAMDAAAQAAAACoDgAAFgAAACgAAAAwAAAAYAAAAAEACAAAAAAAgAoAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAwMDAAMDcwADwyqYAACBAAAAgYAAAIIAA" \ + "ACCgAAAgwAAAIOAAAEAAAABAIAAAQEAAAEBgAABAgAAAQKAAAEDAAABA4AAAYAAAAGAgAABgQAAA" \ + "YGAAAGCAAABgoAAAYMAAAGDgAACAAAAAgCAAAIBAAACAYAAAgIAAAICgAACAwAAAgOAAAKAAAACg" \ + "IAAAoEAAAKBgAACggAAAoKAAAKDAAACg4AAAwAAAAMAgAADAQAAAwGAAAMCAAADAoAAAwMAAAMDg" \ + "AADgAAAA4CAAAOBAAADgYAAA4IAAAOCgAADgwAAA4OAAQAAAAEAAIABAAEAAQABgAEAAgABAAKAA" \ + "QADAAEAA4ABAIAAAQCAgAEAgQABAIGAAQCCAAEAgoABAIMAAQCDgAEBAAABAQCAAQEBAAEBAYABA" \ + "QIAAQECgAEBAwABAQOAAQGAAAEBgIABAYEAAQGBgAEBggABAYKAAQGDAAEBg4ABAgAAAQIAgAECA" \ + "QABAgGAAQICAAECAoABAgMAAQIDgAECgAABAoCAAQKBAAECgYABAoIAAQKCgAECgwABAoOAAQMAA" \ + "AEDAIABAwEAAQMBgAEDAgABAwKAAQMDAAEDA4ABA4AAAQOAgAEDgQABA4GAAQOCAAEDgoABA4MAA" \ + "QODgAIAAAACAACAAgABAAIAAYACAAIAAgACgAIAAwACAAOAAgCAAAIAgIACAIEAAgCBgAIAggACA" \ + "IKAAgCDAAIAg4ACAQAAAgEAgAIBAQACAQGAAgECAAIBAoACAQMAAgEDgAIBgAACAYCAAgGBAAIBg" \ + "YACAYIAAgGCgAIBgwACAYOAAgIAAAICAIACAgEAAgIBgAICAgACAgKAAgIDAAICA4ACAoAAAgKAg" \ + "AICgQACAoGAAgKCAAICgoACAoMAAgKDgAIDAAACAwCAAgMBAAIDAYACAwIAAgMCgAIDAwACAwOAA" \ + "gOAAAIDgIACA4EAAgOBgAIDggACA4KAAgODAAIDg4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AAAAAAKSkpKSkpKSk9/f39/f39/cA" \ + "9/f39/ekpKSkpPf396SkpKSkpKSkAAAAAAAAAAAAAKSkpKSkpKSk9/f39/f39/f39/f39/ekpKSk" \ + "pPf396SkpKSkpKSkAAAAAAAAAAAAAKSkpKSkpKSk9/f39/f39/f39/f39/ekpKSkpPf396SkpKSk" \ + "pKQAAAAAAAAAAAAAAKSkpKSkpKSk9/f39/f39/f39/f39/ekpKSkpPf396SkpKSkpAAA9gAAAAAA" \ + "AAAAAACkpKSkpKSk9/f39/f39/f39/f39/f39/f39/f396SkpKSkAAAAAAAAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////////AAD///////8AAP///////wAA////////" \ + "AAD//w////8AAP8AAAAADwAA/gAAAAAHAAD+AAAAAAcAAP4AAAAABwAA/gAAAAAHAAD+AAAAAAcA" \ + "AP4AAAAABwAA/gAAAAAHAAD+AAAAAAcAAPwAAAAABwAA+AAAAAAHAADwAAAAAAcAAOAAAAAABwAA" \ + "wAAAAAAHAADAAAAAAAcAAMAAAAAABwAAwAAAAAAHAADgAAAAAAcAAPgAAAAABwAA/AAAAAAHAAD+" \ + "AAAAAAcAAP4AAAAABwAA/gAAAAAHAAD+AAAAAAcAAP4AAAAABwAA/gAAAAAHAAD+AAAAAAcAAP4A" \ + "AAAABwAA/gAAAAAHAAD+AAAAAAcAAP4AAAAABwAA/gAAAAAHAAD+AAAAAAcAAP4AAAAABwAA/gAA" \ + "AAAHAAD+AAAAAAcAAP4AAAAABwAA/gAAAAAHAAD+AAAAAA8AAP4AAAAAGwAA/wAAAAA/AAD/////" \ + "//sAAP///////wAA" + ), + "mc6a.ico": base64.b64decode( + "AAABAAEAICAQAAAAAADoAgAAFgAAACgAAAAgAAAAQAAAAAEABAAAAAAAgAIAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAgICAAMDAwAAAAP8AAP8AAAD//wD/AAAA" \ + "/wD/AP//AAD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAHAAAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAAAAAAcABg" \ + "AAAAAAAAAAAAAAAABwAGZgAAAAAAAAAAAAAAAHAAZmZgAHAAAACgAAAAAAcABmZmZgAHAAAAqgAA" \ + "AABwAGZmZmAAAHAAAKqgAAAHAAZmZmYAAAAHAACqqgAAcABmZmZgAAqqqqqqoqqgAAAGZmZmAHB6" \ + "qqqqqqIqqgAAZmZmYAcHCqIiIiIiIqqgAAZmZgBwcHqiIiIiIiIqqnAAZmAHBwcKoiIiIiIiKqoA" \ + "AAYAAHBweqIiIiIiIqqgAAAAAAcHdwqqqqqqoiqqAAAAAAAAAHcKqqqqqqKqoAAAAHAAAAAAAEAA" \ + "AHCqqgAAAAAHAAAAAAwAcAcAqqAAAAAAAHAAAAAAB3BwAKoAAAAAAAAHAADEAAAHAACgAAAAAAAA" \ + "AHAATMAAcAAAAAAAAAAAAAAHAADABwAAAAAAAAAAAAAAAHAAAHAAAAAAAAAAAAAAAAAHAAcAAAAA" \ + "AAAAAAAAAAAAAHBwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \ + "AAAAAAAAAAAAAAD//////////////////////wf///4H///8A///+AH///AAf3/gAD8/wAAfH4AA" \ + "Dw8AAAAHAAAAAwAAAAEAAAAAAAAAAMAAAAHgAAAD8AAAB/AAAQ/4AAMf/AAHP/4AD3//AB///4A/" \ + "///Af///4P////H//////////////////w==" + ), } diff --git a/lzari.py b/lzari.py index de71086..a8bc60b 100755 --- a/lzari.py +++ b/lzari.py @@ -11,7 +11,7 @@ LZARI.C's binary search tree. """ -_SCCS_ID = "@(#) mymc lzari.py 1.6 12/10/04 19:07:53\n" +_SCCS_ID = "@(#) mymc lzari.py 1.7 23/07/06 16:03:53\n" import sys import array @@ -56,18 +56,18 @@ MAX_SUFFIX_CHAIN = 50 # limit on how many identical suffixes to try to match #def debug(value, msg): -# print "@@@ %s %04x" % (msg, value) +# print("@@@ %s %04x" % (msg, value)) debug = lambda value, msg: None -_tr_16 = string.maketrans("0123456789abcdef", - "\x00\x01\x02\x03" - "\x10\x11\x12\x13" - "\x20\x21\x22\x23" - "\x30\x31\x32\x33") -_tr_4 = string.maketrans("0123", - "\x00\x01" - "\x10\x11") -_tr_2 = string.maketrans("01", "\x00\x01") +_tr_16 = bytes.maketrans(b"0123456789abcdef", + b"\x00\x01\x02\x03" + b"\x10\x11\x12\x13" + b"\x20\x21\x22\x23" + b"\x30\x31\x32\x33") +_tr_4 = bytes.maketrans(b"0123", + b"\x00\x01" + b"\x10\x11") +_tr_2 = bytes.maketrans(b"01", b"\x00\x01") def string_to_bit_array(s): """Convert a string to an array containing a sequence of bits.""" @@ -77,15 +77,15 @@ def string_to_bit_array(s): a = array.array('B', s) return a -_tr_rev_2 = string.maketrans("\x00\x01", "01") -_tr_rev_4 = string.maketrans("\x00\x01" - "\x10\x11", - "0123") -_tr_rev_16 = string.maketrans("\x00\x01\x02\x03" - "\x10\x11\x12\x13" - "\x20\x21\x22\x23" - "\x30\x31\x32\x33", - "0123456789abcdef") +_tr_rev_2 = bytes.maketrans(b"\x00\x01", b"01") +_tr_rev_4 = bytes.maketrans(b"\x00\x01" + b"\x10\x11", + b"0123") +_tr_rev_16 = bytes.maketrans(b"\x00\x01\x02\x03" + b"\x10\x11\x12\x13" + b"\x20\x21\x22\x23" + b"\x30\x31\x32\x33", + b"0123456789abcdef") def bit_array_to_string(a): """Convert an array containing a sequence of bits to a string.""" remainder = len(a) % 8 @@ -151,7 +151,7 @@ def init(self, decode): def search(self, table, x): c = 1 - s = len(table) - 1 + s = len(table) - 1 while True: a = (s + c) / 2 if table[a] <= x: @@ -179,11 +179,11 @@ def update_model_decode(self, symbol): freq = sym_freq[symbol] new_symbol = symbol while self.sym_freq[new_symbol - 1] == freq: - new_symbol -= 1 + new_symbol -= 1 # new_symbol = sym_freq.index(freq) if new_symbol != symbol: symbol_to_char = self.symbol_to_char - swap_char = symbol_to_char[new_symbol] + swap_char = symbol_to_char[new_symbol] char = symbol_to_char[symbol] symbol_to_char[new_symbol] = char symbol_to_char[symbol] = swap_char @@ -195,7 +195,7 @@ def update_model_encode(self, symbol): sym_freq = self.sym_freq sym_cum = self.sym_cum - if sym_cum[0] >= MAX_CUM: + if sym_cum[0] >= MAX_CUM: c = 0 for i in range(MAX_CHAR, 0, -1): sym_cum[i] = c @@ -206,10 +206,10 @@ def update_model_encode(self, symbol): freq = sym_freq[symbol] new_symbol = symbol while sym_freq[new_symbol - 1] == freq: - new_symbol -= 1 + new_symbol -= 1 if new_symbol != symbol: debug(new_symbol, "a") - swap_char = self.symbol_to_char[new_symbol] + swap_char = self.symbol_to_char[new_symbol] char = self.symbol_to_char[symbol] self.symbol_to_char[new_symbol] = char self.symbol_to_char[symbol] = swap_char @@ -272,7 +272,7 @@ def decode_position(self): or self.high > QUADRANT3): if self.high > QUADRANT2: return pos - else: + else: self.low -= QUADRANT1 self.code -= QUADRANT1 self.high -= QUADRANT1 @@ -437,11 +437,11 @@ def _add_suffix(self, pos, find): r = self.add_suffix_2(pos, find) start_pos = self.start_pos if find and r[0] != None: - print ("%4d %02x %4d %2d" + print("%4d %02x %4d %2d" % (pos - start_pos, ord(self.src[pos]), r[0] - start_pos, r[1])) else: - print ("%4d %02x" + print("%4d %02x" % (pos - start_pos, ord(self.src[pos]))) return r @@ -570,7 +570,7 @@ def encode(self, src, progress = None): #for k, v in sorted(self.suffix_table.items()): # count, head, table2, chars = v - # print hexlify(k), count, head, len(table2), chars + # print(hexlify(k), count, head, len(table2), chars) if progress: sys.stderr.write("%s100%%\n" % progress) @@ -584,7 +584,7 @@ def decode(self, src, out_length, progress = None): a.fromlist([0] * 32) # add some extra bits self.in_iter = iter(a).next - out = array.array('B', "\0") * out_length + out = array.array('B', b"\0") * out_length outpos = 0 self.init(True) @@ -646,15 +646,15 @@ def decode(src, out_length, progress = None): out = ctypes.create_string_buffer(out_length) if (mylzari_decode(src, len(src), out, out_length, progress) == -1): - raise ValueError, "compressed input is corrupt" + raise ValueError("compressed input is corrupt") return ctypes.string_at(out, out_length) def encode(src, progress = None): (r, compressed, comp_len) = mylzari_encode(src, len(src), progress) - # print r, compressed.value, comp_len + # print(r, compressed.value, comp_len) if r == -1: - raise MemoryError, "out of memory during compression" + raise MemoryError("out of memory during compression") if compressed.value == None: return "" ret = ctypes.string_at(compressed.value, comp_len.value) @@ -665,9 +665,9 @@ def main2(args): import struct import os - src = file(args[2], "rb").read() + src = open(args[2], "rb").read() lzari = lzari_codec() - out = file(args[3], "wb") + out = open(args[3], "wb") start = os.times() if args[1] == "c": dest = lzari.encode(src) @@ -679,7 +679,7 @@ def main2(args): now = os.times() out.write(dest) out.close() - print "time:", now[0] - start[0], now[1] - start[1], now[4] - start[4] + print("time:", now[0] - start[0], now[1] - start[1], now[4] - start[4]) def _get_hotshot_lineinfo(filename): @@ -703,10 +703,10 @@ def _dump_hotshot_lineinfo(log): total_time = sum((time[1] for (loc, time) in a)) for (loc, [count, time]) in a: - print ("%8d %6.3f%% %8d %6.3f%%" + print("%8d %6.3f%% %8d %6.3f%%" % (time, time * 100.0 / total_time, count, count * 100.0 / total_count)), - print "%s:%d(%s)" % loc + print("%s:%d(%s)" % loc) def _dump_hotshot_lineinfo2(log): cur = None @@ -719,25 +719,25 @@ def _dump_hotshot_lineinfo2(log): if cur != filename: if cur != None and f != None: for line in f: - print line[:-1] + print(line[:-1]) f.close() try: - f = file(filename, "r") + f = open(filename, "r") except OSError: f = None cur = filename l = 0 - print "#", filename + print("#", filename) if f != None: while l < lineno: - print f.readline()[:-1] + print(f.readline()[:-1]) l += 1 - print ("# %8d %6.3f%% %8d %6.3f%%" + print("# %8d %6.3f%% %8d %6.3f%%" % (time, time * 100.0 / total_time, count, count * 100.0 / total_count)) if cur != None and f != None: for line in f: - print line[:-1] + print(line[:-1]) f.close() def main(args): @@ -747,7 +747,7 @@ def main(args): import profile pr = profile.Profile() for i in range(5): - print pr.calibrate(100000) + print(pr.calibrate(100000)) return elif args[1] == "p": import profile diff --git a/mymc.py b/mymc.py index 51068ec..e2a3c80 100755 --- a/mymc.py +++ b/mymc.py @@ -7,7 +7,7 @@ """A utility for manipulating PS2 memory card images.""" -_SCCS_ID = "@(#) mymc mymc.py 1.13 22/01/15 01:04:45\n"[:-1] +_SCCS_ID = "@(#) mymc mymc.py 1.14 23/07/06 15:51:52\n"[:-1] import sys import os @@ -50,7 +50,7 @@ def __getattribute__(self, name): def __setattr__(self, name, value): if name == "encoding": - raise TypeError, "readonly attribute" + raise TypeError("readonly attribute") return setattr(object.__getattribute__(self, "_f"), name, value) @@ -89,7 +89,7 @@ def _copy(fout, fin): while True: s = fin.read(1024) - if s == "": + if s == b"": break fout.write(s) @@ -157,7 +157,7 @@ def do_extract(cmd, mc, opts, args, opterr): if opts.use_stdout: opterr("The -o and -p options are mutually exclusive.") dont_close_out = True - out = file(opts.output, "wb") + out = open(opts.output, "wb") elif opts.use_stdout: out = sys.stdout @@ -169,7 +169,7 @@ def do_extract(cmd, mc, opts, args, opterr): _copy(out, f) continue a = filename.split("/") - o = file(a[-1], "wb") + o = open(a[-1], "wb") try: _copy(o, f) finally: @@ -205,7 +205,7 @@ def do_import(cmd, mc, opts, args, opterr): for filename in args: sf = ps2save.ps2_save_file() - f = file(filename, "rb") + f = open(filename, "rb") try: ftype = ps2save.detect_file_type(f) f.seek(0) @@ -218,21 +218,21 @@ def do_import(cmd, mc, opts, args, opterr): elif ftype == "sps": sf.load_sharkport(f) elif ftype == "npo": - raise io_error, (EIO, "nPort saves" + raise io_error((EIO, "nPort saves" " are not supported.", - filename) + filename)) else: - raise io_error, (EIO, "Save file format not" - " recognized", filename) + raise io_error((EIO, "Save file format not" + " recognized", filename)) finally: f.close() dirname = opts.directory if dirname == None: dirname = sf.get_directory()[8] - print "Importing", filename, "to", dirname + print("Importing", filename, "to", dirname) if not mc.import_save_file(sf, opts.ignore_existing, opts.directory): - print (filename + ": already in memory card image," + print(filename + ": already in memory card image," " ignored.") #re_num = re.compile("[0-9]+") @@ -275,9 +275,9 @@ def do_export(cmd, mc, opts, args, opterr): continue raise io_error(EEXIST, "File exists", filename) - f = file(filename, "wb") + f = open(filename, "wb") try: - print "Exporing", dirname, "to", filename + print("Exporing", dirname, "to", filename) if opts.type == "max": sf.save_max_drive(f) @@ -326,7 +326,7 @@ def do_setmode(cmd, mc, opts, args, opterr): ent = mc.get_dirent(arg) if value == None: ent[0] = (ent[0] & clear_mask) | set_mask - # print "new %04x" % ent[0] + # print("new %04x" % ent[0]) else: ent[0] = value mc.set_dirent(arg, ent) @@ -337,7 +337,7 @@ def do_rename(cmd, mc, opts, args, opterr): mc.rename(args[0], args[1]) def _get_ps2_title(mc, enc): - s = mc.get_icon_sys("."); + s = mc.get_icon_sys(".") if s == None: return None a = ps2save.unpack_icon_sys(s) @@ -394,10 +394,10 @@ def do_dir(cmd, mc, opts, args, opterr): if type != None: protection = type - print "%-32s %s" % (ent[8], title[0]) - print ("%4dKB %-25s %s" + print("%-32s %s" % (ent[8], title[0])) + print("%4dKB %-25s %s" % (length / 1024, protection, title[1])) - print + print() finally: if f != None: f.close() @@ -412,18 +412,18 @@ def do_dir(cmd, mc, opts, args, opterr): else: free = "%d" % free - print free + " KB Free" + print(free + " KB Free") def do_df(cmd, mc, opts, args, opterr): if len(args) != 0: opterr("Incorrect number of arguments.") - print mc.f.name + ":", mc.get_free_space(), "bytes free." + print(mc.f.name + ":", mc.get_free_space(), "bytes free.") def do_check(cmd, mc, opts, args, opterr): if len(args) != 0: opterr("Incorrect number of arguments.") if mc.check(): - print "No errors found." + print("No errors found.") return 0 return 1 @@ -443,13 +443,13 @@ def do_format(cmd, mcname, opts, args, opterr): if not opts.overwrite_existing: exists = True try: - file(mcname, "rb").close() + open(mcname, "rb").close() except EnvironmentError: exists = False if exists: - raise io_error, (EEXIST, "file exists", mcname) + raise io_error(EEXIST, "file exists", mcname) - f = file(mcname, "w+b") + f = open(mcname, "w+b") try: ps2mc.ps2mc(f, True, params).close() finally: @@ -472,10 +472,10 @@ def do_create_pad(cmd, mc, opts, args, opterr): length = mc.clusters_per_card if len(args) > 1: length = int(args[1]) - pad = "\0" * mc.cluster_size + pad = b"\0" * mc.cluster_size f = mc.open(args[0], "wb") try: - for i in xrange(length): + for i in range(length): f.write(pad) finally: f.close() @@ -484,15 +484,15 @@ def do_create_pad(cmd, mc, opts, args, opterr): def do_frob(cmd, mc, opts, args, opterr): mc.write_superblock() -_trans = string.maketrans("".join(map(chr, range(32))), " " * 32) +_trans = str.maketrans("".join(map(chr, range(32))), " " * 32) def _print_bin(base, s): for off in range(0, len(s), 16): - print "%04X" % (base + off), + print("%04X" % (base + off)) a = s[off : off + 16] for b in a: - print "%02X" % ord(b), - print "", a.translate(_trans) + print("%02X" % ord(b)) + print("", a.translate(_trans)) def _print_erase_block(mc, n): ppb = mc.pages_per_erase_block @@ -503,9 +503,9 @@ def _print_erase_block(mc, n): print def do_print_good_blocks(cmd, mc, opts, args, opterr): - print "good_block2:" + print("good_block2:") _print_erase_block(mc, mc.good_block2) - print "good_block1:" + print("good_block1:") _print_erase_block(mc, mc.good_block1) def do_ecc_check(cmd, mc, opts, args, opterr): @@ -513,7 +513,7 @@ def do_ecc_check(cmd, mc, opts, args, opterr): try: mc.read_page(i) except ps2mc.ecc_error: - print "bad: %05x" % i + print("bad: %05x" % i) opt = optparse.make_option @@ -688,7 +688,7 @@ class suboption_parser(optparse.OptionParser): def exit(self, status = 0, msg = None): if msg: sys.stderr.write(msg) - raise subopt_error, status + raise subopt_error(status) class my_help_formatter(optparse.IndentedHelpFormatter): """A better formatter for optparser's help message""" @@ -713,7 +713,7 @@ def format_description(self, description): return "\n".join(lines) + "\n" def main(): - prog = sys.argv[0].decode(sys.getdefaultencoding(), "replace") + prog = sys.argv[0] usage = "usage: %prog [-ih] memcard.ps2 command [...]" description = ("Manipulate PS2 memory card images.\n\n" "Supported commands: ") @@ -780,7 +780,7 @@ def main(): ret = fn(cmd, mcname, subopts, subargs, subopt_parser.error) else: - f = file(mcname, mode) + f = open(mcname, mode) mc = ps2mc.ps2mc(f, opts.ignore_ecc) ret = fn(cmd, mc, subopts, subargs, subopt_parser.error) @@ -788,15 +788,15 @@ def main(): if mc != None: mc.close() if f != None: - # print "f.close()" + # print("f.close()") f.close() - except EnvironmentError, value: - if getattr(value, "filename", None) != None: - write_error(value.filename, value.strerror) + except EnvironmentError as e: + if getattr(e, "filename", None) != None: + write_error(e.filename, e.strerror) ret = 1 - elif getattr(value, "strerror", None) != None: - write_error(mcname, value.strerror) + elif getattr(e, "strerror", None) != None: + write_error(mcname, e.strerror) ret = 1 else: # something weird @@ -804,14 +804,14 @@ def main(): if opts.debug: raise - except subopt_error, (ret,): + except subopt_error: pass - except (ps2mc.error, ps2save.error), value: - fn = getattr(value, "filename", None) + except (ps2mc.error, ps2save.error) as e: + fn = getattr(e, "filename", None) if fn == None: fn = mcname - write_error(fn, str(value)) + write_error(fn, str(e)) if opts.debug: raise ret = 1 diff --git a/ps2mc.py b/ps2mc.py index 8e3ca21..7d1b4c1 100755 --- a/ps2mc.py +++ b/ps2mc.py @@ -7,7 +7,7 @@ """Manipulate PS2 memory card images.""" -_SCCS_ID = "@(#) mymc ps2mc.py 1.11 22/01/15 01:17:07\n" +_SCCS_ID = "@(#) mymc ps2mc.py 1.12 23/07/06 19:48:03\n" import sys import array @@ -97,7 +97,7 @@ def unpack_32bit_array(s): return array.array('I', s) def pack_32bit_array(a): - return a.tostring() + return a.tobytes() def unpack_superblock(s): sb = struct.unpack("<28s12sHHHHLLLLLL8x128s128sbbxx", s) @@ -135,10 +135,10 @@ def dump(self): lru_list = self._lru_list i = 0 while i != len(self._lru_list): - print "%d: %s, " % (i, str(lru_list[i][1])), - i = lru_list[i][3] - print - print self._index_map + print("%d: %s, " % (i, str(lru_list[i][1])), + i = lru_list[i][3]) + print() + print(self._index_map) def _move_to_front(self, i): lru_list = self._lru_list @@ -161,10 +161,10 @@ def add(self, key, value): ret = None if key in index_map: i = index_map[key] - # print "add hit ", key, i + # print("add hit ", key, i) elt = lru_list[i] else: - # print "add miss", key + # print("add miss", key) i = lru_list[-1][0] elt = lru_list[i] old_key = elt[1] @@ -181,9 +181,9 @@ def add(self, key, value): def get(self, key, default = None): i = self._index_map.get(key) if i == None: - # print "get miss", key + # print("get miss", key) return default - # print "get hit ", key, i + # print("get hit ", key, i) ret = self._lru_list[i][2] self._move_to_front(i) return ret @@ -207,15 +207,15 @@ def __getitem__(self, i): # not iterable offset = self.offset if i == offset: - # print "@@@ fat_chain[] cur:", i, self._cur + # print("@@@ fat_chain[] cur:", i, self._cur) return self._cur elif i == offset - 1: assert self._prev != None - # print "@@@ fat_chain[] prev:", i, self._prev + # print("@@@ fat_chain[] prev:", i, self._prev) return self._prev if i < offset: if i == 0: - # print "@@@ fat_chain[] first", i, self._first + # print("@@@ fat_chain[] first", i, self._first) return self._first offset = 0 prev = None @@ -223,7 +223,7 @@ def __getitem__(self, i): else: prev = self._prev cur = self._cur - # print "@@@ fat_chain[] distance", i - offset + # print("@@@ fat_chain[] distance", i - offset) while offset != i: next = self.lookup_fat(cur) if next == PS2MC_FAT_CHAIN_END: @@ -241,8 +241,8 @@ def __getitem__(self, i): self.offset = offset self._prev = prev self._cur = cur - # print "@@@ offset, prev, cur:", offset, prev, cur - # print "@@@ fat_chain[]", i, next + # print("@@@ offset, prev, cur:", offset, prev, cur) + # print("@@@ fat_chain[]", i, next) return next def __len__(self): @@ -262,7 +262,7 @@ class ps2mc_file(object): def __init__(self, mc, dirloc, first_cluster, length, mode, name = None): - # print "ps2mc_file.__init__", name, self + # print("ps2mc_file.__init__", name, self) self.mc = mc self.length = length self.first_cluster = first_cluster @@ -297,7 +297,7 @@ def read_file_cluster(self, n): if n == self.buffer_cluster: return self.buffer cluster = self._find_file_cluster(n) - # print "@@@ read_file_cluster", self.dirloc, n, cluster, repr(self.name) + # print("@@@ read_file_cluster", self.dirloc, n, cluster, repr(self.name)) if cluster == PS2MC_FAT_CHAIN_END: return None self.buffer = self.mc.read_allocatable_cluster(cluster) @@ -307,18 +307,18 @@ def read_file_cluster(self, n): def _extend_file(self, n): mc = self.mc cluster = mc.allocate_cluster() - # print "@@@ extending file", n, cluster + # print("@@@ extending file", n, cluster) if cluster == None: return None if n == 0: self.first_cluster = cluster self.fat_chain = None - # print "@@@ linking", self.dirloc, "->", cluster + # print("@@@ linking", self.dirloc, "->", cluster) mc.update_dirent(self.dirloc, self, cluster, None, False) else: prev = self.fat_chain[n - 1] - # print "@@@ linking", prev, "->", cluster + # print("@@@ linking", prev, "->", cluster) mc.set_fat(prev, cluster | PS2MC_FAT_ALLOCATED_BIT) return cluster @@ -336,7 +336,7 @@ def write_file_cluster(self, n, buf): if (cluster < file_cluster_end or len(self.fat_chain) != file_cluster_end): - raise corrupt, ("file length doesn't match cluster" + raise corrupt("file length doesn't match cluster" " chain length", mc.f) for i in range(file_cluster_end, n): @@ -349,7 +349,7 @@ def write_file_cluster(self, n, buf): True) return False mc.write_allocatable_cluster(cluster, - ["\0"] * cluster_size) + [b"\0"] * cluster_size) cluster = self._extend_file(n) if cluster == None: @@ -370,18 +370,18 @@ def update_notify(self, first_cluster, length): def read(self, size = None, eol = None): if self.closed: - raise ValueError, "file is closed" + raise ValueError("file is closed") pos = self._pos cluster_size = self.mc.cluster_size if size == None: size = self.length size = max(min(self.length - pos, size), 0) - ret = "" + ret = b"" while size > 0: - off = pos % cluster_size + off = int(pos % cluster_size) l = min(cluster_size - off, size) - buf = self.read_file_cluster(pos / cluster_size) + buf = self.read_file_cluster(int(pos / cluster_size)) if buf == None: break if eol != None: @@ -397,22 +397,22 @@ def read(self, size = None, eol = None): def write(self, out, _set_modified = True): if self.closed: - raise ValueError, "file is closed" + raise ValueError("file is closed") cluster_size = self.mc.cluster_size pos = self._pos if self._append: pos = self.length elif not self._write: - raise io_error, (EACCES, "file not opened for writing", + raise io_error(EACCES, "file not opened for writing", self.name) size = len(out) - # print "@@@ write", pos, size + # print("@@@ write", pos, size) i = 0 while size > 0: - cluster = pos / cluster_size - off = pos % cluster_size + cluster = int(pos / cluster_size) + off = int(pos % cluster_size) l = min(cluster_size - off, size) s = out[i : i + l] pos += l @@ -421,14 +421,14 @@ def write(self, out, _set_modified = True): else: buf = self.read_file_cluster(cluster) if buf == None: - buf = "\0" * cluster_size + buf = b"\0" * cluster_size buf = buf[:off] + s + buf[off + l:] if not self.write_file_cluster(cluster, buf): - raise io_error, (ENOSPC, + raise io_error(ENOSPC, "out of space on image", self.name) self._pos = pos - # print "@@@ pos", pos + # print("@@@ pos", pos) new_length = None if pos > self.length: new_length = self.length = pos @@ -439,7 +439,7 @@ def write(self, out, _set_modified = True): size -= l def close(self): - # print "ps2mc_file.close", self.name, self + # print("ps2mc_file.close", self.name, self) if self.mc != None: self.mc.notify_closed(self.dirloc, self) self.mc = None @@ -460,7 +460,7 @@ def readlines(self, sizehint): def seek(self, offset, whence = 0): if self.closed: - raise ValueError, "file is closed" + raise ValueError("file is closed") if whence == 1: base = self._pos @@ -473,7 +473,7 @@ def seek(self, offset, whence = 0): def tell(self): if self.closed: - raise ValueError, "file is closed" + raise ValueError("file is closed") return self._pos def __enter__(self): @@ -484,7 +484,7 @@ def __exit__(self, a, b, c): return # def __del__(self): - # # print "ps2mc_file.__del__", self + # # print("ps2mc_file.__del__", self) # if self.mc != None: # self.mc.notify_closed(self.dirloc, self) # self.mc = None @@ -499,7 +499,7 @@ def __init__(self, mc, dirloc, first_cluster, length, length * PS2MC_DIRENT_LENGTH, mode, name) def __iter__(self): - start = self.tell() + start = int(self.tell()) if start != 0: start -= 1 self.seek(start) @@ -507,15 +507,15 @@ def __iter__(self): return self def write_raw_ent(self, index, ent, set_modified): - # print "@@@ write_raw_ent", index + # print("@@@ write_raw_ent", index) self.seek(index) self.f.write(pack_dirent(ent), _set_modified = set_modified) - def next(self): - # print "@@@ next", self.tell(), self.f.name + def __next__(self): + # print("@@@ next", self.tell(), self.f.name) dirent = self.f.read(PS2MC_DIRENT_LENGTH) - if dirent == "": + if dirent == b"": if 0 == self._iter_end: raise StopIteration self.seek(0) @@ -528,13 +528,13 @@ def seek(self, offset, whence = 0): self.f.seek(offset * PS2MC_DIRENT_LENGTH, whence) def tell(self): - return self.f.tell() / PS2MC_DIRENT_LENGTH + return int(self.f.tell() / PS2MC_DIRENT_LENGTH) def __len__(self): - return self.f.length / PS2MC_DIRENT_LENGTH + return int(self.f.length / PS2MC_DIRENT_LENGTH) def __getitem__(self, index): - # print "@@@ getitem", index, self.f.name + # print("@@@ getitem", index, self.f.name) self.seek(index) dirent = self.f.read(PS2MC_DIRENT_LENGTH) if len(dirent) != PS2MC_DIRENT_LENGTH: @@ -556,12 +556,12 @@ def __setitem__(self, index, new_ent): self.write_raw_ent(index, ent, False) def close(self): - # print "ps2mc_directory.close", self + # print("ps2mc_directory.close", self) self.f.close() self.f = None def __del__(self): - # print "ps2mc_directory.__del__", self + # print("ps2mc_directory.__del__", self) if self.f != None: self.f.close() self.f = None @@ -596,7 +596,7 @@ def _calculate_derived(self): self.spare_size = div_round_up(self.page_size, 128) * 4 self.raw_page_size = self.page_size + self.spare_size self.cluster_size = self.page_size * self.pages_per_cluster - self.entries_per_cluster = (self.page_size + self.entries_per_cluster = int(self.page_size * self.pages_per_cluster / 4) limit = (min(self.good_block2, self.good_block1) @@ -615,15 +615,15 @@ def __init__(self, f, ignore_ecc = False, params = None): f.seek(0) s = f.read(0x154) - if len(s) != 0x154 or not s.startswith(PS2MC_MAGIC): + header = PS2MC_MAGIC.encode("utf-8") + if len(s) != 0x154 or not s[0:len(header)] == header: if (params == None): - raise corrupt, ("Not a PS2 memory card image", - f) + raise corrupt("Not a PS2 memory card image", f) self.f = f self.format(params) else: sb = unpack_superblock(s) - self.version = sb[1] + self.version = sb[1].decode("ascii") self.page_size = sb[2] self.pages_per_cluster = sb[3] self.pages_per_erase_block = sb[4] @@ -658,14 +658,14 @@ def __init__(self, f, ignore_ecc = False, params = None): root.close() if (dot[8] != "." or dotdot[8] != ".." or not mode_is_dir(dot[0]) or not mode_is_dir(dotdot[0])): - raise corrupt, "Root directory damaged." + raise corrupt("Root directory damaged.") self.fat_cursor = 0 self.curdir = (0, 0) def write_superblock(self): - s = pack_superblock((PS2MC_MAGIC, - self.version, + s = pack_superblock((PS2MC_MAGIC.encode("ascii"), + self.version.encode("ascii"), self.page_size, self.pages_per_cluster, self.pages_per_erase_block, @@ -680,10 +680,10 @@ def write_superblock(self): self.bad_erase_block_list, 2, 0x2B)) - s += "\x00" * (self.page_size - len(s)) + s += b"\x00" * (self.page_size - len(s)) self.write_page(0, s) - page = "\xFF" * self.raw_page_size + page = b"\xFF" * self.raw_page_size self.f.seek(self.good_block2 * self.pages_per_erase_block * self.raw_page_size) for i in range(self.pages_per_erase_block): @@ -699,23 +699,23 @@ def format(self, params): pages_per_erase_block, param_pages_per_card) = params if pages_per_erase_block < 1: - raise error, ("invalid pages per erase block (%d)" + raise error("invalid pages per erase block (%d)" % page_size) pages_per_card = round_down(param_pages_per_card, pages_per_erase_block) cluster_size = PS2MC_CLUSTER_SIZE - pages_per_cluster = cluster_size / page_size - clusters_per_erase_block = (pages_per_erase_block + pages_per_cluster = int(cluster_size / page_size) + clusters_per_erase_block = int(pages_per_erase_block / pages_per_cluster) - erase_blocks_per_card = pages_per_card / pages_per_erase_block - clusters_per_card = pages_per_card / pages_per_cluster - epc = cluster_size / 4 + erase_blocks_per_card = int(pages_per_card / pages_per_erase_block) + clusters_per_card = int(pages_per_card / pages_per_cluster) + epc = int(cluster_size / 4) if (page_size < PS2MC_DIRENT_LENGTH or pages_per_cluster < 1 or pages_per_cluster * page_size != cluster_size): - raise error, "invalid page size (%d)" % page_size + raise error("invalid page size (%d)" % page_size) good_block1 = erase_blocks_per_card - 1 good_block2 = erase_blocks_per_card - 2 @@ -737,10 +737,10 @@ def format(self, params): * clusters_per_erase_block - allocatable_cluster_offset) if allocatable_cluster_end < 1: - raise error, ("memory card image too small" + raise error("memory card image too small" " to be formatted") - ifc_list = unpack_fat("\0\0\0\0" + ifc_list = unpack_fat(b"\0\0\0\0" * PS2MC_MAX_INDIRECT_FAT_CLUSTERS) for i in range(indirect_fat_clusters): ifc_list[i] = first_ifc + i @@ -756,19 +756,19 @@ def format(self, params): self.good_block1 = good_block1 self.good_block2 = good_block2 self.indirect_fat_cluster_list = ifc_list - bebl = "\xFF\xFF\xFF\xFF" * 32 + bebl = b"\xFF\xFF\xFF\xFF" * 32 self.bad_erase_block_list = unpack_32bit_array(bebl) self._calculate_derived() self.ignore_ecc = not with_ecc - erased = "\0" * page_size + erased = b"\0" * page_size if not with_ecc: self.spare_size = 0 else: ecc = "".join(["".join(map(chr, s)) for s in ecc_calculate_page(erased)]) - erased += ecc + "\0" * (self.spare_size - len(ecc)) + erased += ecc.encode("utf-8") + b"\0" * (self.spare_size - len(ecc)) self.f.seek(0) for page in range(pages_per_card): @@ -802,7 +802,7 @@ def format(self, params): s = pack_dirent((DF_RWX | DF_DIR | DF_0400 | DF_EXISTS, 0, 2, now, 0, 0, now, 0, ".")) - s += "\0" * (cluster_size - len(s)) + s += b"\0" * (cluster_size - len(s)) self.write_allocatable_cluster(0, s) dir = self._directory((0, 0), 0, 2, "wb", "/") dir.write_raw_ent(1, (DF_WRITE | DF_EXECUTE | DF_DIR | DF_0400 @@ -814,22 +814,22 @@ def format(self, params): self.flush() def read_page(self, n): - # print "@@@ page", n + # print("@@@ page", n) f = self.f f.seek(self.raw_page_size * n) page = f.read(self.page_size) if len(page) != self.page_size: - raise corrupt, ("attempted to read past EOF" + raise corrupt("attempted to read past EOF" " (page %05X)" % n, f) if self.ignore_ecc: return page spare = f.read(self.spare_size) if len(spare) != self.spare_size: - raise corrupt, ("attempted to read past EOF" + raise corrupt("attempted to read past EOF" " (page %05X)" % n, f) (status, page, spare) = ecc_check_page(page, spare) if status == ECC_CHECK_FAILED: - raise ecc_error, ("Unrecoverable ECC error (page %d)" + raise ecc_error("Unrecoverable ECC error (page %d)" % n) return page @@ -838,7 +838,7 @@ def write_page(self, n, buf): f.seek(self.raw_page_size * n) self.modified = True if len(buf) != self.page_size: - raise error, ("internal error: write_page:" + raise error("internal error: write_page:" " %d != %d" % (len(buf), self.page_size)) f.write(buf) if self.spare_size != 0: @@ -846,7 +846,7 @@ def write_page(self, n, buf): for s in ecc_calculate_page(buf): a.fromlist(s) a.tofile(f) - f.write("\0" * (self.spare_size - len(a))) + f.write(b"\0" * (self.spare_size - len(a))) def read_cluster(self, n): pages_per_cluster = self.pages_per_cluster @@ -866,7 +866,7 @@ def write_cluster(self, n, buf): if self.spare_size == 0: self.f.seek(cluster_size * n) if len(buf) != cluster_size: - raise error, ("internal error: write_cluster:" + raise error("internal error: write_cluster:" " %d != %d" % (len(buf), cluster_size)) return self.f.write(buf) @@ -887,9 +887,9 @@ def _add_fat_cluster_to_cache(self, n, fat, dirty): def _read_fat_cluster(self, n): v = self.fat_cache.get(n) if v != None: - # print "@@@ fat hit", n + # print("@@@ fat hit", n) return v[0] - # print "@@@ fat miss", n + # print("@@@ fat miss", n) fat = unpack_fat(self.read_cluster(n)) self._add_fat_cluster_to_cache(n, fat, False) return fat @@ -917,9 +917,9 @@ def _add_alloc_cluster_to_cache(self, n, buf, dirty): def read_allocatable_cluster(self, n): a = self.alloc_cluster_cache.get(n) if a != None: - # print "@@@ cache hit", n + # print("@@@ cache hit", n) return a[0] - # print "@@@ cache miss", n + # print("@@@ cache miss", n) buf = self.read_cluster(n + self.allocatable_cluster_offset) self._add_alloc_cluster_to_cache(n, buf, False) return buf @@ -938,8 +938,8 @@ def flush_alloc_cluster_cache(self): a[1] = False def read_fat_cluster(self, n): - indirect_offset = n % self.entries_per_cluster - dbl_offset = n / self.entries_per_cluster + indirect_offset = int(n % self.entries_per_cluster) + dbl_offset = int(n / self.entries_per_cluster) indirect_cluster = self.indirect_fat_cluster_list[dbl_offset] indirect_fat = self._read_fat_cluster(indirect_cluster) cluster = indirect_fat[indirect_offset] @@ -947,11 +947,11 @@ def read_fat_cluster(self, n): def read_fat(self, n): if n < 0 or n >= self.allocatable_cluster_end: - raise io_error, (EIO, + raise io_error(EIO, "FAT cluster index out of range" " (%d)" % n) - offset = n % self.entries_per_cluster - fat_cluster = n / self.entries_per_cluster + offset = int(n % self.entries_per_cluster) + fat_cluster = int(n / self.entries_per_cluster) (fat, cluster) = self.read_fat_cluster(fat_cluster) return (fat, offset, cluster) @@ -969,7 +969,7 @@ def allocate_cluster(self): allocatable_cluster_limit = self.allocatable_cluster_limit end = div_round_up(allocatable_cluster_limit, epc) - remainder = allocatable_cluster_limit % epc + remainder = int(allocatable_cluster_limit % epc) while self.fat_cursor < end: (fat, cluster) = self.read_fat_cluster(self.fat_cursor) @@ -983,7 +983,7 @@ def allocate_cluster(self): fat[offset] = PS2MC_FAT_CHAIN_END self._write_fat_cluster(cluster, fat) ret = self.fat_cursor * epc + offset - # print "@@@ allocated", ret + # print("@@@ allocated", ret) return ret self.fat_cursor += 1 return None @@ -1011,7 +1011,7 @@ def directory(self, dirloc, first_cluster, length, def _directory(self, dirloc, first_cluster, length, mode = None, name = None): - # print "@@@ _directory", dirloc, first_cluster, length + # print("@@@ _directory", dirloc, first_cluster, length) if first_cluster != 0: return self.directory(dirloc, first_cluster, length, mode, name) @@ -1061,8 +1061,8 @@ def _opendir_parent_dirloc(self, dirloc, mode = "rb"): mode) def update_dirent_all(self, dirloc, thisf, new_ent): - # print "@@@ update_dirent", dirloc - # print "@@@ new_ent", new_ent + # print("@@@ update_dirent", dirloc) + # print("@@@ new_ent", new_ent) opened = self.open_files.get(dirloc, None) if opened == None: files = [] @@ -1075,15 +1075,15 @@ def update_dirent_all(self, dirloc, thisf, new_ent): opened[0] = dir ent = dir[dirloc[1]] - # print "@@@ old_ent", ent + # print("@@@ old_ent", ent) is_dir = ent[0] & DF_DIR if is_dir and thisf != None and new_ent[2] != None: new_ent = list(new_ent) - new_ent[2] /= PS2MC_DIRENT_LENGTH + new_ent[2] = int(new_ent[2] / PS2MC_DIRENT_LENGTH) - # print "len: ", ent[2], new_ent[2] + # print("len: ", ent[2], new_ent[2]) modified = changed = notify = False for i in range(len(ent)): @@ -1136,7 +1136,7 @@ def notify_closed(self, dirloc, thisf): dir, files = a files.discard(thisf) if len(files) == 0: - # print "@@@ notify_closed", dir + # print("@@@ notify_closed", dir) if dir != None: dir.close() del self.open_files[dirloc] @@ -1148,7 +1148,7 @@ def search_directory(self, dir, name): start = dir.tell() - 1 if start == -1: start = 0 - for i in range(start, len(dir)) + range(0, start): + for i in list(range(start, len(dir))) + list(range(0, start)): try: ent = dir[i] except IndexError: @@ -1162,14 +1162,14 @@ def create_dir_entry(self, parent_dirloc, name, mode): """Create a new directory entry in a directory.""" if name == "": - raise file_not_found, name + raise file_not_found(name) - # print "@@@ create_dir_ent", parent_dirloc, name + # print("@@@ create_dir_ent", parent_dirloc, name) dir_ent = self._dirloc_to_ent(parent_dirloc) dir = self._directory(parent_dirloc, dir_ent[4], dir_ent[2], "r+b") l = len(dir) - # print "@@@ len", l + # print("@@@ len", l) assert l >= 2 for i in range(l): ent = dir[i] @@ -1179,7 +1179,7 @@ def create_dir_entry(self, parent_dirloc, name, mode): i = l dirloc = (dir_ent[4], i) - # print "@@@ dirloc", dirloc + # print("@@@ dirloc", dirloc) now = tod_now() if mode & DF_DIR: mode &= ~DF_FILE @@ -1203,13 +1203,13 @@ def create_dir_entry(self, parent_dirloc, name, mode): dir.close() if mode & DF_FILE: - # print "@@@ ret", dirloc, ent + # print("@@@ ret", dirloc, ent) return (dirloc, ent) dirent = pack_dirent((DF_RWX | DF_0400 | DF_DIR | DF_EXISTS, 0, 0, now, dirloc[0], dirloc[1], now, 0, ".")) - dirent += "\0" * (self.cluster_size - PS2MC_DIRENT_LENGTH) + dirent += b"\0" * (self.cluster_size - PS2MC_DIRENT_LENGTH) self.write_allocatable_cluster(cluster, dirent) dir = self._directory(dirloc, cluster, 1, "wb", name = "") @@ -1219,24 +1219,24 @@ def create_dir_entry(self, parent_dirloc, name, mode): now, 0, ".."), False) dir.close() ent[2] = 2 - # print "@@@ ret", dirloc, ent + # print("@@@ ret", dirloc, ent) return (dirloc, ent) def delete_dirloc(self, dirloc, truncate, name): """Delete or truncate the file or directory given by dirloc.""" if dirloc == (0, 0): - raise io_error, (EACCES, + raise io_error(EACCES, "cannot remove root directory", name) if dirloc[1] in [0, 1]: - raise io_error, (EACCES, + raise io_error(EACCES, 'cannot remove "." or ".." entries', name) if dirloc in self.open_files: - raise io_error, (EBUSY, - "cannot remove open file", filename) + raise io_error(EBUSY, + "cannot remove open file", name) epc = self.entries_per_cluster @@ -1252,7 +1252,7 @@ def delete_dirloc(self, dirloc, truncate, name): while cluster != PS2MC_FAT_CHAIN_END: if cluster / epc < self.fat_cursor: - self.fat_cursor = cluster / epc + self.fat_cursor = int(cluster / epc) next_cluster = self.lookup_fat(cluster) if next_cluster & PS2MC_FAT_ALLOCATED_BIT == 0: # corrupted @@ -1277,7 +1277,7 @@ def path_search(self, pathname): is a boolean value that's true if the pathname refers a directory.""" - # print "@@@ path_search", repr(pathname) + # print("@@@ path_search", repr(pathname)) if pathname == "": return (None, None, False) @@ -1302,7 +1302,7 @@ def path_search(self, pathname): name = tmpname) for s in components: - # print "@@@", dirloc, repr(s), dir == None, ent + # print("@@@", dirloc, repr(s), dir == None, ent) if dir == None: # tried to traverse a file or a @@ -1349,15 +1349,15 @@ def open(self, filename, mode = "r"): """Open a file, returning a new file-like object for it.""" (dirloc, ent, is_dir) = self.path_search(filename) - # print "@@@ open", (dirloc, ent) + # print("@@@ open", (dirloc, ent)) if dirloc == None: - raise path_not_found, filename + raise path_not_found(filename) if is_dir: - raise io_error, (EISDIR, "not a regular file", + raise io_error(EISDIR, "not a regular file", filename) if ent[0] == 0: if mode[0] not in "wa": - raise file_not_found, filename + raise file_not_found(filename) name = ent[8] (dirloc, ent) = self.create_dir_entry(dirloc, name, DF_FILE | DF_RWX @@ -1372,19 +1372,19 @@ def open(self, filename, mode = "r"): def dir_open(self, filename, mode = "rb"): (dirloc, ent, is_dir) = self.path_search(filename) if dirloc == None: - raise path_not_found, filename + raise path_not_found(filename) if ent[0] == 0: - raise dir_not_found, filename + raise dir_not_found(filename) if not is_dir: - raise io_error, (ENOTDIR, "not a directory", filename) + raise io_error(ENOTDIR, "not a directory", filename) return self.directory(dirloc, ent[4], ent[2], mode, filename) def mkdir(self, filename): (dirloc, ent, is_dir) = self.path_search(filename) if dirloc == None: - raise path_not_found, filename + raise path_not_found(filename) if ent[0] != 0: - raise io_error, (EEXIST, "directory exists", filename) + raise io_error(EEXIST, "directory exists", filename) name = ent[8] self.create_dir_entry(dirloc, name, DF_DIR | DF_RWX | DF_0400) self.flush() @@ -1407,16 +1407,16 @@ def remove(self, filename): (dirloc, ent, is_dir) = self.path_search(filename) if dirloc == None: - raise path_not_found, filename + raise path_not_found(filename) if ent[0] == 0: - raise file_not_found, filename + raise file_not_found(filename) if is_dir: if ent[4] == 0: - raise io_error, (EACCES, + raise io_error(EACCES, "cannot remove" " root directory") if not self._is_empty(dirloc, ent, filename): - raise io_error, (ENOTEMPTY, + raise io_error(ENOTEMPTY, "directory not empty", filename) self.delete_dirloc(dirloc, False, filename) @@ -1425,11 +1425,11 @@ def remove(self, filename): def chdir(self, filename): (dirloc, ent, is_dir) = self.path_search(filename) if dirloc == None: - raise path_not_found, filename + raise path_not_found(filename) if ent[0] == 0: - raise dir_not_found, filename + raise dir_not_found(filename) if not is_dir: - raise io_error, (ENOTDIR, "not a directory", filename) + raise io_error(ENOTDIR, "not a directory", filename) self.curdir = dirloc def get_mode(self, filename): @@ -1448,9 +1448,9 @@ def get_dirent(self, filename): (dirloc, ent, is_dir) = self.path_search(filename) if dirloc == None: - raise path_not_found, filename + raise path_not_found(filename) if ent[0] == 0: - raise file_not_found, filename + raise file_not_found(filename) return ent def set_dirent(self, filename, new_ent): @@ -1461,9 +1461,9 @@ def set_dirent(self, filename, new_ent): (dirloc, ent, is_dir) = self.path_search(filename) if dirloc == None: - raise path_not_found, filename + raise path_not_found(filename) if ent[0] == 0: - raise file_not_found, filename + raise file_not_found(filename) dir = self._opendir_parent_dirloc(dirloc, "r+b") try: new_ent = list(new_ent) @@ -1485,23 +1485,23 @@ def is_ancestor(self, dirloc, olddirloc): def rename(self, oldpathname, newpathname): (olddirloc, oldent, is_dir) = self.path_search(oldpathname) if olddirloc == None: - raise path_not_found, oldpathname + raise path_not_found(oldpathname) if oldent[0] == 0: - raise file_not_found, oldpathname + raise file_not_found(oldpathname) if olddirloc == (0, 0): - raise io_error, (EINVAL, + raise io_error(EINVAL, "cannot rename root directory", oldpathname) if olddirloc in self.open_files: - raise io_error, (EBUSY, "cannot rename open file", + raise io_error(EBUSY, "cannot rename open file", newname) (newparentdirloc, newent, x) = self.path_search(newpathname) if newparentdirloc == None: - raise path_not_found, newpathname + raise path_not_found(newpathname) if newent[0] != 0: - raise io_error, (EEXIST, "file exists", newpathname) + raise io_error(EEXIST, "file exists", newpathname) newname = newent[8] oldparentdirloc = self._get_parent_dirloc(olddirloc) @@ -1516,7 +1516,7 @@ def rename(self, oldpathname, newpathname): return if is_dir and self.is_ancestor(newparentdirloc, olddirloc): - raise io_error, (EINVAL, "cannot move directory" + raise io_error(EINVAL, "cannot move directory" " beneath itself", oldpathname) @@ -1573,11 +1573,11 @@ def import_save_file(self, sf, ignore_existing, dirname = None): (root_dirloc, ent, is_dir) = self.path_search(dirname) if root_dirloc == None: - raise path_not_found, dirname + raise path_not_found(dirname) if ent[0] != 0: if ignore_existing: return False - raise io_error, (EEXIST, "directory exists", dirname) + raise io_error(EEXIST, "directory exists", dirname) name = ent[8] mode = DF_DIR | (dir_ent[0] & ~DF_FILE) @@ -1592,7 +1592,7 @@ def import_save_file(self, sf, ignore_existing, dirname = None): (dirloc, ent) \ = self.create_dir_entry(dir_dirloc, ent[8], mode) - # print "@@@ file", dirloc, ent[4], ent[2] + # print("@@@ file", dirloc, ent[4], ent[2]) f = self.file(dirloc, ent[4], ent[2], "wb", dirname + ent[8]) try: @@ -1605,19 +1605,19 @@ def import_save_file(self, sf, ignore_existing, dirname = None): try: for i in range(dir_ent[2]): (ent, data) = sf.get_file(i) - # print "@@@ remove", ent[8] + # print("@@@ remove", ent[8]) self.remove(dirname + ent[8]) - except EnvironmentError, why: - # print "@@@ failed", why + except EnvironmentError as e: + # print("@@@ failed", e) pass try: - # print "@@@ remove dir", dirname + # print("@@@ remove dir", dirname) self.remove(dirname) - except EnvironmentError, why: - # print "@@@ failed", why + except EnvironmentError as e: + # print("@@@ failed", e) pass - raise type, what, where + raise Exception(type, what, where) finally: del where @@ -1644,13 +1644,13 @@ def import_save_file(self, sf, ignore_existing, dirname = None): def export_save_file(self, filename): (dir_dirloc, dirent, is_dir) = self.path_search(filename) if dir_dirloc == None: - raise path_not_found, filename + raise path_not_found(filename) if dirent[0] == 0: - raise dir_not_found, filename + raise dir_not_found(filename) if not is_dir: - raise io_error, (ENOTDIR, "not a directory", filename) + raise io_error(ENOTDIR, "not a directory", filename) if dir_dirloc == (0, 0): - raise io_error, (EACCES, "can't export root directory", + raise io_error(EACCES, "can't export root directory", filename) sf = ps2save.ps2_save_file() files = [] @@ -1661,7 +1661,7 @@ def export_save_file(self, filename): for i in range(2, dirent[2]): ent = dir[i] if not mode_is_file(ent[0]): - print ("warning: %s/%s is not a file," + print("warning: %s/%s is not a file," " ingored." % (dirent[8], ent[8])) continue @@ -1701,7 +1701,7 @@ def _remove_dir(self, dirloc, ent, dirname): self._remove_dir((first_cluster, i), ent, dirname + ent[8] + "/") else: - # print "deleting", dirname + ent[8] + # print("deleting", dirname + ent[8]) self.delete_dirloc((first_cluster, i), False, dirname + ent[8]) self.delete_dirloc(dirloc, False, dirname) @@ -1711,13 +1711,13 @@ def rmdir(self, dirname): (dirloc, ent, is_dir) = self.path_search(dirname) if dirloc == None: - raise path_not_found, dirname + raise path_not_found(dirname) if ent[0] == 0: - raise dir_not_found, dirname + raise dir_not_found(dirname) if not is_dir: - raise io_error, (ENOTDIR, "not a directory", dirname) + raise io_error(ENOTDIR, "not a directory", dirname) if dirloc == (0, 0): - raise io_error, (EACCES, "can't delete root directory", + raise io_error(EACCES, "can't delete root directory", dirname) if dirname != "" and dirname[-1] != "/": @@ -1728,7 +1728,7 @@ def get_free_space(self): """Returns the amount of free space in bytes.""" free = 0 - for i in xrange(self.allocatable_cluster_end): + for i in range(self.allocatable_cluster_end): if (self.lookup_fat(i) & PS2MC_FAT_ALLOCATED_BIT) == 0: free += 1 return free * self.cluster_size @@ -1746,7 +1746,7 @@ def _check_file(self, fat, first_cluster, length): if fat[cluster]: return "cross linked chain" i += 1 - # print cluster, + # print(cluster) fat[cluster] = 1 next = self.lookup_fat(cluster) if next == PS2MC_FAT_CHAIN_END: @@ -1765,7 +1765,7 @@ def _check_dir(self, fat, dirloc, dirname, ent): why = self._check_file(fat, ent[4], ent[2] * PS2MC_DIRENT_LENGTH) if why != None: - print "bad directory:", dirname + ":", why + print("bad directory:", dirname + ":", why) return False ret = True first_cluster = ent[4] @@ -1774,16 +1774,16 @@ def _check_dir(self, fat, dirloc, dirname, ent): "rb", dirname) dot_ent = dir[0] if dot_ent[8] != ".": - print "bad directory:", dirname + ': missing "." entry' + print("bad directory:", dirname + ': missing "." entry') ret = False if (dot_ent[4], dot_ent[5]) != dirloc: - print "bad directory:", dirname + ': bad "." entry' + print("bad directory:", dirname + ': bad "." entry') ret = False if dir[1][8] != "..": - print "bad directory:", (dirname - + ': missing ".." entry') + print("bad directory:", (dirname + + ': missing ".." entry')) ret = False - for i in xrange(2, length): + for i in range(2, length): ent = dir[i] mode = ent[0] if not (mode & DF_EXISTS): @@ -1796,8 +1796,8 @@ def _check_dir(self, fat, dirloc, dirname, ent): else: why = self._check_file(fat, ent[4], ent[2]) if why != None: - print "bad file:", (dirname + ent[8] - + ":"), why + print("bad file:", (dirname + ent[8] + + ":"), why) ret = False dir.close() @@ -1812,7 +1812,7 @@ def check(self): fat_len = int(str(self.allocatable_cluster_end)) if not isinstance(fat_len, int): - raise error, "Memory card image too big to check." + raise error("Memory card image too big to check.") fat = array.array('B', [0]) * fat_len @@ -1821,14 +1821,14 @@ def check(self): ret = self._check_dir(fat, (0, 0), "/", ent) lost_clusters = 0 - for i in xrange(self.allocatable_cluster_end): + for i in range(self.allocatable_cluster_end): a = self.lookup_fat(i) if (a & PS2MC_FAT_ALLOCATED_BIT) and not fat[i]: - print i, + print(i,) lost_clusters += 1 if lost_clusters > 0: - print - print "found", lost_clusters, "lost clusters" + print() + print("found", lost_clusters, "lost clusters") ret = False return ret @@ -1896,7 +1896,7 @@ def glob(self, pattern): ret = self._globdir(dirname, components, isdir) else: ret = self._glob(dirname, components, isdir) - # print pattern, "->", ret + # print(pattern, "->", ret) return ret def get_icon_sys(self, dirname): @@ -1909,8 +1909,8 @@ def get_icon_sys(self, dirname): f = self.open(icon_sys, "rb") s = f.read(964) f.close() - if len(s) == 964 and s[0:4] == "PS2D": - return s; + if len(s) == 964 and s[0:4] == b"PS2D": + return s return None def dir_size(self, dirname): @@ -1946,14 +1946,14 @@ def close(self): access the raw image. After this method has been called on a ps2mc object, it can no longer be used.""" - # print "ps2mc.close" + # print("ps2mc.close") try: f = self.f if f == None or getattr(f, "closed", False): - # print "closed" + # print("closed") return open_files = self.open_files - # print "open_files", open_files + # print("open_files", open_files) if open_files != None: # this is complicated by the fact as # files are closed they will remove @@ -1977,7 +1977,7 @@ def close(self): self.rootdir = None def __del__(self): - # print "ps2mc.__del__" + # print("ps2mc.__del__") try: self.close() except: diff --git a/ps2mc_dir.py b/ps2mc_dir.py index 2ab2c6e..a0aca16 100755 --- a/ps2mc_dir.py +++ b/ps2mc_dir.py @@ -7,11 +7,12 @@ """Functions for working with PS2 memory card directory entries.""" -_SCCS_ID = "@(#) mymc ps2mc_dir.py 1.4 12/10/04 19:11:08\n" +_SCCS_ID = "@(#) mymc ps2mc_dir.py 1.5 23/07/06 06:30:13\n" import struct import time import calendar +import os PS2MC_DIRENT_LENGTH = 512 @@ -36,7 +37,7 @@ def zero_terminate(s): """Truncate a string at the first NUL ('\0') character, if any.""" - i = s.find('\0') + i = s.find(b'\0') if i == -1: return s return s[:i] @@ -67,13 +68,14 @@ def unpack_dirent(s): ent = list(ent) ent[3] = _tod_struct.unpack(ent[3]) ent[6] = _tod_struct.unpack(ent[6]) - ent[8] = zero_terminate(ent[8]) + ent[8] = zero_terminate(ent[8]).decode("utf-8") return ent def pack_dirent(ent): ent = list(ent) ent[3] = _tod_struct.pack(*ent[3]) ent[6] = _tod_struct.pack(*ent[6]) + ent[8] = ent[8].encode("utf-8") return _dirent_struct.pack(*ent) else: def unpack_tod(s): @@ -97,6 +99,7 @@ def pack_dirent(ent): ent = list(ent) ent[3] = struct.pack(_tod_fmt, *ent[3]) ent[6] = struct.pack(_tod_fmt, *ent[6]) + ent[8] = ent[8].encode("utf-8") return struct.pack(_dirent_fmt, *ent) def time_to_tod(when): diff --git a/ps2mc_ecc.py b/ps2mc_ecc.py index 396e4be..1c18a2e 100755 --- a/ps2mc_ecc.py +++ b/ps2mc_ecc.py @@ -10,7 +10,7 @@ correcting codes (ECC), as used on PS2 memory cards. """ -_SCCS_ID = "@(#) mymc ps2mc_ecc.py 1.4 07/12/17 02:34:04\n" +_SCCS_ID = "@(#) mymc ps2mc_ecc.py 1.5 23/07/06 16:03:58\n" import array @@ -64,7 +64,7 @@ def _ecc_calculate(s): if not isinstance(s, array.array): a = array.array('B') - a.fromstring(s) + a.frombytes(s) s = a column_parity = 0x77 line_parity_0 = 0x7F @@ -88,10 +88,10 @@ def _ecc_check(s, ecc): if computed == ecc: return ECC_CHECK_OK - #print + #print() #_print_bin(0, s.tostring()) - #print "computed %02x %02x %02x" % tuple(computed) - #print "actual %02x %02x %02x" % tuple(ecc) + #print("computed %02x %02x %02x" % tuple(computed)) + #print("actual %02x %02x %02x" % tuple(ecc)) # ECC mismatch @@ -101,17 +101,17 @@ def _ecc_check(s, ecc): lp_comp = lp0_diff ^ lp1_diff cp_comp = (cp_diff >> 4) ^ (cp_diff & 0x07) - #print "%02x %02x %02x %02x %02x" % (cp_diff, lp0_diff, lp1_diff, - # lp_comp, cp_comp) + #print("%02x %02x %02x %02x %02x" % (cp_diff, lp0_diff, lp1_diff, + # lp_comp, cp_comp)) if lp_comp == 0x7F and cp_comp == 0x07: - print "corrected 1" + print("corrected 1") # correctable 1 bit error in data s[lp1_diff] ^= 1 << (cp_diff >> 4) return ECC_CHECK_CORRECTED if ((cp_diff == 0 and lp0_diff == 0 and lp1_diff == 0) or _popcount(lp_comp) + _popcount(cp_comp) == 1): - print "corrected 2" + print("corrected 2") # correctable 1 bit error in ECC # (and/or one of the unused bits was set) ecc[0] = computed[0] @@ -140,15 +140,15 @@ def ecc_check_page(page, spare): chunks = [] for i in range(div_round_up(len(page), 128)): a = array.array('B') - a.fromstring(page[i * 128 : i * 128 + 128]) - chunks.append((a, map(ord, spare[i * 3 : i * 3 + 3]))) + a.frombytes(page[i * 128 : i * 128 + 128]) + chunks.append((a, list(spare[i * 3 : i * 3 + 3]))) r = [ecc_check(s, ecc) for (s, ecc) in chunks] ret = ECC_CHECK_OK if ECC_CHECK_CORRECTED in r: # rebuild sector and spare from the corrected versions - page = "".join([a[0].tostring() + page = "".join([a[0].tobytes() for a in chunks]) spare = "".join([chr(a[1][i]) for a in chunks @@ -164,14 +164,14 @@ def ecc_check_page(page, spare): else: # _c_ubyte_p = ctypes.POINTER(ctypes.c_ubyte) def ecc_calculate(s): - aecc = array.array('B', "\0\0\0") + aecc = array.array('B', b"\0\0\0") cecc = ctypes.c_ubyte.from_address(aecc.buffer_info()[0]) mymcsup.ecc_calculate(s, len(s), cecc) return list(aecc) def ecc_check(s, ecc): cs = ctypes.c_ubyte.from_address(s.buffer_info()[0]) - # print "%08X" % s.buffer_info()[0] + # print("%08X" % s.buffer_info()[0]) aecc = array.array('B', ecc) cecc = ctypes.c_ubyte.from_address(aecc.buffer_info()[0]) ret = mymcsup.ecc_check(cs, len(s), cecc) diff --git a/ps2save.py b/ps2save.py index 465de20..f7c3d9c 100755 --- a/ps2save.py +++ b/ps2save.py @@ -7,7 +7,7 @@ # A simple interface for working with various PS2 save file formats. # -_SCCS_ID = "@(#) mymc ps2save.py 1.8 22/01/15 01:25:25\n" +_SCCS_ID = "@(#) mymc ps2save.py 1.9 23/07/06 19:46:30\n" import sys import os @@ -26,10 +26,10 @@ except ImportError: lzari = None -PS2SAVE_MAX_MAGIC = "Ps2PowerSave" -PS2SAVE_SPS_MAGIC = "\x0d\0\0\0SharkPortSave" -PS2SAVE_CBS_MAGIC = "CFU\0" -PS2SAVE_NPO_MAGIC = "nPort" +PS2SAVE_MAX_MAGIC = b"Ps2PowerSave" +PS2SAVE_SPS_MAGIC = b"\x0d\0\0\0SharkPortSave" +PS2SAVE_CBS_MAGIC = b"CFU\0" +PS2SAVE_NPO_MAGIC = b"nPort" # This is the initial permutation state ("S") for the RC4 stream cipher # algorithm used to encrpyt and decrypt Codebreaker saves. @@ -180,8 +180,8 @@ def shift_jis_conv(src, encoding = None): if encoding == "shift_jis": return src u = src.decode("shift_jis", "replace") - if encoding == "unicode": - return u + if encoding == "utf-8": + return u.encode("utf-8") a = [] for uc in u: try: @@ -242,8 +242,9 @@ def icon_sys_title(icon_sys, encoding = None): offset = icon_sys[1] title = icon_sys[14] - title2 = shift_jis_conv(title[offset:], encoding) - title1 = shift_jis_conv(title[:offset], encoding) + encoding = sys.getdefaultencoding() if not encoding else encoding + title2 = shift_jis_conv(title[offset:], encoding).decode(encoding) + title1 = shift_jis_conv(title[:offset], encoding).decode(encoding) return (title1, title2) def _read_fixed(f, n): @@ -251,7 +252,7 @@ def _read_fixed(f, n): s = f.read(n) if len(s) != n: - raise eof, f + raise eof(f) return s def _read_long_string(f): @@ -314,7 +315,7 @@ def load_ems(self, f): or not mode_is_dir(dotent[0]) or not mode_is_dir(dotdotent[0]) or dirent[2] < 2): - raise corrupt, ("Not a EMS (.psu) save file.", f) + raise corrupt("Not a EMS (.psu) save file.", f) dirent[2] -= 2 self.set_directory(dirent) @@ -323,7 +324,7 @@ def load_ems(self, f): ent = unpack_dirent(_read_fixed(f, PS2MC_DIRENT_LENGTH)) if not mode_is_file(ent[0]): - raise subdir, f + raise subdir(f) flen = ent[2] self.set_file(i, ent, _read_fixed(f, flen)) _read_fixed(f, round_up(flen, cluster_size) - flen) @@ -346,11 +347,11 @@ def save_ems(self, f): (ent, data) = self.get_file(i) f.write(pack_dirent(ent)) if not mode_is_file(ent[0]): - # print ent - # print hex(ent[0]) - raise error, "Directory has a subdirectory." + # print(ent) + # print(hex(ent[0])) + raise error("Directory has a subdirectory.") f.write(data) - f.write("\0" * (round_up(len(data), cluster_size) + f.write(b"\0" * (round_up(len(data), cluster_size) - len(data))) f.flush() @@ -359,7 +360,7 @@ def _load_max_drive_2(self): self._compressed = None if lzari == None: - raise error, ("The lzari module is needed to " + raise error("The lzari module is needed to " " decompress MAX Drive saves.") s = lzari.decode(s, length, "decompressing " + self.dirent[8] + ": ") @@ -368,14 +369,14 @@ def _load_max_drive_2(self): off = 0 for i in range(dirlen): if len(s) - off < 36: - raise eof, f + raise eof(self.f) (l, name) = struct.unpack("] \\\"" _bad_filename_repl2 = _bad_filename_repl + "______(())___" -_filename_trans = string.maketrans(_bad_filename_chars, _bad_filename_repl); -_filename_trans2 = string.maketrans(_bad_filename_chars2, _bad_filename_repl2); +_filename_trans = str.maketrans(_bad_filename_chars, _bad_filename_repl); +_filename_trans2 = str.maketrans(_bad_filename_chars2, _bad_filename_repl2); def fix_filename(filename): """Replace illegal or problematic characters from a filename.""" @@ -617,10 +618,10 @@ def make_longname(dirname, sf): title = icon_sys_title(icon_sys, "ascii") title = title[0] + " " + title[1] title = " ".join(title.split()) - crc = binascii.crc32("") + crc = binascii.crc32(b"") for (ent, data) in sf: crc = binascii.crc32(data, crc) - if len(dirname) >= 12 and (dirname[0:2] in ("BA", "BJ", "BE", "BK")): + if len(dirname) >= 12 and (dirname[0:2] in ("BA", "BJ", "BE", "BK")): if dirname[2:6] == "DATA": title = "" else: diff --git a/round.py b/round.py index 1d81ef9..a768ee3 100755 --- a/round.py +++ b/round.py @@ -7,15 +7,15 @@ # Simple rounding functions. # -_SCCS_ID = "@(#) mymc round.py 1.3 07/04/17 02:10:27\n" +_SCCS_ID = "@(#) mymc round.py 1.4 23/07/06 02:44:14\n" def div_round_up(a, b): - return (a + b - 1) / b + return int((a + b - 1) / b) def round_up(a, b): - return (a + b - 1) / b * b + return int((a + b - 1) / b * b) def round_down(a, b): - return a / b * b + return int(a / b * b) diff --git a/verbuild.py b/verbuild.py index 71b2f66..7190414 100755 --- a/verbuild.py +++ b/verbuild.py @@ -1,2 +1,2 @@ -MYMC_VERSION_BUILD = r'''7''' -MYMC_VERSION_MAJOR = r'''2''' +MYMC_VERSION_BUILD = r'''0''' +MYMC_VERSION_MAJOR = r'''3'''