Converted "from errors import *" to "from . import errors"

This commit is contained in:
Rob McMullen 2018-06-24 12:10:59 -07:00
parent 1b7e1fad4c
commit 6b9cf6d4d2
17 changed files with 121 additions and 119 deletions

View File

@ -13,7 +13,7 @@ try:
except ImportError:
raise RuntimeError("atrcopy %s requires numpy" % __version__)
from .errors import *
from . import errors
from .ataridos import AtrHeader, AtariDosDiskImage, BootDiskImage, AtariDosFile, XexContainerSegment, get_xex, add_atr_header
from .dos33 import Dos33DiskImage
from .kboot import KBootImage, add_xexboot_header
@ -74,7 +74,7 @@ def find_diskimage(filename):
break
if parser is None:
print("%s: Unknown disk image type" % filename)
except UnsupportedDiskImage as e:
except errors.UnsupportedDiskImage as e:
print("%s: %s" % (filename, e))
return None
except IOError as e:
@ -92,7 +92,7 @@ def extract_files(image, files):
for name in files:
try:
dirent = image.find_dirent(name)
except FileNotFound:
except errors.FileNotFound:
print("%s not in %s" % (name, image))
continue
output = dirent.filename
@ -118,7 +118,7 @@ def save_file(image, name, filetype, data):
else:
print("skipping %s, use -f to overwrite" % (name))
return False
except FileNotFound:
except errors.FileNotFound:
pass
print("copying %s to %s" % (name, image.filename))
if not options.dry_run:
@ -145,7 +145,7 @@ def remove_files(image, files):
for name in files:
try:
dirent = image.find_dirent(name)
except FileNotFound:
except errors.FileNotFound:
print("%s not in %s" % (name, image))
continue
print("removing %s from %s" % (name, image))
@ -185,14 +185,14 @@ def assemble_segments(source_files, data_files, obj_files, run_addr=""):
try:
import pyatasm
except ImportError:
raise AtrError("Please install pyatasm to compile code.")
raise errors.AtrError("Please install pyatasm to compile code.")
changed = False
segments = SegmentList()
for name in source_files:
try:
asm = pyatasm.Assemble(name)
except SyntaxError as e:
raise AtrError("Assembly error: %s" % e.msg)
raise errors.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)
@ -200,7 +200,7 @@ def assemble_segments(source_files, data_files, obj_files, run_addr=""):
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")
raise errors.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))
@ -254,7 +254,7 @@ def assemble(image, source_files, data_files, obj_files, run_addr=""):
def boot_image(image_name, source_files, data_files, obj_files, run_addr=""):
try:
image_cls = parsers_for_filename(image_name)[0]
except InvalidDiskImage as e:
except errors.InvalidDiskImage as e:
print("%s: %s" % (image_name, e))
return None
segments, run_addr = assemble_segments(source_files, data_files, obj_files, run_addr)
@ -339,16 +339,16 @@ def get_template_info():
def get_template_data(template):
possibilities = get_template_images(template)
if not possibilities:
raise InvalidDiskImage("Unknown template disk image %s" % template)
raise errors.InvalidDiskImage("Unknown template disk image %s" % template)
if len(possibilities) > 1:
raise InvalidDiskImage("Name %s is ambiguous (%d matches: %s)" % (template, len(possibilities), ", ".join(sorted(possibilities.keys()))))
raise errors.InvalidDiskImage("Name %s is ambiguous (%d matches: %s)" % (template, len(possibilities), ", ".join(sorted(possibilities.keys()))))
name, inf = possibilities.popitem()
path = inf['path']
try:
with open(path, "rb") as fh:
data = fh.read()
except IOError:
raise InvalidDiskImage("Failed reading template file %s" % path)
raise errors.InvalidDiskImage("Failed reading template file %s" % path)
return data, inf
@ -357,7 +357,7 @@ def create_image(template, name):
try:
data, inf = get_template_data(template)
except InvalidDiskImage as e:
except errors.InvalidDiskImage as e:
info = get_template_info()
print("Error: %s\n\n%s" % (e, info))
return

View File

@ -1,6 +1,6 @@
import numpy as np
from .errors import *
from . import errors
from .diskimages import DiskImageBase, BaseHeader
from .segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment, DefaultSegment, SegmentedFileSegment, SegmentSaver, get_style_bits
from .utils import *
@ -197,7 +197,7 @@ class AtariDosDirent(Dirent):
def start_read(self, image):
if not self.is_sane:
raise InvalidDirent("Invalid directory entry '%s'" % str(self))
raise errors.InvalidDirent("Invalid directory entry '%s'" % str(self))
self.current_sector = self.starting_sector
self.current_read = self.num_sectors
self.sectors_seen = set()
@ -210,11 +210,11 @@ class AtariDosDirent(Dirent):
def process_raw_sector(self, image, raw):
file_num = raw[-3] >> 2
if file_num != self.file_num:
raise FileNumberMismatchError164("Expecting file %d, found %d" % (self.file_num, file_num))
raise errors.FileNumberMismatchError164("Expecting file %d, found %d" % (self.file_num, file_num))
self.sectors_seen.add(self.current_sector)
next_sector = ((raw[-3] & 0x3) << 8) + raw[-2]
if next_sector in self.sectors_seen:
raise InvalidFile("Bad sector pointer data: attempting to reread sector %d" % next_sector)
raise errors.InvalidFile("Bad sector pointer data: attempting to reread sector %d" % next_sector)
self.current_sector = next_sector
num_bytes = raw[-1]
return raw[0:num_bytes], num_bytes
@ -299,7 +299,7 @@ class AtariDosFile(object):
first = False
continue
elif first:
raise InvalidBinaryFile("Object file doesn't start with 0xffff")
raise errors.InvalidBinaryFile("Object file doesn't start with 0xffff")
if _xd: log.debug("header parsing: header=0x%x" % header)
if len(b[pos:pos + 4]) < 4:
self.segments.append(ObjSegment(r[pos:pos + 4], 0, 0, 0, len(b[pos:pos + 4]), "Short Segment Header"))
@ -307,7 +307,7 @@ class AtariDosFile(object):
start, end = b[pos:pos + 4].view(dtype='<u2')
s[style_pos:pos + 4] = get_style_bits(data=True)
if end < start:
raise InvalidBinaryFile("Nonsensical start and end addresses")
raise errors.InvalidBinaryFile("Nonsensical start and end addresses")
count = end - start + 1
found = len(b[pos + 4:pos + 4 + count])
if found < count:
@ -344,7 +344,7 @@ class AtrHeader(BaseHeader):
if len(bytes) == 16:
values = bytes.view(dtype=self.format)[0]
if values[0] != 0x296:
raise InvalidAtrHeader("no ATR header magic value")
raise errors.InvalidAtrHeader("no ATR header magic value")
self.image_size = (int(values[3]) * 256 * 256 + int(values[1])) * 16
self.sector_size = int(values[2])
self.crc = int(values[4])
@ -352,7 +352,7 @@ class AtrHeader(BaseHeader):
self.flags = int(values[6])
self.header_offset = 16
else:
raise InvalidAtrHeader("incorrect AHC header size of %d" % len(bytes))
raise errors.InvalidAtrHeader("incorrect AHC header size of %d" % len(bytes))
def __str__(self):
return "%s Disk Image (size=%d (%dx%dB), crc=%d flags=%d unused=%d)" % (self.file_format, self.image_size, self.max_sectors, self.sector_size, self.crc, self.flags, self.unused)
@ -414,7 +414,7 @@ class AtrHeader(BaseHeader):
size = len(image)
if self.header_offset == 16 or size in [92176, 133136, 184336, 183952]:
return
raise InvalidDiskImage("Uncommon size of ATR file")
raise errors.InvalidDiskImage("Uncommon size of ATR file")
class XfdHeader(AtrHeader):
@ -434,7 +434,7 @@ class XfdHeader(AtrHeader):
size = len(image)
if size in [92160, 133120, 183936, 184320]:
return
raise InvalidDiskImage("Uncommon size of XFD file")
raise errors.InvalidDiskImage("Uncommon size of XFD file")
class AtariDosDiskImage(DiskImageBase):
@ -489,7 +489,7 @@ class AtariDosDiskImage(DiskImageBase):
bytes = self.bytes[0:16]
try:
self.header = AtrHeader(bytes)
except InvalidAtrHeader:
except errors.InvalidAtrHeader:
self.header = XfdHeader()
def calc_vtoc_code(self):
@ -521,7 +521,7 @@ class AtariDosDiskImage(DiskImageBase):
self.assert_valid_sector(self.first_vtoc)
self.num_vtoc = num
if num < 0 or num > self.calc_vtoc_code():
raise InvalidDiskImage("Invalid number of VTOC sectors: %d" % num)
raise errors.InvalidDiskImage("Invalid number of VTOC sectors: %d" % num)
self.total_sectors = values[1]
self.unused_sectors = values[2]
@ -657,7 +657,7 @@ class AtariDosDiskImage(DiskImageBase):
try:
binary = AtariDosFile(segment.rawdata)
segments_out.extend(binary.segments)
except InvalidBinaryFile:
except errors.InvalidBinaryFile:
log.debug("%s not a binary file; skipping segment generation" % str(segment))
return segments_out
@ -678,7 +678,7 @@ class BootDiskImage(AtariDosDiskImage):
i = self.header.header_offset
flag = b[i:i + 2].view(dtype='<u2')[0]
if flag == 0xffff:
raise InvalidDiskImage("Appears to be an executable")
raise errors.InvalidDiskImage("Appears to be an executable")
nsec = b[i + 1]
bload = b[i + 2:i + 4].view(dtype='<u2')[0]
@ -689,9 +689,9 @@ class BootDiskImage(AtariDosDiskImage):
max_size = max_ram - bload
max_sectors = max_size // self.header.sector_size
if nsec > max_sectors or nsec < 1:
raise InvalidDiskImage("Number of boot sectors out of range (tried %d, max=%d" % (nsec, max_sectors))
raise errors.InvalidDiskImage("Number of boot sectors out of range (tried %d, max=%d" % (nsec, max_sectors))
if bload > (0xc000 - (nsec * self.header.sector_size)):
raise InvalidDiskImage("Bad boot load address")
raise errors.InvalidDiskImage("Bad boot load address")
def get_boot_sector_info(self):
pass
@ -764,7 +764,7 @@ def get_xex(segments, run_addr=None):
found = True
break
if not found:
raise InvalidBinaryFile("Run address points outside data segments")
raise errors.InvalidBinaryFile("Run address points outside data segments")
else:
run_addr = segments[0].origin
words[0] = run_addr

View File

@ -2,7 +2,7 @@ from collections import defaultdict
import numpy as np
from .errors import *
from . import errors
from .segments import SegmentData, EmptySegment, ObjSegment
from .diskimages import DiskImageBase
from .utils import to_numpy
@ -108,7 +108,7 @@ def get_cart(cart_type):
try:
return known_cart_types[known_cart_type_map[cart_type]]
except KeyError:
raise InvalidDiskImage("Unsupported cart type %d" % cart_type)
raise errors.InvalidDiskImage("Unsupported cart type %d" % cart_type)
class A8CartHeader(object):
@ -146,13 +146,13 @@ class A8CartHeader(object):
if len(bytes) == 16:
values = bytes.view(dtype=self.format)[0]
if values[0] != b'CART':
raise InvalidCartHeader
raise errors.InvalidCartHeader
self.cart_type = int(values[1])
self.crc = int(values[2])
self.header_offset = 16
self.set_type(self.cart_type)
else:
raise InvalidCartHeader
raise errors.InvalidCartHeader
def __str__(self):
return "%s Cartridge (atari800 type=%d size=%d, %d banks, crc=%d)" % (self.cart_name, self.cart_type, self.cart_size, self.bank_size, self.crc)
@ -208,13 +208,13 @@ class AtariCartImage(DiskImageBase):
data = self.bytes[0:16]
try:
self.header = A8CartHeader(data)
except InvalidCartHeader:
except errors.InvalidCartHeader:
self.header = A8CartHeader()
self.header.set_type(self.cart_type)
def strict_check(self):
if self.header.cart_type != self.cart_type:
raise InvalidDiskImage("Cart type doesn't match type defined in header")
raise errors.InvalidDiskImage("Cart type doesn't match type defined in header")
def relaxed_check(self):
if self.header.cart_type != self.cart_type:
@ -229,9 +229,9 @@ class AtariCartImage(DiskImageBase):
c = get_cart(self.cart_type)
log.debug("checking type=%d, k=%d, rem=%d for %s, %s" % (self.cart_type, k, rem, c[1], c[2]))
if rem > 0:
raise InvalidDiskImage("Cart not multiple of 1K")
raise errors.InvalidDiskImage("Cart not multiple of 1K")
if k != c[2]:
raise InvalidDiskImage("Image size %d doesn't match cart type %d size %d" % (k, self.cart_type, c[2]))
raise errors.InvalidDiskImage("Image size %d doesn't match cart type %d size %d" % (k, self.cart_type, c[2]))
def parse_segments(self):
r = self.rawdata

View File

@ -1,6 +1,6 @@
import numpy as np
from .errors import *
from . import errors
from .segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment
from .utils import *
@ -80,7 +80,7 @@ class BaseHeader(object):
return track, sector
def check_size(self, size):
raise InvalidDiskImage("BaseHeader subclasses need custom checks for size")
raise errors.InvalidDiskImage("BaseHeader subclasses need custom checks for size")
def strict_check(self, image):
pass
@ -168,12 +168,12 @@ class DiskImageBase(object):
@classmethod
def new_header(cls, diskimage, format="ATR"):
raise NotImplementedError
raise errors.NotImplementedError
def as_new_format(self, format="ATR"):
""" Create a new disk image in the specified format
"""
raise NotImplementedError
raise errors.NotImplementedError
def save(self, filename=""):
if not filename:
@ -192,7 +192,7 @@ class DiskImageBase(object):
def check_sane(self):
if not self.all_sane:
raise InvalidDiskImage("Invalid directory entries; may be boot disk")
raise errors.InvalidDiskImage("Invalid directory entries; may be boot disk")
def read_header(self):
return BaseHeader()
@ -277,7 +277,7 @@ class DiskImageBase(object):
for dirent in self.files:
if filename == dirent.filename:
return dirent
raise FileNotFound("%s not found on disk" % str(filename))
raise errors.FileNotFound("%s not found on disk" % str(filename))
def find_file(self, filename):
dirent = self.find_dirent(filename)
@ -295,17 +295,17 @@ class DiskImageBase(object):
for dirent in self.files:
try:
segment = self.get_file_segment(dirent)
except InvalidFile as e:
except errors.InvalidFile as e:
segment = EmptySegment(self.rawdata, name=dirent.filename, error=str(e))
segments.append(segment)
return segments
def create_executable_file_image(self, segments, run_addr=None):
raise NotImplementedError
raise errors.NotImplementedError
@classmethod
def create_boot_image(self, segments, run_addr=None):
raise NotImplementedError
raise errors.NotImplementedError
# file writing methods
@ -341,7 +341,7 @@ class DiskImageBase(object):
self.write_sector_list(sector_list)
self.write_sector_list(vtoc)
self.write_sector_list(directory)
except AtrError:
except errors.AtrError:
self.rollback_transaction(state)
raise
finally:
@ -375,7 +375,7 @@ class DiskImageBase(object):
directory.remove_dirent(self, dirent, vtoc, sector_list)
self.write_sector_list(vtoc)
self.write_sector_list(directory)
except AtrError:
except errors.AtrError:
self.rollback_transaction(state)
raise
finally:
@ -388,7 +388,7 @@ class DiskImageBase(object):
for sector_num, pos, size in vtoc.iter_free_sectors():
if _xd: log.debug("shredding: sector %s at %d, fill value=%d" % (sector_num, pos, fill_value))
self.bytes[pos:pos + size] = fill_value
except AtrError:
except errors.AtrError:
self.rollback_transaction(state)
raise
finally:

View File

@ -1,6 +1,6 @@
import numpy as np
from .errors import *
from . import errors
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
@ -320,7 +320,7 @@ class Dos33Dirent(Dirent):
def start_read(self, image):
if not self.is_sane:
raise InvalidDirent("Invalid directory entry '%s'" % str(self))
raise errors.InvalidDirent("Invalid directory entry '%s'" % str(self))
self.get_track_sector_list(image)
if _xd: log.debug("start_read: %s, t/s list: %s" % (str(self), str(self.sector_map)))
self.current_sector_index = 0
@ -369,7 +369,7 @@ class Dos33Header(BaseHeader):
def check_size(self, size):
if size != 143360:
raise InvalidDiskImage("Incorrect size for DOS 3.3 image")
raise errors.InvalidDiskImage("Incorrect size for DOS 3.3 image")
self.image_size = size
self.first_vtoc = 17 * 16
self.num_vtoc = 1
@ -408,7 +408,7 @@ class Dos33DiskImage(DiskImageBase):
data, style = self.get_sectors(0)
magic = data[0:4]
if (magic == [1, 56, 176, 3]).all():
raise InvalidDiskImage("ProDOS format found; not DOS 3.3 image")
raise errors.InvalidDiskImage("ProDOS format found; not DOS 3.3 image")
swap_order = False
data, style = self.get_sectors(self.header.first_vtoc)
if data[3] == 3:
@ -418,7 +418,7 @@ class Dos33DiskImage(DiskImageBase):
log.warning("DOS 3.3 byte swap needed!")
swap_order = True
else:
raise InvalidDiskImage("Invalid VTOC location for DOS 3.3")
raise errors.InvalidDiskImage("Invalid VTOC location for DOS 3.3")
vtoc_type = np.dtype([
@ -563,7 +563,7 @@ class Dos33DiskImage(DiskImageBase):
next_sector = self.header.sector_from_track(raw[1], raw[2])
if _xd: log.debug("checking catalog sector %d, next catalog sector: %d" % (sector_num, next_sector))
if next_sector == 0:
raise NoSpaceInDirectory("No space left in catalog")
raise errors.NoSpaceInDirectory("No space left in catalog")
return sector_num, next_sector
def get_file_segment(self, dirent):
@ -609,7 +609,7 @@ class Dos33DiskImage(DiskImageBase):
found = True
break
if not found:
raise InvalidBinaryFile("Run address points outside data segments")
raise errors.InvalidBinaryFile("Run address points outside data segments")
origin -= 3
hi, lo = divmod(run_addr, 256)
raw = SegmentData([0x4c, lo, hi])
@ -708,7 +708,7 @@ class ProdosDiskImage(DiskImageBase):
# https://github.com/RasppleII/a2server but it seems that
# more magic bytes might be acceptable?
#raise InvalidDiskImage("No ProDOS header info found")
#raise errors.InvalidDiskImage("No ProDOS header info found")
pass
raise UnsupportedDiskImage("ProDOS format found but not supported")
raise InvalidDiskImage("Not ProDOS format")
raise errors.UnsupportedDiskImage("ProDOS format found but not supported")
raise errors.InvalidDiskImage("Not ProDOS format")

View File

@ -1,6 +1,6 @@
import numpy as np
from .errors import *
from . import errors
from .ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment, get_xex
from .segments import SegmentData
@ -41,7 +41,7 @@ class KBootImage(AtariDosDiskImage):
def check_sane(self):
if not self.all_sane:
raise InvalidDiskImage("Doesn't seem to be KBoot header")
raise errors.InvalidDiskImage("Doesn't seem to be KBoot header")
def get_vtoc(self):
pass

View File

@ -2,7 +2,7 @@ import zipfile
import numpy as np
from .errors import *
from . import errors
from .segments import SegmentData, EmptySegment, ObjSegment
from .diskimages import DiskImageBase
from .utils import to_numpy
@ -20,7 +20,7 @@ class MameZipImage(DiskImageBase):
self.check_zip_size(zf)
self.create_rawdata(zf)
else:
raise InvalidDiskImage("Not a MAME zip file")
raise errors.InvalidDiskImage("Not a MAME zip file")
DiskImageBase.__init__(self, self.rawdata, filename)
def __str__(self):
@ -39,7 +39,7 @@ class MameZipImage(DiskImageBase):
for item in zf.infolist():
_, r = divmod(item.file_size, 16)
if r > 0:
raise InvalidDiskImage("zip entry not 16 byte multiple")
raise errors.InvalidDiskImage("zip entry not 16 byte multiple")
def create_rawdata(self, zf):
roms = []

View File

@ -8,7 +8,7 @@ from .cartridge import AtariCartImage, get_known_carts
from .mame import MameZipImage
from .dos33 import Dos33DiskImage, ProdosDiskImage, Dos33BinFile
from .standard_delivery import StandardDeliveryImage
from .errors import *
from . import errors
from .magic import guess_detail_for_mime
import logging
@ -70,10 +70,10 @@ class SegmentParser(object):
self.image = self.get_image(r)
self.check_image()
self.image.parse_segments()
except UnsupportedDiskImage:
except errors.UnsupportedDiskImage:
raise
except AtrError as e:
raise InvalidSegmentParser(e)
except errors.AtrError as e:
raise errors.InvalidSegmentParser(e)
self.segments.extend(self.image.segments)
def get_image(self, r):
@ -83,8 +83,8 @@ class SegmentParser(object):
if self.strict:
try:
self.image.strict_check()
except AtrError as e:
raise InvalidSegmentParser(e)
except errors.AtrError as e:
raise errors.InvalidSegmentParser(e)
else:
self.image.relaxed_check()
@ -164,7 +164,7 @@ def guess_parser_for_mime(mime, r, verbose=False):
try:
found = parser(r, True)
break
except InvalidSegmentParser as e:
except errors.InvalidSegmentParser as e:
if verbose:
log.info("parser isn't %s: %s" % (parser.__name__, str(e)))
pass
@ -207,7 +207,7 @@ def parsers_for_filename(name):
_, name = name.rsplit(".", 1)
except ValueError:
pass
raise InvalidDiskImage("no disk image formats that match '%s'" % name)
raise errors.InvalidDiskImage("no disk image formats that match '%s'" % name)
return matches

View File

@ -3,7 +3,7 @@ import io
import numpy as np
from .errors import *
from . import errors
from .utils import to_numpy, to_numpy_list, uuid
from functools import reduce
@ -194,7 +194,7 @@ class SegmentData(object):
newsize = len(base_raw)
oldsize = len(self.data_base)
if newsize < oldsize:
raise NotImplementedError("Can't truncate yet")
raise errors.NotImplementedError("Can't truncate yet")
if self.is_indexed:
self.data.np_data = base_raw.data
self.data.base = base_raw.data.base

View File

@ -1,6 +1,6 @@
import numpy as np
from .errors import *
from . import errors
from .ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment
from .segments import DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentSaver
@ -90,7 +90,7 @@ class SpartaDosDirent(AtariDosDirent):
def start_read(self, image):
if not self.is_sane:
log.debug("Invalid directory entry '%s', starting_sector=%s" % (str(self), self.starting_sector))
raise InvalidDirent("Invalid directory entry '%s'" % str(self))
raise errors.InvalidDirent("Invalid directory entry '%s'" % str(self))
self.sector_map = image.get_sector_map(self.starting_sector)
self.sector_map_index = 0
self.length_remaining = self.length
@ -159,7 +159,7 @@ class SpartaDosDiskImage(AtariDosDiskImage):
num = self.header.max_sectors
self.is_sane = self.total_sectors == num and values['first_free'] <= num and self.first_bitmap <= num and self.root_dir <= num and self.fs_version in [0x11, 0x20, 0x21] and self.sector_size != -1
if not self.is_sane:
raise InvalidDiskImage("Invalid SpartaDos parameters in boot header")
raise errors.InvalidDiskImage("Invalid SpartaDos parameters in boot header")
def get_vtoc(self):
pass

View File

@ -1,6 +1,6 @@
import numpy as np
from .errors import *
from . import errors
from .segments import SegmentData
from .diskimages import BaseHeader, DiskImageBase
@ -20,14 +20,14 @@ class StandardDeliveryHeader(BaseHeader):
if np.all(data == (0x01, 0xa8, 0xee, 0x06, 0x08)):
log.debug("Found 48k loader")
else:
raise InvalidDiskImage("No %s boot header" % self.file_format)
raise errors.InvalidDiskImage("No %s boot header" % self.file_format)
def __str__(self):
return "Standard Delivery Boot Disk (size=%d (%dx%dB)" % (self.file_format, self.image_size, self.max_sectors, self.sector_size)
def check_size(self, size):
if size != 143360:
raise InvalidDiskImage("Incorrect size for Standard Delivery image")
raise errors.InvalidDiskImage("Incorrect size for Standard Delivery image")
self.image_size = size
self.tracks_per_disk = 35
self.sectors_per_track = 16

View File

@ -3,7 +3,7 @@ import uuid as stdlib_uuid
import numpy as np
from .errors import *
from . import errors
import logging
log = logging.getLogger(__name__)
@ -159,28 +159,28 @@ class Dirent(object):
self.file_num = file_num
def __eq__(self, other):
raise NotImplementedError
raise errors.NotImplementedError
def extra_metadata(self, image):
raise NotImplementedError
raise errors.NotImplementedError
def mark_deleted(self):
raise NotImplementedError
raise errors.NotImplementedError
def parse_raw_dirent(self, image, bytes):
raise NotImplementedError
raise errors.NotImplementedError
def encode_dirent(self):
raise NotImplementedError
raise errors.NotImplementedError
def get_sectors_in_vtoc(self, image):
raise NotImplementedError
raise errors.NotImplementedError
def start_read(self, image):
raise NotImplementedError
raise errors.NotImplementedError
def read_sector(self, image):
raise NotImplementedError
raise errors.NotImplementedError
class Directory(BaseSectorList):
@ -205,7 +205,7 @@ class Directory(BaseSectorList):
return i
used.add(i)
if self.num_dirents > 0 and (len(used) >= self.num_dirents):
raise NoSpaceInDirectory()
raise errors.NoSpaceInDirectory()
i += 1
else:
i = 0
@ -229,7 +229,7 @@ class Directory(BaseSectorList):
for dirent in list(self.dirents.values()):
if filename == dirent.filename:
return dirent
raise FileNotFound("%s not found on disk" % filename)
raise errors.FileNotFound("%s not found on disk" % filename)
def save_dirent(self, image, dirent, vtoc, sector_list):
vtoc.assign_sector_numbers(dirent, sector_list)
@ -244,7 +244,7 @@ class Directory(BaseSectorList):
@property
def dirent_class(self):
raise NotImplementedError
raise errors.NotImplementedError
def calc_sectors(self, image):
self.sectors = []
@ -270,10 +270,10 @@ class Directory(BaseSectorList):
return self.sector_class(self.sector_size)
def encode_empty(self):
raise NotImplementedError
raise errors.NotImplementedError
def encode_dirent(self, dirent):
raise NotImplementedError
raise errors.NotImplementedError
def store_encoded(self, data):
while True:
@ -291,7 +291,7 @@ class Directory(BaseSectorList):
self.set_sector_numbers(image)
def set_sector_numbers(self, image):
raise NotImplementedError
raise errors.NotImplementedError
class VTOC(BaseSectorList):
@ -317,7 +317,7 @@ class VTOC(BaseSectorList):
yield i, pos, size
def parse_segments(self, segments):
raise NotImplementedError
raise errors.NotImplementedError
def assign_sector_numbers(self, dirent, sector_list):
""" Map out the sectors and link the sectors together
@ -328,7 +328,7 @@ class VTOC(BaseSectorList):
num = len(sector_list)
order = self.reserve_space(num)
if len(order) != num:
raise InvalidFile("VTOC reserved space for %d sectors. Sectors needed: %d" % (len(order), num))
raise errors.InvalidFile("VTOC reserved space for %d sectors. Sectors needed: %d" % (len(order), num))
file_length = 0
last_sector = None
for sector, sector_num in zip(sector_list.sectors, order):
@ -357,10 +357,10 @@ class VTOC(BaseSectorList):
if _xd: log.debug("Found sector %d free" % num)
self.sector_map[num] = 0
return num
raise NotEnoughSpaceOnDisk("No space left in VTOC")
raise errors.NotEnoughSpaceOnDisk("No space left in VTOC")
def calc_bitmap(self):
raise NotImplementedError
raise errors.NotImplementedError
def free_sector_list(self, sector_list):
for sector in sector_list:

View File

@ -4,8 +4,8 @@ import numpy as np
from mock import *
from atrcopy import SegmentData, AtariDosDiskImage, Dos33DiskImage,InvalidBinaryFile
from atrcopy.errors import *
from atrcopy import SegmentData, AtariDosDiskImage, Dos33DiskImage
from atrcopy import errors
class BaseFilesystemModifyTest(object):
@ -85,7 +85,7 @@ class BaseFilesystemModifyTest(object):
data = np.arange(50*1024, dtype=np.uint8)
self.image.write_file("RAMP50K.BIN", None, data)
assert len(self.image.files) == self.num_files_in_sample + 1
with pytest.raises(NotEnoughSpaceOnDisk):
with pytest.raises(errors.NotEnoughSpaceOnDisk):
huge = np.arange(500*1024, dtype=np.uint8)
self.image.write_file("RAMP500K.BIN", None, huge)
assert len(self.image.files) == self.num_files_in_sample + 1

View File

@ -2,7 +2,8 @@ from __future__ import print_function
from builtins import object
from mock import *
from atrcopy import SegmentData, AtariDosFile, InvalidBinaryFile, DefaultSegment, XexContainerSegment
from atrcopy import SegmentData, AtariDosFile, DefaultSegment, XexContainerSegment, errors
class TestAtariDosFile(object):
@ -41,7 +42,7 @@ class TestAtariDosFile(object):
bytes = [0xff, 0xff, 0x00, 0x60, 0x00, 0x00, 1, 2]
rawdata = SegmentData(bytes)
image = AtariDosFile(rawdata)
with pytest.raises(InvalidBinaryFile):
with pytest.raises(errors.InvalidBinaryFile):
image.parse_segments()

View File

@ -3,7 +3,8 @@ from __future__ import division
from builtins import object
from mock import *
from atrcopy import AtariCartImage, SegmentData, InvalidDiskImage
from atrcopy import AtariCartImage, SegmentData
from atrcopy import errors
class TestAtariCart(object):
@ -60,16 +61,16 @@ class TestAtariCart(object):
# check for error because invalid data in cart image itself
data = self.get_cart(k_size, 1337)
rawdata = SegmentData(data)
with pytest.raises(InvalidDiskImage):
with pytest.raises(errors.InvalidDiskImage):
image = AtariCartImage(rawdata, 1337)
with pytest.raises(InvalidDiskImage):
with pytest.raises(errors.InvalidDiskImage):
image = AtariCartImage(rawdata, 12)
# check for error with valid cart image, but invalid cart type supplied
# to the image parser
data = self.get_cart(k_size, 12)
rawdata = SegmentData(data)
with pytest.raises(InvalidDiskImage):
with pytest.raises(errors.InvalidDiskImage):
image = AtariCartImage(rawdata, 1337)

View File

@ -4,8 +4,8 @@ import numpy as np
from mock import *
from atrcopy import SegmentData, AtariDosDiskImage, Dos33DiskImage,InvalidBinaryFile, DefaultSegment
from atrcopy.errors import *
from atrcopy import SegmentData, AtariDosDiskImage, Dos33DiskImage, DefaultSegment
from atrcopy import errors
def get_image(file_name, diskimage_type):
@ -39,8 +39,8 @@ class BaseCreateTest(object):
image = get_image(sample_file, diskimage_type)
segments = self.get_exe_segments()
try:
_ = issubclass(AtrError, expected)
with pytest.raises(InvalidBinaryFile) as e:
_ = issubclass(errors.AtrError, expected)
with pytest.raises(errors.InvalidBinaryFile) as e:
file_data, filetype = image.create_executable_file_image(segments, run_addr)
except TypeError:
file_data, filetype = image.create_executable_file_image(segments, run_addr)
@ -53,11 +53,11 @@ class TestAtariDosSDImage(BaseCreateTest):
diskimage_type = AtariDosDiskImage
@pytest.mark.parametrize("run_addr,expected", [
(0x2000, InvalidBinaryFile),
(0x2000, errors.InvalidBinaryFile),
(None, (2 + 6 + (4 + 0x1000) + (4 + 0x1000))),
(0x4000, (2 + 6 + (4 + 0x1000) + (4 + 0x1000))),
(0x8000, (2 + 6 + (4 + 0x1000) + (4 + 0x1000))),
(0xffff, InvalidBinaryFile),
(0xffff, errors.InvalidBinaryFile),
])
def test_exe(self, run_addr, expected, sample_file):
self.check_exe(sample_file, self.diskimage_type, run_addr, expected)
@ -68,11 +68,11 @@ class TestDos33Image(BaseCreateTest):
diskimage_type = Dos33DiskImage
@pytest.mark.parametrize("run_addr,expected", [
(0x2000, InvalidBinaryFile),
(0x2000, errors.InvalidBinaryFile),
(None, (4 + (0x9000 - 0x4000))),
(0x4000, (4 + (0x9000 - 0x4000))),
(0x8000, (4 + 3 + (0x9000 - 0x4000))),
(0xffff, InvalidBinaryFile),
(0xffff, errors.InvalidBinaryFile),
])
def test_exe(self, run_addr, expected, sample_file):
self.check_exe(sample_file, self.diskimage_type, run_addr, expected)

View File

@ -8,7 +8,7 @@ import numpy as np
import pytest
from atrcopy import DefaultSegment, SegmentData, get_xex, interleave_segments, user_bit_mask, diff_bit_mask
from atrcopy.errors import *
from atrcopy import errors
from functools import reduce
@ -38,7 +38,7 @@ class TestSegment1(object):
s[1].set_comment_at(10, "comment 10")
s[1].set_comment_at(100, "comment 100")
print(list(s[1].iter_comments_in_segment()))
with pytest.raises(InvalidBinaryFile):
with pytest.raises(errors.InvalidBinaryFile):
seg, subseg = get_xex(s, 0xbeef)
seg, subseg = get_xex(s)
assert tuple(seg.data[0:2]) == (0xff, 0xff)