mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2024-11-29 11:51:14 +00:00
Added dummy diskimage to allow writing assembled files to local disk
This commit is contained in:
parent
e4ce309bd3
commit
dff073208f
@ -23,6 +23,7 @@ from .cartridge import A8CartHeader, AtariCartImage
|
||||
from .parsers import SegmentParser, DefaultSegmentParser, guess_parser_for_mime, guess_parser_for_system, guess_container, iter_parsers, iter_known_segment_parsers, mime_parse_order, parsers_for_filename
|
||||
from .magic import guess_detail_for_mime
|
||||
from .utils import to_numpy, text_to_int
|
||||
from .dummy import LocalFilesystem
|
||||
|
||||
|
||||
def process(image, dirent, options):
|
||||
@ -54,27 +55,30 @@ def process(image, dirent, options):
|
||||
|
||||
|
||||
def find_diskimage(filename):
|
||||
with open(filename, "rb") as fh:
|
||||
if options.verbose:
|
||||
print("Loading file %s" % filename)
|
||||
data = to_numpy(fh.read())
|
||||
parser = None
|
||||
container = guess_container(data, options.verbose)
|
||||
if container is not None:
|
||||
data = container.unpacked
|
||||
rawdata = SegmentData(data)
|
||||
for mime in mime_parse_order:
|
||||
if options.verbose:
|
||||
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)
|
||||
mime2 = guess_detail_for_mime(mime, rawdata, parser)
|
||||
if mime != mime2 and options.verbose:
|
||||
print("Signature match: %s" % mime2)
|
||||
break
|
||||
if filename == ".":
|
||||
parser = LocalFilesystem()
|
||||
else:
|
||||
with open(filename, "rb") as fh:
|
||||
if options.verbose:
|
||||
print("Loading file %s" % filename)
|
||||
data = to_numpy(fh.read())
|
||||
parser = None
|
||||
container = guess_container(data, options.verbose)
|
||||
if container is not None:
|
||||
data = container.unpacked
|
||||
rawdata = SegmentData(data)
|
||||
for mime in mime_parse_order:
|
||||
if options.verbose:
|
||||
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)
|
||||
mime2 = guess_detail_for_mime(mime, rawdata, parser)
|
||||
if mime != mime2 and options.verbose:
|
||||
print("Signature match: %s" % mime2)
|
||||
break
|
||||
if parser is None:
|
||||
raise errors.UnsupportedDiskImage("Unknown disk image type")
|
||||
else:
|
||||
|
41
atrcopy/dummy.py
Normal file
41
atrcopy/dummy.py
Normal file
@ -0,0 +1,41 @@
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
|
||||
from . import errors
|
||||
from .segments import SegmentData, EmptySegment, ObjSegment
|
||||
from .diskimages import DiskImageBase
|
||||
from .utils import to_numpy
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LocalFilesystemImage(DiskImageBase):
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
||||
def __str__(self, path="."):
|
||||
return f"Local filesystem output to: {self.path}"
|
||||
|
||||
def save(self, filename=""):
|
||||
# This is to save the disk image containing the files on the disk image
|
||||
# to the local disk, which doesn't make sense when the disk image is
|
||||
# the filesystem.
|
||||
pass
|
||||
|
||||
def find_dirent(self, name):
|
||||
path = os.path.join(self.path, name)
|
||||
if os.path.exists(path):
|
||||
return True
|
||||
raise errors.FileNotFound("%s not found on disk" % str(name))
|
||||
|
||||
def write_file(self, name, filetype, data):
|
||||
path = os.path.join(self.path, name)
|
||||
with open(path, "wb") as fh:
|
||||
fh.write(data)
|
||||
|
||||
|
||||
class LocalFilesystem():
|
||||
def __init__(self, path="."):
|
||||
self.image = LocalFilesystemImage(path)
|
Loading…
Reference in New Issue
Block a user