PEP8 whitespace fixes

This commit is contained in:
Rob McMullen 2017-03-23 10:06:37 -07:00
parent 6f29e6053a
commit c897460df0
12 changed files with 219 additions and 186 deletions

View File

@ -45,6 +45,7 @@ def process(image, dirent, options):
else: else:
print dirent print dirent
def find_diskimage(filename): def find_diskimage(filename):
try: try:
with open(filename, "rb") as fh: with open(filename, "rb") as fh:
@ -72,6 +73,7 @@ def find_diskimage(filename):
parser.image.ext = "" parser.image.ext = ""
return parser return parser
def extract_files(image, files): def extract_files(image, files):
for name in files: for name in files:
try: try:
@ -85,6 +87,7 @@ def extract_files(image, files):
with open(dirent.filename, "wb") as fh: with open(dirent.filename, "wb") as fh:
fh.write(data) fh.write(data)
def save_file(image, name, filetype, data): def save_file(image, name, filetype, data):
try: try:
dirent = image.find_dirent(name) dirent = image.find_dirent(name)
@ -114,6 +117,7 @@ def add_files(image, files):
if changed: if changed:
image.save() image.save()
def remove_files(image, files): def remove_files(image, files):
changed = False changed = False
for name in files: for name in files:
@ -129,6 +133,7 @@ def remove_files(image, files):
if changed: if changed:
image.save() image.save()
def list_files(image, files): def list_files(image, files):
files = set(files) files = set(files)
for dirent in image.files: for dirent in image.files:
@ -137,6 +142,7 @@ def list_files(image, files):
if options.metadata: if options.metadata:
print dirent.extra_metadata(image) print dirent.extra_metadata(image)
def assemble(image, source_files, data_files): def assemble(image, source_files, data_files):
if source_files: if source_files:
try: try:
@ -170,6 +176,7 @@ def assemble(image, source_files, data_files):
if changed: if changed:
image.save() image.save()
def shred_image(image, value=0): 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: if not options.dry_run:

View File

@ -256,6 +256,7 @@ class AtariDosFile(object):
Ref: http://www.atarimax.com/jindroush.atari.org/afmtexe.html Ref: http://www.atarimax.com/jindroush.atari.org/afmtexe.html
""" """
def __init__(self, rawdata): def __init__(self, rawdata):
self.rawdata = rawdata self.rawdata = rawdata
self.size = len(rawdata) self.size = len(rawdata)
@ -746,6 +747,7 @@ def get_xex(segments, runaddr=None):
i += len(s) i += len(s)
return bytes return bytes
def add_atr_header(bytes): def add_atr_header(bytes):
header = AtrHeader(create=True) header = AtrHeader(create=True)
header.check_size(len(bytes)) header.check_size(len(bytes))

View File

@ -95,6 +95,7 @@ known_cart_types = [
known_cart_type_map = {c[0]:i for i, c in enumerate(known_cart_types)} known_cart_type_map = {c[0]:i for i, c in enumerate(known_cart_types)}
def get_known_carts(): def get_known_carts():
grouped = defaultdict(list) grouped = defaultdict(list)
for c in known_cart_types[1:]: for c in known_cart_types[1:]:
@ -102,6 +103,7 @@ def get_known_carts():
grouped[size].append(c) grouped[size].append(c)
return grouped return grouped
def get_cart(cart_type): def get_cart(cart_type):
try: try:
return known_cart_types[known_cart_type_map[cart_type]] return known_cart_types[known_cart_type_map[cart_type]]

View File

@ -605,10 +605,6 @@ class Dos33DiskImage(DiskImageBase):
return image, 'B' return image, 'B'
class ProdosHeader(Dos33Header): class ProdosHeader(Dos33Header):
file_format = "ProDOS" file_format = "ProDOS"

View File

@ -1,12 +1,15 @@
class AtrError(RuntimeError): class AtrError(RuntimeError):
pass pass
class InvalidAtrHeader(AtrError): class InvalidAtrHeader(AtrError):
pass pass
class InvalidCartHeader(AtrError): class InvalidCartHeader(AtrError):
pass pass
class InvalidDiskImage(AtrError): class InvalidDiskImage(AtrError):
""" Disk image is not recognized by a parser. """ Disk image is not recognized by a parser.
@ -15,6 +18,7 @@ class InvalidDiskImage(AtrError):
""" """
pass pass
class UnsupportedDiskImage(AtrError): class UnsupportedDiskImage(AtrError):
""" Disk image is recognized by a parser but it isn't supported yet. """ Disk image is recognized by a parser but it isn't supported yet.
@ -22,32 +26,42 @@ class UnsupportedDiskImage(AtrError):
""" """
pass pass
class InvalidDirent(AtrError): class InvalidDirent(AtrError):
pass pass
class LastDirent(AtrError): class LastDirent(AtrError):
pass pass
class InvalidFile(AtrError): class InvalidFile(AtrError):
pass pass
class FileNumberMismatchError164(InvalidFile): class FileNumberMismatchError164(InvalidFile):
pass pass
class ByteNotInFile166(InvalidFile): class ByteNotInFile166(InvalidFile):
pass pass
class InvalidBinaryFile(InvalidFile): class InvalidBinaryFile(InvalidFile):
pass pass
class InvalidSegmentParser(AtrError): class InvalidSegmentParser(AtrError):
pass pass
class NoSpaceInDirectory(AtrError): class NoSpaceInDirectory(AtrError):
pass pass
class NotEnoughSpaceOnDisk(AtrError): class NotEnoughSpaceOnDisk(AtrError):
pass pass
class FileNotFound(AtrError): class FileNotFound(AtrError):
pass pass

View File

@ -57,8 +57,10 @@ class KBootImage(AtariDosDiskImage):
raw = self.rawdata[start:end] raw = self.rawdata[start:end]
return XexSegment(raw, 0, 0, start, end, name="KBoot Executable") 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 = '\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_string(data, offset, string, color):
s = np.fromstring(string.upper(), dtype=np.uint8) - 32 # convert to internal s = np.fromstring(string.upper(), dtype=np.uint8) - 32 # convert to internal
s = s | color s = s | color
@ -66,6 +68,7 @@ def insert_string(data, offset, string, color):
tx = offset + (20 - count)/ 2 tx = offset + (20 - count)/ 2
data[tx:tx+count] = s 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="DEMO", author="an atari user"):
sec_size = 128 sec_size = 128
xex_size = len(bytes) xex_size = len(bytes)

View File

@ -122,6 +122,7 @@ def guess_parser_for_mime(mime, r, verbose=False):
pass pass
return found return found
def guess_parser_for_system(mime_base, r): def guess_parser_for_system(mime_base, r):
for mime in mime_parse_order: for mime in mime_parse_order:
if mime.startswith(mime_base): if mime.startswith(mime_base):
@ -130,6 +131,7 @@ def guess_parser_for_system(mime_base, r):
return mime, p return mime, p
return None, None return None, None
def iter_parsers(r): def iter_parsers(r):
for mime in mime_parse_order: for mime in mime_parse_order:
p = guess_parser_for_mime(mime, r) p = guess_parser_for_mime(mime, r)
@ -197,6 +199,7 @@ known_segment_parsers = [DefaultSegmentParser]
for mime in mime_parse_order: for mime in mime_parse_order:
known_segment_parsers.extend(mime_parsers[mime]) known_segment_parsers.extend(mime_parsers[mime])
def iter_known_segment_parsers(): def iter_known_segment_parsers():
yield "application/octet-stream", "", [DefaultSegmentParser] yield "application/octet-stream", "", [DefaultSegmentParser]
for mime in mime_parse_order: for mime in mime_parse_order:

View File

@ -16,6 +16,7 @@ match_bit_mask = 0x20
comment_bit_mask = 0x40 comment_bit_mask = 0x40
selected_bit_mask = 0x80 selected_bit_mask = 0x80
def get_style_bits(match=False, comment=False, selected=False, data=False, diff=False, user=0): def get_style_bits(match=False, comment=False, selected=False, data=False, diff=False, user=0):
""" Return an int value that contains the specified style bits set. """ Return an int value that contains the specified style bits set.
@ -41,6 +42,7 @@ def get_style_bits(match=False, comment=False, selected=False, data=False, diff=
style_bits |= selected_bit_mask style_bits |= selected_bit_mask
return style_bits return style_bits
def get_style_mask(**kwargs): def get_style_mask(**kwargs):
"""Get the bit mask that, when anded with data, will turn off the """Get the bit mask that, when anded with data, will turn off the
selected bits selected bits
@ -70,6 +72,7 @@ class OrderWrapper(object):
intermediate layer is needed that defines the __setitem__ method that intermediate layer is needed that defines the __setitem__ method that
explicitly references the byte ordering in the data array. explicitly references the byte ordering in the data array.
""" """
def __init__(self, data, byte_order): def __init__(self, data, byte_order):
self.np_data = data self.np_data = data
self.base = data.base # base array for numpy bounds determination self.base = data.base # base array for numpy bounds determination
@ -109,6 +112,7 @@ class OrderWrapper(object):
def tostring(self): def tostring(self):
return self.np_data[self.order].tostring() return self.np_data[self.order].tostring()
class UserExtraData(object): class UserExtraData(object):
def __init__(self): def __init__(self):
self.comments = dict() self.comments = dict()
@ -492,7 +496,6 @@ class DefaultSegment(object):
if slot in e: if slot in e:
self.set_style_ranges(e[slot], user=i) self.set_style_ranges(e[slot], user=i)
def __str__(self): def __str__(self):
if self.start_addr > 0: if self.start_addr > 0:
origin = " @ %04x" % (self.start_addr) origin = " @ %04x" % (self.start_addr)
@ -1055,6 +1058,7 @@ class RawTrackSectorSegment(RawSectorsSegment):
return "t%02ds%02d:%02x" % (t, s, byte) return "t%02ds%02d:%02x" % (t, s, byte)
return "t%02ds%02d:%02X" % (t, s, byte) return "t%02ds%02d:%02X" % (t, s, byte)
def interleave_indexes(segments, num_bytes): def interleave_indexes(segments, num_bytes):
num_segments = len(segments) num_segments = len(segments)
size = len(segments[0]) size = len(segments[0])
@ -1074,6 +1078,7 @@ def interleave_indexes(segments, num_bytes):
start += 1 start += 1
return interleave return interleave
def interleave_segments(segments, num_bytes): def interleave_segments(segments, num_bytes):
new_index = interleave_indexes(segments, num_bytes) new_index = interleave_indexes(segments, num_bytes)
data_base, style_base = segments[0].rawdata.get_bases() data_base, style_base = segments[0].rawdata.get_bases()

View File

@ -137,6 +137,7 @@ class Dirent(object):
"""Abstract base class for a directory entry """Abstract base class for a directory entry
""" """
def __init__(self, file_num=0): def __init__(self, file_num=0):
self.file_num = file_num self.file_num = file_num