mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2025-01-19 21:32:47 +00:00
Futurize --stage1 changes
This commit is contained in:
parent
6047824405
commit
bddae24cb1
@ -1,3 +1,5 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
import sys
|
||||
import zlib
|
||||
@ -5,22 +7,22 @@ import zlib
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
from _metadata import __version__
|
||||
from ._metadata import __version__
|
||||
|
||||
try:
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
raise RuntimeError("atrcopy %s requires numpy" % __version__)
|
||||
|
||||
from errors import *
|
||||
from ataridos import AtrHeader, AtariDosDiskImage, BootDiskImage, AtariDosFile, XexContainerSegment, get_xex, add_atr_header
|
||||
from dos33 import Dos33DiskImage
|
||||
from kboot import KBootImage, add_xexboot_header
|
||||
from segments import SegmentData, SegmentSaver, DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentedFileSegment, user_bit_mask, match_bit_mask, comment_bit_mask, data_style, selected_bit_mask, diff_bit_mask, not_user_bit_mask, interleave_segments, SegmentList, get_style_mask, get_style_bits
|
||||
from spartados import SpartaDosDiskImage
|
||||
from cartridge import A8CartHeader, AtariCartImage
|
||||
from parsers import SegmentParser, DefaultSegmentParser, guess_parser_for_mime, guess_parser_for_system, iter_parsers, iter_known_segment_parsers, mime_parse_order
|
||||
from utils import to_numpy, text_to_int
|
||||
from .errors import *
|
||||
from .ataridos import AtrHeader, AtariDosDiskImage, BootDiskImage, AtariDosFile, XexContainerSegment, get_xex, add_atr_header
|
||||
from .dos33 import Dos33DiskImage
|
||||
from .kboot import KBootImage, add_xexboot_header
|
||||
from .segments import SegmentData, SegmentSaver, DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentedFileSegment, user_bit_mask, match_bit_mask, comment_bit_mask, data_style, selected_bit_mask, diff_bit_mask, not_user_bit_mask, interleave_segments, SegmentList, get_style_mask, get_style_bits
|
||||
from .spartados import SpartaDosDiskImage
|
||||
from .cartridge import A8CartHeader, AtariCartImage
|
||||
from .parsers import SegmentParser, DefaultSegmentParser, guess_parser_for_mime, guess_parser_for_system, iter_parsers, iter_known_segment_parsers, mime_parse_order
|
||||
from .utils import to_numpy, text_to_int
|
||||
|
||||
|
||||
def process(image, dirent, options):
|
||||
@ -42,38 +44,38 @@ def process(image, dirent, options):
|
||||
action = "DRY_RUN: %s" % action
|
||||
skip = True
|
||||
if options.extract:
|
||||
print "%s: %s %s" % (dirent, action, outfilename)
|
||||
print("%s: %s %s" % (dirent, action, outfilename))
|
||||
if not skip:
|
||||
bytes = image.get_file(dirent)
|
||||
with open(outfilename, "wb") as fh:
|
||||
fh.write(bytes)
|
||||
else:
|
||||
print dirent
|
||||
print(dirent)
|
||||
|
||||
|
||||
def find_diskimage(filename):
|
||||
try:
|
||||
with open(filename, "rb") as fh:
|
||||
if options.verbose:
|
||||
print "Loading file %s" % filename
|
||||
print("Loading file %s" % filename)
|
||||
rawdata = SegmentData(fh.read())
|
||||
parser = None
|
||||
for mime in mime_parse_order:
|
||||
if options.verbose:
|
||||
print "Trying MIME type %s" % mime
|
||||
print("Trying MIME type %s" % mime)
|
||||
parser = guess_parser_for_mime(mime, rawdata, options.verbose)
|
||||
if parser is None:
|
||||
continue
|
||||
if options.verbose:
|
||||
print "Found parser %s" % parser.menu_name
|
||||
print("Found parser %s" % parser.menu_name)
|
||||
break
|
||||
if parser is None:
|
||||
print "%s: Unknown disk image type" % filename
|
||||
except UnsupportedDiskImage, e:
|
||||
print "%s: %s" % (filename, e)
|
||||
print("%s: Unknown disk image type" % filename)
|
||||
except UnsupportedDiskImage as e:
|
||||
print("%s: %s" % (filename, e))
|
||||
return None
|
||||
except IOError, e:
|
||||
print "%s: %s" % (filename, e)
|
||||
except IOError as e:
|
||||
print("%s: %s" % (filename, e))
|
||||
return None
|
||||
else:
|
||||
parser.image.filename = filename
|
||||
@ -88,7 +90,7 @@ def extract_files(image, files):
|
||||
try:
|
||||
dirent = image.find_dirent(name)
|
||||
except FileNotFound:
|
||||
print "%s not in %s" % (name, image)
|
||||
print("%s not in %s" % (name, image))
|
||||
continue
|
||||
output = dirent.filename
|
||||
if options.lower:
|
||||
@ -96,13 +98,13 @@ def extract_files(image, files):
|
||||
if not options.dry_run:
|
||||
data = image.get_file(dirent)
|
||||
if os.path.exists(output) and not options.force:
|
||||
print "skipping %s, file exists. Use -f to overwrite" % output
|
||||
print("skipping %s, file exists. Use -f to overwrite" % output)
|
||||
continue
|
||||
print "extracting %s -> %s" % (name, output)
|
||||
print("extracting %s -> %s" % (name, output))
|
||||
with open(output, "wb") as fh:
|
||||
fh.write(data)
|
||||
else:
|
||||
print "extracting %s -> %s" % (name, output)
|
||||
print("extracting %s -> %s" % (name, output))
|
||||
|
||||
|
||||
def save_file(image, name, filetype, data):
|
||||
@ -111,11 +113,11 @@ def save_file(image, name, filetype, data):
|
||||
if options.force:
|
||||
image.delete_file(name)
|
||||
else:
|
||||
print "skipping %s, use -f to overwrite" % (name)
|
||||
print("skipping %s, use -f to overwrite" % (name))
|
||||
return False
|
||||
except FileNotFound:
|
||||
pass
|
||||
print "copying %s to %s" % (name, image.filename)
|
||||
print("copying %s to %s" % (name, image.filename))
|
||||
if not options.dry_run:
|
||||
image.write_file(name, filetype, data)
|
||||
return True
|
||||
@ -141,9 +143,9 @@ def remove_files(image, files):
|
||||
try:
|
||||
dirent = image.find_dirent(name)
|
||||
except FileNotFound:
|
||||
print "%s not in %s" % (name, image)
|
||||
print("%s not in %s" % (name, image))
|
||||
continue
|
||||
print "removing %s from %s" % (name, image)
|
||||
print("removing %s from %s" % (name, image))
|
||||
if not options.dry_run:
|
||||
image.delete_file(name)
|
||||
changed = True
|
||||
@ -163,7 +165,7 @@ def list_files(image, files, show_crc=False, show_metadata=False):
|
||||
extra = ""
|
||||
print("%s%s" % (dirent, extra))
|
||||
if show_metadata:
|
||||
print dirent.extra_metadata(image)
|
||||
print(dirent.extra_metadata(image))
|
||||
|
||||
|
||||
def crc_files(image, files):
|
||||
@ -186,20 +188,20 @@ def assemble(image, source_files, data_files, obj_files, run_addr=""):
|
||||
for name in source_files:
|
||||
try:
|
||||
asm = pyatasm.Assemble(name)
|
||||
except SyntaxError, e:
|
||||
except SyntaxError as e:
|
||||
raise AtrError("Assembly error: %s" % e.msg)
|
||||
log.debug("Assembled %s into:" % name)
|
||||
for first, last, object_code in asm.segments:
|
||||
s = segments.add_segment(object_code, first)
|
||||
log.debug(" %s" % s.name)
|
||||
print "adding %s from %s assembly" % (s, name)
|
||||
print("adding %s from %s assembly" % (s, name))
|
||||
for name in data_files:
|
||||
if "@" not in name:
|
||||
raise AtrError("Data files must include a load address specified with the @ char")
|
||||
name, addr = name.rsplit("@", 1)
|
||||
first = text_to_int(addr)
|
||||
log.debug("Adding data file %s at $%04x" % (name, first))
|
||||
subset = slice(0, sys.maxint)
|
||||
subset = slice(0, sys.maxsize)
|
||||
if "[" in name and "]" in name:
|
||||
name, slicetext = name.rsplit("[", 1)
|
||||
if ":" in slicetext:
|
||||
@ -224,11 +226,11 @@ def assemble(image, source_files, data_files, obj_files, run_addr=""):
|
||||
if parser and parser.image:
|
||||
for s in parser.segments:
|
||||
if s.start_addr > 0:
|
||||
print "adding %s from %s" % (s, name)
|
||||
print("adding %s from %s" % (s, name))
|
||||
segments.add_segment(s.data, s.start_addr)
|
||||
if options.verbose:
|
||||
for s in segments:
|
||||
print "%s - %04x)" % (str(s)[:-1], s.start_addr + len(s))
|
||||
print("%s - %04x)" % (str(s)[:-1], s.start_addr + len(s)))
|
||||
if run_addr:
|
||||
try:
|
||||
run_addr = text_to_int(run_addr)
|
||||
@ -236,14 +238,14 @@ def assemble(image, source_files, data_files, obj_files, run_addr=""):
|
||||
run_addr = None
|
||||
|
||||
file_data, filetype = image.create_executable_file_image(segments, run_addr)
|
||||
print "total file size: $%x (%d) bytes" % (len(file_data), len(file_data))
|
||||
print("total file size: $%x (%d) bytes" % (len(file_data), len(file_data)))
|
||||
changed = save_file(image, options.output, filetype, file_data)
|
||||
if changed:
|
||||
image.save()
|
||||
|
||||
|
||||
def shred_image(image, value=0):
|
||||
print "shredding: free sectors from %s filled with %d" % (image, value)
|
||||
print("shredding: free sectors from %s filled with %d" % (image, value))
|
||||
if not options.dry_run:
|
||||
image.shred()
|
||||
image.save()
|
||||
@ -266,7 +268,7 @@ def get_template_path(rel_path="templates"):
|
||||
zippath, template_path = template_path.split(".zip/")
|
||||
template_path = os.path.normpath(os.path.join(root, template_path))
|
||||
else:
|
||||
print "App packager %s not yet supported for image paths!!!"
|
||||
print("App packager %s not yet supported for image paths!!!")
|
||||
return template_path
|
||||
|
||||
|
||||
@ -313,18 +315,18 @@ def create_image(template, name):
|
||||
import textwrap
|
||||
|
||||
data, inf = get_template_data(template)
|
||||
print "using %s template:\n %s" % (template, "\n ".join(textwrap.wrap(inf, 77)))
|
||||
print("using %s template:\n %s" % (template, "\n ".join(textwrap.wrap(inf, 77))))
|
||||
if not options.dry_run:
|
||||
if os.path.exists(name) and not options.force:
|
||||
print "skipping %s, use -f to overwrite" % (name)
|
||||
print("skipping %s, use -f to overwrite" % (name))
|
||||
else:
|
||||
with open(name, "wb") as fh:
|
||||
fh.write(data)
|
||||
parser = find_diskimage(name)
|
||||
print "created %s: %s" % (name, str(parser.image))
|
||||
print("created %s: %s" % (name, str(parser.image)))
|
||||
list_files(parser.image, [])
|
||||
else:
|
||||
print "creating %s" % name
|
||||
print("creating %s" % name)
|
||||
|
||||
|
||||
def run():
|
||||
@ -512,10 +514,10 @@ def run():
|
||||
parser = find_diskimage(disk_image_name)
|
||||
if parser and parser.image:
|
||||
if command not in skip_diskimage_summary:
|
||||
print "%s: %s" % (disk_image_name, parser.image)
|
||||
print("%s: %s" % (disk_image_name, parser.image))
|
||||
if command == "vtoc":
|
||||
vtoc = parser.image.get_vtoc_object()
|
||||
print vtoc
|
||||
print(vtoc)
|
||||
if options.clear_empty:
|
||||
shred_image(parser.image)
|
||||
elif command == "list":
|
||||
@ -534,6 +536,6 @@ def run():
|
||||
obj = options.obj[0] if options.obj else []
|
||||
assemble(parser.image, asm, data, obj, options.run_addr)
|
||||
elif command == "segments":
|
||||
print "\n".join([str(a) for a in parser.segments])
|
||||
print("\n".join([str(a) for a in parser.segments]))
|
||||
else:
|
||||
log.error("Invalid disk image: %s" % disk_image_name)
|
||||
|
@ -1,9 +1,10 @@
|
||||
from __future__ import absolute_import
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from diskimages import DiskImageBase, BaseHeader
|
||||
from segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment, DefaultSegment, SegmentedFileSegment, SegmentSaver, get_style_bits
|
||||
from utils import *
|
||||
from .errors import *
|
||||
from .diskimages import DiskImageBase, BaseHeader
|
||||
from .segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment, DefaultSegment, SegmentedFileSegment, SegmentSaver, get_style_bits
|
||||
from .utils import *
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -1,11 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
from collections import defaultdict
|
||||
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from segments import SegmentData, EmptySegment, ObjSegment
|
||||
from diskimages import DiskImageBase
|
||||
from utils import to_numpy
|
||||
from .errors import *
|
||||
from .segments import SegmentData, EmptySegment, ObjSegment
|
||||
from .diskimages import DiskImageBase
|
||||
from .utils import to_numpy
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -1,8 +1,9 @@
|
||||
from __future__ import absolute_import
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment
|
||||
from utils import *
|
||||
from .errors import *
|
||||
from .segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment
|
||||
from .utils import *
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@ -290,7 +291,7 @@ class DiskImageBase(object):
|
||||
for dirent in self.files:
|
||||
try:
|
||||
segment = self.get_file_segment(dirent)
|
||||
except InvalidFile, e:
|
||||
except InvalidFile as e:
|
||||
segment = EmptySegment(self.rawdata, name=dirent.filename, error=str(e))
|
||||
segments.append(segment)
|
||||
return segments
|
||||
|
@ -1,9 +1,11 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from diskimages import BaseHeader, DiskImageBase
|
||||
from utils import Directory, VTOC, WriteableSector, BaseSectorList, Dirent
|
||||
from segments import DefaultSegment, EmptySegment, ObjSegment, RawTrackSectorSegment, SegmentSaver, get_style_bits, SegmentData
|
||||
from .errors import *
|
||||
from .diskimages import BaseHeader, DiskImageBase
|
||||
from .utils import Directory, VTOC, WriteableSector, BaseSectorList, Dirent
|
||||
from .segments import DefaultSegment, EmptySegment, ObjSegment, RawTrackSectorSegment, SegmentSaver, get_style_bits, SegmentData
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@ -624,7 +626,7 @@ class Dos33DiskImage(DiskImageBase):
|
||||
words[1] = size
|
||||
for s in all_segments:
|
||||
index = s.start_addr - origin + 4
|
||||
print "setting data for $%04x - $%04x at index $%04x" % (s.start_addr, s.start_addr + len(s), index)
|
||||
print("setting data for $%04x - $%04x at index $%04x" % (s.start_addr, s.start_addr + len(s), index))
|
||||
image[index:index + len(s)] = s.data
|
||||
return image, 'B'
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
from __future__ import absolute_import
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment
|
||||
from .errors import *
|
||||
from .ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment
|
||||
|
||||
|
||||
class KBootDirent(AtariDosDirent):
|
||||
|
@ -1,11 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
import zipfile
|
||||
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from segments import SegmentData, EmptySegment, ObjSegment
|
||||
from diskimages import DiskImageBase
|
||||
from utils import to_numpy
|
||||
from .errors import *
|
||||
from .segments import SegmentData, EmptySegment, ObjSegment
|
||||
from .diskimages import DiskImageBase
|
||||
from .utils import to_numpy
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -1,13 +1,14 @@
|
||||
from __future__ import absolute_import
|
||||
import numpy as np
|
||||
|
||||
from segments import SegmentData, DefaultSegment
|
||||
from kboot import KBootImage
|
||||
from ataridos import AtariDosDiskImage, BootDiskImage, AtariDosFile, XexContainerSegment
|
||||
from spartados import SpartaDosDiskImage
|
||||
from cartridge import AtariCartImage, get_known_carts
|
||||
from mame import MameZipImage
|
||||
from dos33 import Dos33DiskImage, ProdosDiskImage, Dos33BinFile
|
||||
from errors import *
|
||||
from .segments import SegmentData, DefaultSegment
|
||||
from .kboot import KBootImage
|
||||
from .ataridos import AtariDosDiskImage, BootDiskImage, AtariDosFile, XexContainerSegment
|
||||
from .spartados import SpartaDosDiskImage
|
||||
from .cartridge import AtariCartImage, get_known_carts
|
||||
from .mame import MameZipImage
|
||||
from .dos33 import Dos33DiskImage, ProdosDiskImage, Dos33BinFile
|
||||
from .errors import *
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@ -60,7 +61,7 @@ class SegmentParser(object):
|
||||
self.image.parse_segments()
|
||||
except UnsupportedDiskImage:
|
||||
raise
|
||||
except AtrError, e:
|
||||
except AtrError as e:
|
||||
raise InvalidSegmentParser(e)
|
||||
self.segments.extend(self.image.segments)
|
||||
|
||||
@ -71,7 +72,7 @@ class SegmentParser(object):
|
||||
if self.strict:
|
||||
try:
|
||||
self.image.strict_check()
|
||||
except AtrError, e:
|
||||
except AtrError as e:
|
||||
raise InvalidSegmentParser(e)
|
||||
else:
|
||||
self.image.relaxed_check()
|
||||
@ -147,7 +148,7 @@ def guess_parser_for_mime(mime, r, verbose=False):
|
||||
try:
|
||||
found = parser(r, True)
|
||||
break
|
||||
except InvalidSegmentParser, e:
|
||||
except InvalidSegmentParser as e:
|
||||
if verbose:
|
||||
log.info("parser isn't %s: %s" % (parser.__name__, str(e)))
|
||||
pass
|
||||
|
@ -1,11 +1,14 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
import bisect
|
||||
import cStringIO
|
||||
import uuid
|
||||
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from utils import to_numpy, to_numpy_list
|
||||
from .errors import *
|
||||
from .utils import to_numpy, to_numpy_list
|
||||
from functools import reduce
|
||||
|
||||
user_bit_mask = 0x07
|
||||
data_style = 0x1
|
||||
@ -1007,11 +1010,11 @@ class DefaultSegment(object):
|
||||
def compare_segment(self, other_segment):
|
||||
self.clear_style_bits(diff=True)
|
||||
diff = self.rawdata.data != other_segment.rawdata.data
|
||||
print diff, diff.dtype
|
||||
print(diff, diff.dtype)
|
||||
d = diff * np.uint8(diff_bit_mask)
|
||||
print d
|
||||
print(d)
|
||||
self.style |= (diff * np.uint8(diff_bit_mask))
|
||||
print "# entries", len(diff), "# diffs:", len(np.where(diff == True)[0])
|
||||
print("# entries", len(diff), "# diffs:", len(np.where(diff == True)[0]))
|
||||
|
||||
|
||||
class EmptySegment(DefaultSegment):
|
||||
|
@ -1,8 +1,9 @@
|
||||
from __future__ import absolute_import
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment
|
||||
from segments import DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentSaver
|
||||
from .errors import *
|
||||
from .ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment
|
||||
from .segments import DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentSaver
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -1,8 +1,9 @@
|
||||
from __future__ import absolute_import
|
||||
import types
|
||||
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from .errors import *
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@ -15,9 +16,9 @@ except NameError:
|
||||
def to_numpy(value):
|
||||
if type(value) is np.ndarray:
|
||||
return value
|
||||
elif type(value) is types.StringType:
|
||||
elif type(value) is bytes:
|
||||
return np.fromstring(value, dtype=np.uint8)
|
||||
elif type(value) is types.ListType:
|
||||
elif type(value) is list:
|
||||
return np.asarray(value, dtype=np.uint8)
|
||||
raise TypeError("Can't convert to numpy data")
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import numpy as np
|
||||
|
||||
from mock import *
|
||||
@ -161,7 +162,7 @@ class TestDos33Image(BaseFilesystemModifyTest):
|
||||
if __name__ == "__main__":
|
||||
t = TestAtariDosSDImage()
|
||||
for name in dir(t):
|
||||
print name
|
||||
print(name)
|
||||
if name.startswith("test_"):
|
||||
t.setup()
|
||||
getattr(t, name)()
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
from mock import *
|
||||
|
||||
from atrcopy import SegmentData, AtariDosFile, InvalidBinaryFile, DefaultSegment, XexContainerSegment
|
||||
@ -13,7 +14,7 @@ class TestAtariDosFile(object):
|
||||
container = XexContainerSegment(rawdata, 0)
|
||||
image = AtariDosFile(container.rawdata)
|
||||
image.parse_segments()
|
||||
print image.segments
|
||||
print(image.segments)
|
||||
assert len(image.segments) == 1
|
||||
assert len(image.segments[0]) == 2
|
||||
assert np.all(image.segments[0] == bytes[6:8])
|
||||
@ -23,7 +24,7 @@ class TestAtariDosFile(object):
|
||||
new_segment = DefaultSegment(rawdata[8:16])
|
||||
new_segment[:] = 99
|
||||
assert np.all(image.segments[0] == bytes[6:8])
|
||||
print new_segment[:]
|
||||
print(new_segment[:])
|
||||
assert np.all(new_segment[:] == 99)
|
||||
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
from mock import *
|
||||
|
||||
from atrcopy import AtariCartImage, SegmentData, InvalidDiskImage
|
||||
@ -73,7 +74,7 @@ class TestAtariCart(object):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print "\n".join(mime_parse_order)
|
||||
print("\n".join(mime_parse_order))
|
||||
|
||||
t = TestAtariCart()
|
||||
t.setup()
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import numpy as np
|
||||
|
||||
from mock import *
|
||||
@ -42,8 +43,8 @@ class BaseCreateTest(object):
|
||||
file_data, filetype = image.create_executable_file_image(segments, run_addr)
|
||||
except TypeError:
|
||||
file_data, filetype = image.create_executable_file_image(segments, run_addr)
|
||||
print image
|
||||
print file_data, filetype
|
||||
print(image)
|
||||
print(file_data, filetype)
|
||||
assert len(file_data) == expected
|
||||
|
||||
@pytest.mark.parametrize("sample_file", ["../test_data/dos_sd_test1.atr"])
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import os
|
||||
|
||||
import pytest
|
||||
@ -14,33 +15,33 @@ class TestJsonPickle(object):
|
||||
self.segment = DefaultSegment(SegmentData(data))
|
||||
|
||||
def test_simple(self):
|
||||
print self.segment.byte_bounds_offset(), len(self.segment)
|
||||
print(self.segment.byte_bounds_offset(), len(self.segment))
|
||||
r2 = self.segment.rawdata[100:400]
|
||||
s2 = DefaultSegment(r2)
|
||||
print s2.byte_bounds_offset(), len(s2), s2.__getstate__()
|
||||
print(s2.byte_bounds_offset(), len(s2), s2.__getstate__())
|
||||
r3 = s2.rawdata[100:200]
|
||||
s3 = DefaultSegment(r3)
|
||||
print s3.byte_bounds_offset(), len(s3), s3.__getstate__()
|
||||
print(s3.byte_bounds_offset(), len(s3), s3.__getstate__())
|
||||
order = list(reversed(range(700, 800)))
|
||||
r4 = self.segment.rawdata.get_indexed(order)
|
||||
s4 = DefaultSegment(r4)
|
||||
print s4.byte_bounds_offset(), len(s4), s4.__getstate__()
|
||||
print(s4.byte_bounds_offset(), len(s4), s4.__getstate__())
|
||||
|
||||
slist = [s2, s3, s4]
|
||||
for s in slist:
|
||||
print s
|
||||
print(s)
|
||||
j = jsonpickle.dumps(slist)
|
||||
print j
|
||||
print(j)
|
||||
|
||||
slist2 = jsonpickle.loads(j)
|
||||
print slist2
|
||||
print(slist2)
|
||||
for s in slist2:
|
||||
s.reconstruct_raw(self.segment.rawdata)
|
||||
print s
|
||||
print(s)
|
||||
|
||||
for orig, rebuilt in zip(slist, slist2):
|
||||
print "orig", orig.data[:]
|
||||
print "rebuilt", rebuilt.data[:]
|
||||
print("orig", orig.data[:])
|
||||
print("rebuilt", rebuilt.data[:])
|
||||
assert np.array_equal(orig[:], rebuilt[:])
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
@ -21,9 +22,9 @@ class TestKbootHeader(object):
|
||||
rawdata = SegmentData(bytes)
|
||||
newatr = KBootImage(rawdata)
|
||||
image = newatr.bytes
|
||||
print image[0:16]
|
||||
print(image[0:16])
|
||||
paragraphs = image_size / 16
|
||||
print newatr.header, paragraphs
|
||||
print(newatr.header, paragraphs)
|
||||
assert int(image[2:4].view(dtype='<u2')) == paragraphs
|
||||
assert int(image[16 + 9:16 + 9 + 2].view('<u2')) == xex_size
|
||||
return image
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
@ -5,6 +6,7 @@ import pytest
|
||||
|
||||
from atrcopy import DefaultSegment, SegmentData, get_xex, interleave_segments, user_bit_mask, diff_bit_mask
|
||||
from atrcopy.errors import *
|
||||
from functools import reduce
|
||||
|
||||
|
||||
def get_indexed(segment, num, scale):
|
||||
@ -32,7 +34,7 @@ class TestSegment1(object):
|
||||
s[1].set_comment_at(0, "comment 0")
|
||||
s[1].set_comment_at(10, "comment 10")
|
||||
s[1].set_comment_at(100, "comment 100")
|
||||
print list(s[1].iter_comments_in_segment())
|
||||
print(list(s[1].iter_comments_in_segment()))
|
||||
with pytest.raises(InvalidBinaryFile):
|
||||
seg, subseg = get_xex(s, 0xbeef)
|
||||
seg, subseg = get_xex(s)
|
||||
@ -42,8 +44,8 @@ class TestSegment1(object):
|
||||
# An extra segment has been inserted for the run address!
|
||||
size = reduce(lambda a, b:a + len(b), subseg, 0)
|
||||
assert len(seg) == 2 + size
|
||||
print id(s[1]), list(s[1].iter_comments_in_segment())
|
||||
print id(subseg[2]), list(subseg[2].iter_comments_in_segment())
|
||||
print(id(s[1]), list(s[1].iter_comments_in_segment()))
|
||||
print(id(subseg[2]), list(subseg[2].iter_comments_in_segment()))
|
||||
for i, c in s[1].iter_comments_in_segment():
|
||||
assert c == subseg[2].get_comment(i + 4)
|
||||
assert np.all(s[1].style[:] == subseg[2].style[4:])
|
||||
@ -51,15 +53,15 @@ class TestSegment1(object):
|
||||
def test_copy(self):
|
||||
for s in self.segments:
|
||||
d = s.rawdata
|
||||
print "orig:", d.data.shape, d.is_indexed, d.data, id(d.data)
|
||||
print("orig:", d.data.shape, d.is_indexed, d.data, id(d.data))
|
||||
c = d.copy()
|
||||
print "copy", c.data.shape, c.is_indexed, c.data, id(c.data)
|
||||
print("copy", c.data.shape, c.is_indexed, c.data, id(c.data))
|
||||
assert c.data.shape == s.data.shape
|
||||
assert id(c) != id(s)
|
||||
assert np.all((c.data[:] - s.data[:]) == 0)
|
||||
c.data[0:100] = 1
|
||||
print d.data
|
||||
print c.data
|
||||
print(d.data)
|
||||
print(c.data)
|
||||
assert not np.all((c.data[:] - s.data[:]) == 0)
|
||||
|
||||
|
||||
@ -104,13 +106,13 @@ class TestIndexed(object):
|
||||
|
||||
# try with elements up to 256 * 3
|
||||
s, indexes = get_indexed(sub, 256, 3)
|
||||
print sub.data
|
||||
print indexes
|
||||
print s.data[:]
|
||||
print(sub.data)
|
||||
print(indexes)
|
||||
print(s.data[:])
|
||||
assert s.rawdata.is_indexed
|
||||
for i in range(len(indexes)):
|
||||
ri = s.get_raw_index(i)
|
||||
print ri, "base[ri]=%d" % base[ri], i, indexes[i], "s[i]=%d" % s[i]
|
||||
print(ri, "base[ri]=%d" % base[ri], i, indexes[i], "s[i]=%d" % s[i])
|
||||
assert ri == sub.start_addr + indexes[i]
|
||||
assert s[i] == base[ri]
|
||||
start, end = s.byte_bounds_offset()
|
||||
@ -147,9 +149,9 @@ class TestIndexed(object):
|
||||
a[1::4] = s1[1::2]
|
||||
a[2::4] = s2[0::2]
|
||||
a[3::4] = s2[1::2]
|
||||
print list(s[:])
|
||||
print list(a[:])
|
||||
print s.rawdata.order
|
||||
print(list(s[:]))
|
||||
print(list(a[:]))
|
||||
print(s.rawdata.order)
|
||||
assert np.array_equal(s[:], a)
|
||||
|
||||
s = interleave_segments([s1, s2], 4)
|
||||
@ -184,8 +186,8 @@ class TestIndexed(object):
|
||||
def test_copy(self):
|
||||
s, indexes = get_indexed(self.segment, 1024, 3)
|
||||
c = s.rawdata.copy()
|
||||
print c.data.shape, c.is_indexed
|
||||
print id(c.data.np_data), id(s.data.np_data)
|
||||
print(c.data.shape, c.is_indexed)
|
||||
print(id(c.data.np_data), id(s.data.np_data))
|
||||
assert c.data.shape == s.data.shape
|
||||
assert id(c) != id(s)
|
||||
assert np.all((c.data[:] - s.data[:]) == 0)
|
||||
@ -220,9 +222,9 @@ class TestComments(object):
|
||||
s.set_user_data([r], 4, 99)
|
||||
|
||||
s2 = self.sub_segment
|
||||
print len(s2)
|
||||
print(len(s2))
|
||||
copy = s2.get_comment_locations()
|
||||
print copy
|
||||
print(copy)
|
||||
# comments at 4 and 40 in the original means 2 and 38 in the copy
|
||||
orig = s.get_comment_locations()
|
||||
assert copy[2] == orig[4]
|
||||
@ -235,17 +237,17 @@ class TestComments(object):
|
||||
s.set_comment([[i,i+1]], "comment at %d" % i)
|
||||
|
||||
s2 = self.sub_segment
|
||||
print len(s2)
|
||||
print(len(s2))
|
||||
copy = s2.get_comment_locations()
|
||||
print copy
|
||||
print(copy)
|
||||
# comments at 4 and 40 in the original means 2 and 38 in the copy
|
||||
orig = s.get_comment_locations()
|
||||
print orig[0:200]
|
||||
print(orig[0:200])
|
||||
assert copy[2] == orig[4]
|
||||
assert copy[28] == orig[38]
|
||||
|
||||
r = s2.get_entire_style_ranges([1], user=True)
|
||||
print r
|
||||
print(r)
|
||||
assert r == [((0, 23), 1), ((23, 48), 1), ((48, 73), 1), ((73, 98), 1), ((98, 123), 1), ((123, 148), 1), ((148, 173), 1), ((173, 198), 1), ((198, 200), 1)]
|
||||
|
||||
def test_split_data_at_comment2(self):
|
||||
@ -260,17 +262,17 @@ class TestComments(object):
|
||||
s.set_comment([[i,i+1]], "comment at %d" % i)
|
||||
|
||||
s2 = self.sub_segment
|
||||
print len(s2)
|
||||
print(len(s2))
|
||||
copy = s2.get_comment_locations()
|
||||
print copy
|
||||
print(copy)
|
||||
# comments at 4 and 40 in the original means 2 and 38 in the copy
|
||||
orig = s.get_comment_locations()
|
||||
print orig[0:200]
|
||||
print(orig[0:200])
|
||||
assert copy[2] == orig[4]
|
||||
assert copy[28] == orig[38]
|
||||
|
||||
r = s2.get_entire_style_ranges([1], user=user_bit_mask)
|
||||
print r
|
||||
print(r)
|
||||
assert r == [((0, 38), 0), ((38, 48), 1), ((48, 73), 1), ((73, 78), 1), ((78, 118), 2), ((118, 158), 3), ((158, 198), 4), ((198, 200), 5)]
|
||||
|
||||
def test_restore_comments(self):
|
||||
@ -280,64 +282,64 @@ class TestComments(object):
|
||||
s.set_comment([[i,i+1]], "comment at %d" % i)
|
||||
|
||||
s1 = self.segment
|
||||
print len(s1)
|
||||
print(len(s1))
|
||||
indexes = [7,12]
|
||||
r = s1.get_comment_restore_data([indexes])
|
||||
print r
|
||||
print(r)
|
||||
# force clear comments
|
||||
s1.rawdata.extra.comments = {}
|
||||
s1.style[indexes[0]:indexes[1]] = 0
|
||||
r0 = s1.get_comment_restore_data([indexes])
|
||||
print r0
|
||||
print(r0)
|
||||
for start, end, style, items in r0:
|
||||
print style
|
||||
print(style)
|
||||
assert np.all(style == 0)
|
||||
for rawindex, comment in items.values():
|
||||
assert not comment
|
||||
s1.restore_comments(r)
|
||||
r1 = s1.get_comment_restore_data([indexes])
|
||||
print r1
|
||||
print(r1)
|
||||
for item1, item2 in zip(r, r1):
|
||||
print item1
|
||||
print item2
|
||||
print(item1)
|
||||
print(item2)
|
||||
for a1, a2 in zip(item1, item2):
|
||||
print a1, a2
|
||||
print(a1, a2)
|
||||
if hasattr(a1, "shape"):
|
||||
assert np.all(a1 - a2 == 0)
|
||||
else:
|
||||
assert a1 == a2
|
||||
|
||||
s2 = self.sub_segment
|
||||
print len(s2)
|
||||
print(len(s2))
|
||||
indexes = [5,10]
|
||||
r = s2.get_comment_restore_data([indexes])
|
||||
print r
|
||||
print(r)
|
||||
# force clear comments
|
||||
s2.rawdata.extra.comments = {}
|
||||
s2.style[indexes[0]:indexes[1]] = 0
|
||||
r0 = s2.get_comment_restore_data([indexes])
|
||||
print r0
|
||||
print(r0)
|
||||
for start, end, style, items in r0:
|
||||
print style
|
||||
print(style)
|
||||
assert np.all(style == 0)
|
||||
for rawindex, comment in items.values():
|
||||
assert not comment
|
||||
s2.restore_comments(r)
|
||||
r2 = s2.get_comment_restore_data([indexes])
|
||||
print r2
|
||||
print(r2)
|
||||
for item1, item2 in zip(r, r2):
|
||||
print item1
|
||||
print item2
|
||||
print(item1)
|
||||
print(item2)
|
||||
for a1, a2 in zip(item1, item2):
|
||||
print a1, a2
|
||||
print(a1, a2)
|
||||
if hasattr(a1, "shape"):
|
||||
assert np.all(a1 - a2 == 0)
|
||||
else:
|
||||
assert a1 == a2
|
||||
|
||||
for item1, item2 in zip(r1, r2):
|
||||
print item1
|
||||
print item2
|
||||
print(item1)
|
||||
print(item2)
|
||||
# indexes won't be the same, but rawindexes and comments will
|
||||
assert np.all(item1[2] - item2[2] == 0)
|
||||
assert set(item1[3].values()) == set(item2[3].values())
|
||||
@ -381,11 +383,11 @@ class TestResize(object):
|
||||
# pointing to the same array in memory
|
||||
newbase = c.rawdata
|
||||
newsub = s.rawdata
|
||||
print c.rawdata.data[offset:offset+offset]
|
||||
print s.rawdata.data[:]
|
||||
print(c.rawdata.data[offset:offset+offset])
|
||||
print(s.rawdata.data[:])
|
||||
s.rawdata.data[:] = 111
|
||||
print c.rawdata.data[offset:offset+offset]
|
||||
print s.rawdata.data[:]
|
||||
print(c.rawdata.data[offset:offset+offset])
|
||||
print(s.rawdata.data[:])
|
||||
for i in range(offset):
|
||||
assert s[i] == c[i + offset]
|
||||
|
||||
@ -408,11 +410,11 @@ class TestResize(object):
|
||||
assert s.get_raw_index(i) == indexes[i]
|
||||
newbase = c.rawdata
|
||||
newsub = s.rawdata
|
||||
print c.rawdata.data
|
||||
print s.rawdata.data[:]
|
||||
print(c.rawdata.data)
|
||||
print(s.rawdata.data[:])
|
||||
s.rawdata.data[:] = 111
|
||||
print c.rawdata.data
|
||||
print s.rawdata.data[:]
|
||||
print(c.rawdata.data)
|
||||
print(s.rawdata.data[:])
|
||||
for i in range(len(indexes)):
|
||||
assert c.rawdata.data[indexes[i]] == s.rawdata.data[i]
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
@ -33,7 +34,7 @@ class TestSegment(object):
|
||||
|
||||
out = dict()
|
||||
s.serialize_extra_to_dict(out)
|
||||
print "saved", out
|
||||
print("saved", out)
|
||||
|
||||
data = np.ones([4000], dtype=np.uint8)
|
||||
r = SegmentData(data)
|
||||
@ -41,7 +42,7 @@ class TestSegment(object):
|
||||
s2.restore_extra_from_dict(out)
|
||||
out2 = dict()
|
||||
s2.serialize_extra_to_dict(out2)
|
||||
print "loaded", out2
|
||||
print("loaded", out2)
|
||||
assert out == out2
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user