mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2025-01-18 00:31:39 +00:00
Added entry point for omnivore framework loader
This commit is contained in:
parent
0abcf2d929
commit
b8a858ee6d
@ -54,6 +54,32 @@ def process(image, dirent, options):
|
||||
print(dirent)
|
||||
|
||||
|
||||
def find_diskimage_from_data(data, verbose=False):
|
||||
data = to_numpy(data)
|
||||
parser = None
|
||||
container = guess_container(data, verbose)
|
||||
if container is not None:
|
||||
data = container.unpacked
|
||||
rawdata = SegmentData(data)
|
||||
mime, parser = guess_parser_by_size(rawdata)
|
||||
if parser is None:
|
||||
for mime in mime_parse_order:
|
||||
if verbose:
|
||||
print("Trying MIME type %s" % mime)
|
||||
parser = guess_parser_for_mime(mime, rawdata, verbose)
|
||||
if parser is None:
|
||||
continue
|
||||
if verbose:
|
||||
print("Found parser %s" % parser.menu_name)
|
||||
mime2 = guess_detail_for_mime(mime, rawdata, parser)
|
||||
if mime != mime2 and verbose:
|
||||
print("Signature match: %s" % mime2)
|
||||
break
|
||||
if parser is None:
|
||||
raise errors.UnsupportedDiskImage("Unknown disk image type")
|
||||
return parser, mime
|
||||
|
||||
|
||||
def find_diskimage(filename, verbose=False):
|
||||
if filename == ".":
|
||||
parser = LocalFilesystem()
|
||||
@ -62,31 +88,10 @@ def find_diskimage(filename, verbose=False):
|
||||
if verbose:
|
||||
print("Loading file %s" % filename)
|
||||
data = to_numpy(fh.read())
|
||||
parser = None
|
||||
container = guess_container(data, verbose)
|
||||
if container is not None:
|
||||
data = container.unpacked
|
||||
rawdata = SegmentData(data)
|
||||
mime, parser = guess_parser_by_size(rawdata)
|
||||
if parser is None:
|
||||
for mime in mime_parse_order:
|
||||
if verbose:
|
||||
print("Trying MIME type %s" % mime)
|
||||
parser = guess_parser_for_mime(mime, rawdata, verbose)
|
||||
if parser is None:
|
||||
continue
|
||||
if verbose:
|
||||
print("Found parser %s" % parser.menu_name)
|
||||
mime2 = guess_detail_for_mime(mime, rawdata, parser)
|
||||
if mime != mime2 and verbose:
|
||||
print("Signature match: %s" % mime2)
|
||||
break
|
||||
if parser is None:
|
||||
raise errors.UnsupportedDiskImage("Unknown disk image type")
|
||||
else:
|
||||
parser.image.filename = filename
|
||||
parser.image.ext = ""
|
||||
return parser
|
||||
parser, mime = find_diskimage_from_data(data, verbose)
|
||||
parser.image.filename = filename
|
||||
parser.image.ext = ""
|
||||
return parser
|
||||
|
||||
|
||||
def extract_files(image, files):
|
||||
|
21
atrcopy/omnivore_framework_loader.py
Normal file
21
atrcopy/omnivore_framework_loader.py
Normal file
@ -0,0 +1,21 @@
|
||||
from . import find_diskimage_from_data, errors
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def identify_mime(header):
|
||||
mime_type = None
|
||||
try:
|
||||
parser, mime_type = find_diskimage_from_data(header, True)
|
||||
except (errors.UnsupportedContainer, errors.UnsupportedDiskImage, IOError) as e:
|
||||
print(f"error in atrcopy parser: {e}")
|
||||
else:
|
||||
print(f"{parser.image}: {mime_type}")
|
||||
|
||||
if mime_type:
|
||||
log.debug(f"atrcopy loader: identified {mime_type}")
|
||||
return dict(mime=mime_type, ext="")
|
||||
else:
|
||||
log.debug(f"atrcopy loader: unidentified")
|
||||
return None
|
1
setup.py
1
setup.py
@ -23,6 +23,7 @@ setup(name="atrcopy",
|
||||
packages=["atrcopy"],
|
||||
include_package_data=True,
|
||||
scripts=scripts,
|
||||
entry_points={"omnivore_framework.loaders": 'atrcopy = atrcopy.omnivore_framework_loader'},
|
||||
description="Utility to manage file systems on Atari 8-bit (DOS 2) and Apple ][ (DOS 3.3) disk images.",
|
||||
long_description=long_description,
|
||||
license="GPL",
|
||||
|
Loading…
x
Reference in New Issue
Block a user