mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2024-12-27 23:32:06 +00:00
Merge branch 'py3'
This commit is contained in:
commit
baa2090565
@ -1,3 +1,6 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from builtins import str
|
||||
import os
|
||||
import sys
|
||||
import zlib
|
||||
@ -5,22 +8,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 +45,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 +91,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 +99,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 +114,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 +144,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 +166,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 +189,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 +227,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 +239,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 +269,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 +316,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():
|
||||
@ -377,7 +380,7 @@ def run():
|
||||
}
|
||||
# reverse aliases does the inverse mapping of command aliases, including
|
||||
# the identity mapping of "command" to "command"
|
||||
reverse_aliases = {z: k for k, v in command_aliases.iteritems() for z in (v + [k])}
|
||||
reverse_aliases = {z: k for k, v in command_aliases.items() for z in (v + [k])}
|
||||
|
||||
skip_diskimage_summary = set(["crc"])
|
||||
|
||||
@ -512,10 +515,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 +537,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,14 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
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__)
|
||||
@ -88,8 +93,8 @@ class AtariDosDirent(Dirent):
|
||||
self.deleted = False
|
||||
self.num_sectors = 0
|
||||
self.starting_sector = 0
|
||||
self.basename = ""
|
||||
self.ext = ""
|
||||
self.basename = b''
|
||||
self.ext = b''
|
||||
self.is_sane = True
|
||||
self.current_sector = 0
|
||||
self.current_read = 0
|
||||
@ -97,14 +102,14 @@ class AtariDosDirent(Dirent):
|
||||
self.parse_raw_dirent(image, bytes)
|
||||
|
||||
def __str__(self):
|
||||
return "File #%-2d (%s) %03d %-8s%-3s %03d" % (self.file_num, self.summary, self.starting_sector, self.basename, self.ext, self.num_sectors)
|
||||
return "File #%-2d (%s) %03d %-8s%-3s %03d" % (self.file_num, self.summary, self.starting_sector, str(self.basename), str(self.ext), self.num_sectors)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__class__ == other.__class__ and self.filename == other.filename and self.starting_sector == other.starting_sector and self.num_sectors == other.num_sectors
|
||||
|
||||
@property
|
||||
def filename(self):
|
||||
ext = ("." + self.ext) if self.ext else ""
|
||||
ext = (b'.' + self.ext) if self.ext else b''
|
||||
return self.basename + ext
|
||||
|
||||
@property
|
||||
@ -132,10 +137,10 @@ class AtariDosDirent(Dirent):
|
||||
def extra_metadata(self, image):
|
||||
return self.verbose_info
|
||||
|
||||
def parse_raw_dirent(self, image, bytes):
|
||||
if bytes is None:
|
||||
def parse_raw_dirent(self, image, data):
|
||||
if data is None:
|
||||
return
|
||||
values = bytes.view(dtype=self.format)[0]
|
||||
values = data.view(dtype=self.format)[0]
|
||||
flag = values[0]
|
||||
self.flag = flag
|
||||
self.opened_output = (flag&0x01) > 0
|
||||
@ -147,8 +152,8 @@ class AtariDosDirent(Dirent):
|
||||
self.deleted = (flag&0x80) > 0
|
||||
self.num_sectors = int(values[1])
|
||||
self.starting_sector = int(values[2])
|
||||
self.basename = str(values[3]).rstrip()
|
||||
self.ext = str(values[4]).rstrip()
|
||||
self.basename = bytes(values[3]).rstrip()
|
||||
self.ext = bytes(values[4]).rstrip()
|
||||
self.is_sane = self.sanity_check(image)
|
||||
|
||||
def encode_dirent(self):
|
||||
@ -220,11 +225,13 @@ class AtariDosDirent(Dirent):
|
||||
return raw[0:num_bytes], num_bytes
|
||||
|
||||
def set_values(self, filename, filetype, index):
|
||||
if "." in filename:
|
||||
filename, ext = filename.split(".", 1)
|
||||
if type(filename) is not bytes:
|
||||
filename = filename.encode("utf-8")
|
||||
if b'.' in filename:
|
||||
filename, ext = filename.split(b'.', 1)
|
||||
else:
|
||||
ext = " "
|
||||
self.basename = "%-8s" % filename[0:8]
|
||||
ext = b' '
|
||||
self.basename = b'%-8s' % filename[0:8]
|
||||
self.ext = ext
|
||||
self.file_num = index
|
||||
self.dos_2 = True
|
||||
@ -358,7 +365,7 @@ class AtrHeader(BaseHeader):
|
||||
def encode(self, raw):
|
||||
values = raw.view(dtype=self.format)[0]
|
||||
values[0] = 0x296
|
||||
paragraphs = self.image_size / 16
|
||||
paragraphs = self.image_size // 16
|
||||
parshigh, pars = divmod(paragraphs, 256*256)
|
||||
values[1] = pars
|
||||
values[2] = self.sector_size
|
||||
@ -394,7 +401,7 @@ class AtrHeader(BaseHeader):
|
||||
self.sectors_per_track = 18
|
||||
self.payload_bytes = self.sector_size - 3
|
||||
initial_bytes = self.initial_sector_size * self.num_initial_sectors
|
||||
self.max_sectors = ((self.image_size - initial_bytes) / self.sector_size) + self.num_initial_sectors
|
||||
self.max_sectors = ((self.image_size - initial_bytes) // self.sector_size) + self.num_initial_sectors
|
||||
|
||||
def get_pos(self, sector):
|
||||
if not self.sector_is_valid(sector):
|
||||
@ -486,14 +493,14 @@ class AtariDosDiskImage(DiskImageBase):
|
||||
|
||||
def calc_vtoc_code(self):
|
||||
# From AA post: http://atariage.com/forums/topic/179868-mydos-vtoc-size/
|
||||
num = 1 + (self.total_sectors + 80) / (self.header.sector_size * 8)
|
||||
num = 1 + (self.total_sectors + 80) // (self.header.sector_size * 8)
|
||||
if self.header.sector_size == 128:
|
||||
if num == 1:
|
||||
code = 2
|
||||
else:
|
||||
if num & 1:
|
||||
num += 1
|
||||
code = ((num + 1) / 2) + 2
|
||||
code = ((num + 1) // 2) + 2
|
||||
else:
|
||||
if self.total_sectors < 1024:
|
||||
code = 2
|
||||
@ -629,7 +636,7 @@ class AtariDosDiskImage(DiskImageBase):
|
||||
dirent.start_read(self)
|
||||
while True:
|
||||
bytes, last, pos, size = dirent.read_sector(self)
|
||||
byte_order.extend(range(pos, pos + size))
|
||||
byte_order.extend(list(range(pos, pos + size)))
|
||||
if last:
|
||||
break
|
||||
if len(byte_order) > 0:
|
||||
@ -679,7 +686,7 @@ class BootDiskImage(AtariDosDiskImage):
|
||||
# before the boot sectors are finished loading
|
||||
max_ram = 0xc000
|
||||
max_size = max_ram - bload
|
||||
max_sectors = max_size / self.header.sector_size
|
||||
max_sectors = max_size // self.header.sector_size
|
||||
if nsec > max_sectors or nsec < 1:
|
||||
raise InvalidDiskImage("Number of boot sectors out of range")
|
||||
if bload < 0x200 or bload > (0xc000 - (nsec * self.header.sector_size)):
|
||||
|
@ -1,11 +1,14 @@
|
||||
from __future__ import absolute_import
|
||||
from builtins import str
|
||||
from builtins import object
|
||||
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__)
|
||||
@ -145,7 +148,7 @@ class A8CartHeader(object):
|
||||
|
||||
if len(bytes) == 16:
|
||||
values = bytes.view(dtype=self.format)[0]
|
||||
if values[0] != 'CART':
|
||||
if values[0] != b'CART':
|
||||
raise InvalidCartHeader
|
||||
self.cart_type = int(values[1])
|
||||
self.crc = int(values[2])
|
||||
@ -205,9 +208,9 @@ class AtariCartImage(DiskImageBase):
|
||||
return str(self.header)
|
||||
|
||||
def read_header(self):
|
||||
bytes = self.bytes[0:16]
|
||||
data = self.bytes[0:16]
|
||||
try:
|
||||
self.header = A8CartHeader(bytes)
|
||||
self.header = A8CartHeader(data)
|
||||
except InvalidCartHeader:
|
||||
self.header = A8CartHeader()
|
||||
self.header.set_type(self.cart_type)
|
||||
|
@ -1,8 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
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__)
|
||||
@ -125,10 +129,11 @@ class DiskImageBase(object):
|
||||
return Directory
|
||||
|
||||
def set_filename(self, filename):
|
||||
if "." in filename:
|
||||
self.filename, self.ext = filename.rsplit(".", 1)
|
||||
if type(filename) is not bytes: filename = filename.encode("utf-8")
|
||||
if b'.' in filename:
|
||||
self.filename, self.ext = filename.rsplit(b'.', 1)
|
||||
else:
|
||||
self.filename, self.ext = filename, ""
|
||||
self.filename, self.ext = filename, b''
|
||||
|
||||
def dir(self):
|
||||
lines = []
|
||||
@ -174,12 +179,13 @@ class DiskImageBase(object):
|
||||
if not filename:
|
||||
filename = self.filename
|
||||
if self.ext:
|
||||
filename += "." + self.ext
|
||||
filename += b'.' + self.ext
|
||||
if not filename:
|
||||
raise RuntimeError("No filename specified for save!")
|
||||
bytes = self.bytes[:]
|
||||
if type(filename) is not bytes: filename = filename.encode("utf-8")
|
||||
data = self.bytes[:]
|
||||
with open(filename, "wb") as fh:
|
||||
bytes.tofile(fh)
|
||||
data.tofile(fh)
|
||||
|
||||
def assert_valid_sector(self, sector):
|
||||
if not self.header.sector_is_valid(sector):
|
||||
@ -269,10 +275,11 @@ class DiskImageBase(object):
|
||||
# check if we've been passed a dirent instead of a filename
|
||||
if hasattr(filename, "filename"):
|
||||
return filename
|
||||
if type(filename) is not bytes: filename = filename.encode("utf-8")
|
||||
for dirent in self.files:
|
||||
if filename == dirent.filename:
|
||||
return dirent
|
||||
raise FileNotFound("%s not found on disk" % filename)
|
||||
raise FileNotFound("%s not found on disk" % str(filename))
|
||||
|
||||
def find_file(self, filename):
|
||||
dirent = self.find_dirent(filename)
|
||||
@ -290,7 +297,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,15 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
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__)
|
||||
@ -56,7 +62,7 @@ class Dos33TSSector(WriteableSector):
|
||||
|
||||
|
||||
class Dos33VTOC(VTOC):
|
||||
max_tracks = (256 - 0x38) / 4 # 50, but kept here in case sector size changed
|
||||
max_tracks = (256 - 0x38) // 4 # 50, but kept here in case sector size changed
|
||||
max_sectors = max_tracks * 16
|
||||
vtoc_bit_reorder_index = np.tile(np.arange(15, -1, -1), max_tracks) + (np.repeat(np.arange(max_tracks), 16) * 16)
|
||||
|
||||
@ -164,7 +170,7 @@ class Dos33Dirent(Dirent):
|
||||
self.deleted = False
|
||||
self.track = 0
|
||||
self.sector = 0
|
||||
self.filename = ""
|
||||
self.filename = b''
|
||||
self.num_sectors = 0
|
||||
self.is_sane = True
|
||||
self.current_sector_index = 0
|
||||
@ -189,7 +195,7 @@ class Dos33Dirent(Dirent):
|
||||
0x20: "a", # ?
|
||||
0x40: "b", # ?
|
||||
}
|
||||
text_to_type = {v: k for k, v in type_to_text.iteritems()}
|
||||
text_to_type = {v: k for k, v in type_to_text.items()}
|
||||
|
||||
@property
|
||||
def file_type(self):
|
||||
@ -346,7 +352,8 @@ class Dos33Dirent(Dirent):
|
||||
return self.filename
|
||||
|
||||
def set_values(self, filename, filetype, index):
|
||||
self.filename = "%-30s" % filename[0:30]
|
||||
if type(filename) is not bytes: filename = filename.encode("utf-8")
|
||||
self.filename = b'%-30s' % filename[0:30]
|
||||
self._file_type = self.text_to_type.get(filetype, 0x04)
|
||||
self.locked = False
|
||||
self.deleted = False
|
||||
@ -531,7 +538,7 @@ class Dos33DiskImage(DiskImageBase):
|
||||
self.assert_valid_sector(sector)
|
||||
if _xd: log.debug("loading directory segment from catalog sector %d" % sector)
|
||||
raw, pos, size = self.get_raw_bytes(sector)
|
||||
byte_order.extend(range(pos, pos + size))
|
||||
byte_order.extend(list(range(pos, pos + size)))
|
||||
sector = self.header.sector_from_track(raw[1], raw[2])
|
||||
raw = self.rawdata.get_indexed(byte_order)
|
||||
segment = DefaultSegment(raw, name="Catalog")
|
||||
@ -571,7 +578,7 @@ class Dos33DiskImage(DiskImageBase):
|
||||
dirent.start_read(self)
|
||||
while True:
|
||||
bytes, last, pos, size = dirent.read_sector(self)
|
||||
byte_order.extend(range(pos, pos + size))
|
||||
byte_order.extend(list(range(pos, pos + size)))
|
||||
if last:
|
||||
break
|
||||
if len(byte_order) > 0:
|
||||
@ -624,7 +631,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,9 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
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):
|
||||
@ -24,7 +26,7 @@ class KBootDirent(AtariDosDirent):
|
||||
else:
|
||||
self.exe_size = count
|
||||
self.exe_start = start
|
||||
self.num_sectors = count / 128 + 1
|
||||
self.num_sectors = count // 128 + 1
|
||||
|
||||
def parse_raw_dirent(self, image, bytes):
|
||||
pass
|
||||
@ -58,25 +60,25 @@ class KBootImage(AtariDosDiskImage):
|
||||
return XexSegment(raw, 0, 0, start, end, name="KBoot Executable")
|
||||
|
||||
|
||||
xexboot_header = '\x00\x03\x00\x07\r\x07L\r\x07\x1c[\x00\x00\xa0\x00\x8c\t\x03\x8c\x04\x03\x8cD\x02\x8c\xe2\x02\x8c\xe3\x02\xc8\x84\t\x8c\x01\x03\xce\x06\x03\xa91\x8d\x00\x03\xa9R\x8d\x02\x03\xa9\x80\x8d\x08\x03\xa9\x01\x8d\x05\x03\xa9\xe3\x8d0\x02\x8d\x02\xd4\xa9\x07\x8d1\x02\x8d\x03\xd4\xa9\x00\xaa\x8d\x0b\x03\xa9\x04\x8d\n\x03 \xbc\x07\xca \xa5\x07\x85C \xa5\x07\x85D%C\xc9\xff\xf0\xf0 \xa5\x07\x85E \xa5\x07\x85F \xa5\x07\x91C\xe6C\xd0\x02\xe6D\xa5E\xc5C\xa5F\xe5D\xb0\xeb\xad\xe2\x02\r\xe3\x02\xf0\xc9\x86\x19 \xa2\x07\xa6\x19\xa0\x00\x8c\xe2\x02\x8c\xe3\x02\xf0\xb8l\xe2\x02\xad\t\x07\xd0\x0b\xad\n\x07\xd0\x03l\xe0\x02\xce\n\x07\xce\t\x07\xe0\x80\x90"\xa9@\x8d\x03\x03 Y\xe4\x10\x06\xce\x01\x07\xd0\xf1\x00\xee\n\x03\xd0\x03\xee\x0b\x03\xad\n\x03\x8d\x19\xd0\xa0\x00\xa2\x00\xbd\x00\x01\xe8`pppppF\xf8\x07p\x07ppp\x06p\x06p\x06A\xe3\x07\x00\x00\x00\x00\x00,/!$).\'\x0e\x0e\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00&2/-'
|
||||
xexboot_header = b'\x00\x03\x00\x07\r\x07L\r\x07\x1c[\x00\x00\xa0\x00\x8c\t\x03\x8c\x04\x03\x8cD\x02\x8c\xe2\x02\x8c\xe3\x02\xc8\x84\t\x8c\x01\x03\xce\x06\x03\xa91\x8d\x00\x03\xa9R\x8d\x02\x03\xa9\x80\x8d\x08\x03\xa9\x01\x8d\x05\x03\xa9\xe3\x8d0\x02\x8d\x02\xd4\xa9\x07\x8d1\x02\x8d\x03\xd4\xa9\x00\xaa\x8d\x0b\x03\xa9\x04\x8d\n\x03 \xbc\x07\xca \xa5\x07\x85C \xa5\x07\x85D%C\xc9\xff\xf0\xf0 \xa5\x07\x85E \xa5\x07\x85F \xa5\x07\x91C\xe6C\xd0\x02\xe6D\xa5E\xc5C\xa5F\xe5D\xb0\xeb\xad\xe2\x02\r\xe3\x02\xf0\xc9\x86\x19 \xa2\x07\xa6\x19\xa0\x00\x8c\xe2\x02\x8c\xe3\x02\xf0\xb8l\xe2\x02\xad\t\x07\xd0\x0b\xad\n\x07\xd0\x03l\xe0\x02\xce\n\x07\xce\t\x07\xe0\x80\x90"\xa9@\x8d\x03\x03 Y\xe4\x10\x06\xce\x01\x07\xd0\xf1\x00\xee\n\x03\xd0\x03\xee\x0b\x03\xad\n\x03\x8d\x19\xd0\xa0\x00\xa2\x00\xbd\x00\x01\xe8`pppppF\xf8\x07p\x07ppp\x06p\x06p\x06A\xe3\x07\x00\x00\x00\x00\x00,/!$).\'\x0e\x0e\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00&2/-'
|
||||
|
||||
|
||||
def insert_string(data, offset, string, color):
|
||||
def insert_bytes(data, offset, string, color):
|
||||
s = np.fromstring(string.upper(), dtype=np.uint8) - 32 # convert to internal
|
||||
s = s | color
|
||||
count = len(s)
|
||||
tx = offset + (20 - count)/ 2
|
||||
tx = offset + (20 - count) // 2
|
||||
data[tx:tx+count] = s
|
||||
|
||||
|
||||
def add_xexboot_header(bytes, bootcode=None, title="DEMO", author="an atari user"):
|
||||
def add_xexboot_header(bytes, bootcode=None, title=b"DEMO", author=b"an atari user"):
|
||||
sec_size = 128
|
||||
xex_size = len(bytes)
|
||||
num_sectors = (xex_size + sec_size - 1) / sec_size
|
||||
num_sectors = (xex_size + sec_size - 1) // sec_size
|
||||
padded_size = num_sectors * sec_size
|
||||
if xex_size < padded_size:
|
||||
bytes = np.append(bytes, np.zeros([padded_size - xex_size], dtype=np.uint8))
|
||||
paragraphs = padded_size / 16
|
||||
paragraphs = padded_size // 16
|
||||
|
||||
if bootcode is None:
|
||||
bootcode = np.fromstring(xexboot_header, dtype=np.uint8)
|
||||
@ -92,8 +94,8 @@ def add_xexboot_header(bytes, bootcode=None, title="DEMO", author="an atari user
|
||||
bootsectors = np.zeros([384], dtype=np.uint8)
|
||||
bootsectors[0:bootsize] = bootcode
|
||||
|
||||
insert_string(bootsectors, 268, title, 0b11000000)
|
||||
insert_string(bootsectors, 308, author, 0b01000000)
|
||||
insert_bytes(bootsectors, 268, title, 0b11000000)
|
||||
insert_bytes(bootsectors, 308, author, 0b01000000)
|
||||
|
||||
image = np.append(bootsectors, bytes)
|
||||
return image
|
||||
|
@ -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__)
|
||||
@ -14,7 +15,7 @@ log = logging.getLogger(__name__)
|
||||
class MameZipImage(DiskImageBase):
|
||||
def __init__(self, rawdata, filename=""):
|
||||
self.zipdata = rawdata
|
||||
fh = self.zipdata.stringio
|
||||
fh = self.zipdata.bufferedio
|
||||
if zipfile.is_zipfile(fh):
|
||||
with zipfile.ZipFile(fh) as zf:
|
||||
self.check_zip_size(zf)
|
||||
|
@ -1,13 +1,16 @@
|
||||
from __future__ import absolute_import
|
||||
from builtins import str
|
||||
from builtins import object
|
||||
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 +63,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 +74,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 +150,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,20 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import zip
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
import bisect
|
||||
import cStringIO
|
||||
import io
|
||||
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
|
||||
@ -192,8 +201,8 @@ class SegmentData(object):
|
||||
raise ValueError("The base SegmentData object should use the resize method to replace arrays")
|
||||
|
||||
@property
|
||||
def stringio(self):
|
||||
buf = cStringIO.StringIO(self.data[:])
|
||||
def bufferedio(self):
|
||||
buf = io.BytesIO(self.data[:])
|
||||
return buf
|
||||
|
||||
@property
|
||||
@ -432,7 +441,7 @@ class DefaultSegment(object):
|
||||
state['_order_list'] = r.order.tolist() # more compact serialization in python list
|
||||
else:
|
||||
state['_order_list'] = None
|
||||
state['memory_map'] = sorted([list(i) for i in self.memory_map.iteritems()])
|
||||
state['memory_map'] = sorted([list(i) for i in self.memory_map.items()])
|
||||
return state
|
||||
|
||||
def __setstate__(self, state):
|
||||
@ -626,7 +635,7 @@ class DefaultSegment(object):
|
||||
that uses this base data.
|
||||
"""
|
||||
style_base = self.rawdata.style_base
|
||||
comment_text_indexes = np.asarray(self.rawdata.extra.comments.keys(), dtype=np.uint32)
|
||||
comment_text_indexes = np.asarray(list(self.rawdata.extra.comments.keys()), dtype=np.uint32)
|
||||
comment_mask = self.get_style_mask(comment=True)
|
||||
has_comments = np.where(style_base & comment_bit_mask > 0)[0]
|
||||
both = np.intersect1d(comment_text_indexes, has_comments)
|
||||
@ -641,7 +650,7 @@ class DefaultSegment(object):
|
||||
#print len(r.style)
|
||||
#print len(r.style_base)
|
||||
r.style_base[:] &= style_bits
|
||||
comment_indexes = np.asarray(self.rawdata.extra.comments.keys(), dtype=np.uint32)
|
||||
comment_indexes = np.asarray(list(self.rawdata.extra.comments.keys()), dtype=np.uint32)
|
||||
#print comment_indexes
|
||||
r.style_base[comment_indexes] |= comment_bit_mask
|
||||
return r.unindexed_style[:]
|
||||
@ -930,7 +939,7 @@ class DefaultSegment(object):
|
||||
|
||||
# Naive way, but maybe it's fast enough: loop over all comments
|
||||
# gathering those within the bounds
|
||||
for rawindex, comment in self.rawdata.extra.comments.iteritems():
|
||||
for rawindex, comment in self.rawdata.extra.comments.items():
|
||||
try:
|
||||
index = self.get_index_from_base_index(rawindex)
|
||||
except IndexError:
|
||||
@ -973,13 +982,13 @@ class DefaultSegment(object):
|
||||
del self.rawdata.extra.comments[rawindex]
|
||||
|
||||
def get_sorted_comments(self):
|
||||
return sorted([[k, v] for k, v in self.rawdata.extra.comments.iteritems()])
|
||||
return sorted([[k, v] for k, v in self.rawdata.extra.comments.items()])
|
||||
|
||||
def iter_comments_in_segment(self):
|
||||
start = self.start_addr
|
||||
start_index = self.get_raw_index(0)
|
||||
end_index = self.get_raw_index(len(self.rawdata))
|
||||
for k, v in self.rawdata.extra.comments.iteritems():
|
||||
for k, v in self.rawdata.extra.comments.items():
|
||||
if k >= start_index and k < end_index:
|
||||
yield self.rawdata.get_reverse_index(k), v
|
||||
|
||||
@ -1007,11 +1016,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,11 @@
|
||||
from __future__ import absolute_import
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
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__)
|
||||
@ -232,7 +235,7 @@ class SpartaDosDiskImage(AtariDosDiskImage):
|
||||
while True:
|
||||
bytes, last, pos, size = dirent.read_sector(self)
|
||||
if not last:
|
||||
byte_order.extend(range(pos, pos + size))
|
||||
byte_order.extend(list(range(pos, pos + size)))
|
||||
else:
|
||||
break
|
||||
if len(byte_order) > 0:
|
||||
|
@ -1,8 +1,13 @@
|
||||
from __future__ import absolute_import
|
||||
from builtins import zip
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
import types
|
||||
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from .errors import *
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@ -15,9 +20,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")
|
||||
|
||||
@ -184,7 +189,7 @@ class Directory(BaseSectorList):
|
||||
|
||||
def get_free_dirent(self):
|
||||
used = set()
|
||||
d = self.dirents.items()
|
||||
d = list(self.dirents.items())
|
||||
if d:
|
||||
d.sort()
|
||||
for i, dirent in d:
|
||||
@ -209,11 +214,11 @@ class Directory(BaseSectorList):
|
||||
def find_dirent(self, filename):
|
||||
if hasattr(filename, "filename"):
|
||||
# we've been passed a dirent instead of a filename
|
||||
for dirent in self.dirents.values():
|
||||
for dirent in list(self.dirents.values()):
|
||||
if dirent == filename:
|
||||
return dirent
|
||||
else:
|
||||
for dirent in self.dirents.values():
|
||||
for dirent in list(self.dirents.values()):
|
||||
if filename == dirent.filename:
|
||||
return dirent
|
||||
raise FileNotFound("%s not found on disk" % filename)
|
||||
@ -238,7 +243,7 @@ class Directory(BaseSectorList):
|
||||
self.current_sector = self.get_dirent_sector()
|
||||
self.encode_index = 0
|
||||
|
||||
d = self.dirents.items()
|
||||
d = list(self.dirents.items())
|
||||
d.sort()
|
||||
# there may be gaps, so fill in missing entries with blanks
|
||||
current = 0
|
||||
|
11
setup.py
11
setup.py
@ -5,7 +5,7 @@ try:
|
||||
except ImportError:
|
||||
from distutils.core import setup
|
||||
|
||||
execfile('atrcopy/_metadata.py')
|
||||
exec(open('atrcopy/_metadata.py').read())
|
||||
|
||||
with open("README.rst", "r") as fp:
|
||||
long_description = fp.read()
|
||||
@ -27,16 +27,21 @@ setup(name="atrcopy",
|
||||
long_description=long_description,
|
||||
license="GPL",
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 2",
|
||||
"Programming Language :: Python :: 2.7",
|
||||
"Programming Language :: Python :: 3.5",
|
||||
"Programming Language :: Python :: 3.6",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: GNU General Public License (GPL)",
|
||||
"Topic :: Software Development :: Libraries",
|
||||
"Topic :: Utilities",
|
||||
],
|
||||
install_requires = [
|
||||
"future",
|
||||
'numpy',
|
||||
],
|
||||
tests_require = [
|
||||
'pytest',
|
||||
'pytest>3.0',
|
||||
'coverage',
|
||||
'pytest.cov',
|
||||
],
|
||||
)
|
||||
|
@ -8,6 +8,8 @@ module_dir = os.path.realpath(os.path.abspath(".."))
|
||||
if module_dir not in sys.path:
|
||||
sys.path.insert(0, module_dir)
|
||||
|
||||
print(sys.path)
|
||||
|
||||
import pytest
|
||||
try:
|
||||
slow = pytest.mark.skipif(
|
||||
|
@ -1,3 +1,5 @@
|
||||
from __future__ import print_function
|
||||
from builtins import object
|
||||
import numpy as np
|
||||
|
||||
from mock import *
|
||||
@ -15,12 +17,13 @@ class BaseFilesystemModifyTest(object):
|
||||
rawdata = SegmentData(self.sample_data.copy())
|
||||
self.image = self.diskimage_type(rawdata)
|
||||
|
||||
def check_entries(self, entries, prefix="TEST", save=None):
|
||||
def check_entries(self, entries, prefix=b"TEST", save=None):
|
||||
if type(prefix) is not bytes: prefix = prefix.encode("utf-8")
|
||||
orig_num_files = len(self.image.files)
|
||||
filenames = []
|
||||
count = 1
|
||||
for data in entries:
|
||||
filename = "%s%d.BIN" % (prefix, count)
|
||||
filename = b"%s%d.BIN" % (prefix, count)
|
||||
self.image.write_file(filename, None, data)
|
||||
assert len(self.image.files) == orig_num_files + count
|
||||
data2 = np.fromstring(self.image.find_file(filename), dtype=np.uint8)
|
||||
@ -30,7 +33,7 @@ class BaseFilesystemModifyTest(object):
|
||||
# loop over them again to make sure data wasn't overwritten
|
||||
count = 1
|
||||
for data in entries:
|
||||
filename = "%s%d.BIN" % (prefix, count)
|
||||
filename = b"%s%d.BIN" % (prefix, count)
|
||||
data2 = np.fromstring(self.image.find_file(filename), dtype=np.uint8)
|
||||
assert np.array_equal(data, data2[0:len(data)])
|
||||
count += 1
|
||||
@ -45,20 +48,20 @@ class BaseFilesystemModifyTest(object):
|
||||
assert len(self.image.files) == self.num_files_in_sample
|
||||
|
||||
data = np.asarray([0xff, 0xff, 0x00, 0x60, 0x01, 0x60, 1, 2], dtype=np.uint8)
|
||||
self.image.write_file("TEST.XEX", None, data)
|
||||
self.image.write_file(b"TEST.XEX", None, data)
|
||||
assert len(self.image.files) == self.num_files_in_sample + 1
|
||||
|
||||
data2 = np.fromstring(self.image.find_file("TEST.XEX"), dtype=np.uint8)
|
||||
data2 = np.fromstring(self.image.find_file(b"TEST.XEX"), dtype=np.uint8)
|
||||
assert np.array_equal(data, data2[0:len(data)])
|
||||
|
||||
def test_50k(self):
|
||||
assert len(self.image.files) == self.num_files_in_sample
|
||||
|
||||
data = np.arange(50*1024, dtype=np.uint8)
|
||||
self.image.write_file("RAMP50K.BIN", None, data)
|
||||
self.image.write_file(b"RAMP50K.BIN", None, data)
|
||||
assert len(self.image.files) == self.num_files_in_sample + 1
|
||||
|
||||
data2 = self.image.find_file("RAMP50K.BIN")
|
||||
data2 = self.image.find_file(b"RAMP50K.BIN")
|
||||
assert data.tostring() == data2
|
||||
|
||||
def test_many_small(self):
|
||||
@ -75,17 +78,17 @@ class BaseFilesystemModifyTest(object):
|
||||
np.arange(9*1024, dtype=np.uint8),
|
||||
np.arange(10*1024, dtype=np.uint8),
|
||||
]
|
||||
self.check_entries(entries, save="many_small.atr")
|
||||
self.check_entries(entries, save=b"many_small.atr")
|
||||
|
||||
def test_big_failure(self):
|
||||
assert len(self.image.files) == self.num_files_in_sample
|
||||
|
||||
data = np.arange(50*1024, dtype=np.uint8)
|
||||
self.image.write_file("RAMP50K.BIN", None, data)
|
||||
self.image.write_file(b"RAMP50K.BIN", None, data)
|
||||
assert len(self.image.files) == self.num_files_in_sample + 1
|
||||
with pytest.raises(NotEnoughSpaceOnDisk):
|
||||
huge = np.arange(500*1024, dtype=np.uint8)
|
||||
self.image.write_file("RAMP500K.BIN", None, huge)
|
||||
self.image.write_file(b"RAMP500K.BIN", None, huge)
|
||||
assert len(self.image.files) == self.num_files_in_sample + 1
|
||||
|
||||
def test_delete(self):
|
||||
@ -115,7 +118,7 @@ class BaseFilesystemModifyTest(object):
|
||||
self.image.delete_file(filenames[8])
|
||||
assert len(self.image.files) == self.num_files_in_sample + 7
|
||||
|
||||
filename = self.check_entries(entries2, "SECOND", save="test_delete.atr")
|
||||
filename = self.check_entries(entries2, b"SECOND", save="test_delete.atr")
|
||||
assert len(self.image.files) == self.num_files_in_sample + 9
|
||||
|
||||
def test_delete_all(self):
|
||||
@ -161,7 +164,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,5 @@
|
||||
from __future__ import print_function
|
||||
from builtins import object
|
||||
from mock import *
|
||||
|
||||
from atrcopy import SegmentData, AtariDosFile, InvalidBinaryFile, DefaultSegment, XexContainerSegment
|
||||
@ -13,7 +15,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 +25,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,6 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from builtins import object
|
||||
from mock import *
|
||||
|
||||
from atrcopy import AtariCartImage, SegmentData, InvalidDiskImage
|
||||
@ -9,7 +12,7 @@ class TestAtariCart(object):
|
||||
|
||||
def get_cart(self, k_size, cart_type):
|
||||
data = np.zeros((k_size * 1024)+16, dtype=np.uint8)
|
||||
data[0:4].view("|a4")[0] = 'CART'
|
||||
data[0:4].view("|a4")[0] = b'CART'
|
||||
data[4:8].view(">u4")[0] = cart_type
|
||||
return data
|
||||
|
||||
@ -46,7 +49,7 @@ class TestAtariCart(object):
|
||||
rawdata = SegmentData(data)
|
||||
image = AtariCartImage(rawdata, cart_type)
|
||||
image.parse_segments()
|
||||
assert len(image.segments) == 1 + 1 + (k_size - main_size)/banked_size
|
||||
assert len(image.segments) == 1 + 1 + (k_size - main_size) //banked_size
|
||||
assert len(image.segments[0]) == 16
|
||||
assert len(image.segments[1]) == main_size * 1024
|
||||
assert len(image.segments[2]) == banked_size * 1024
|
||||
@ -73,7 +76,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,5 @@
|
||||
from __future__ import print_function
|
||||
from builtins import object
|
||||
import numpy as np
|
||||
|
||||
from mock import *
|
||||
@ -42,8 +44,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,7 @@
|
||||
from __future__ import print_function
|
||||
from builtins import zip
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
import os
|
||||
|
||||
import pytest
|
||||
@ -14,33 +18,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__()
|
||||
order = list(reversed(range(700, 800)))
|
||||
print(s3.byte_bounds_offset(), len(s3), s3.__getstate__())
|
||||
order = list(reversed(list(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,7 +1,12 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
|
||||
from mock import *
|
||||
from atrcopy import SegmentData, KBootImage, add_xexboot_header, add_atr_header
|
||||
|
||||
|
||||
@ -21,9 +26,9 @@ class TestKbootHeader(object):
|
||||
rawdata = SegmentData(bytes)
|
||||
newatr = KBootImage(rawdata)
|
||||
image = newatr.bytes
|
||||
print image[0:16]
|
||||
paragraphs = image_size / 16
|
||||
print newatr.header, paragraphs
|
||||
print(image[0:16])
|
||||
paragraphs = image_size // 16
|
||||
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,7 @@
|
||||
from __future__ import print_function
|
||||
from builtins import zip
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
@ -5,6 +9,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 +37,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 +47,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 +56,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 +109,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 +152,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 +189,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 +225,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 +240,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 +265,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 +285,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():
|
||||
for rawindex, comment in list(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():
|
||||
for rawindex, comment in list(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 +386,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 +413,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,6 @@
|
||||
from __future__ import print_function
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
@ -33,7 +36,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 +44,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
|
||||
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
from builtins import object
|
||||
from mock import *
|
||||
from atrcopy import utils
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user