mirror of
https://github.com/brouhaha/sosar.git
synced 2024-06-02 07:41:28 +00:00
Use IntEnum for FileType.
This commit is contained in:
parent
1e41af7b87
commit
3111409cd9
107
sosdisk.py
107
sosdisk.py
|
@ -59,62 +59,50 @@ class StorageType(IntEnum):
|
||||||
volume_directory_header = 0x0f
|
volume_directory_header = 0x0f
|
||||||
|
|
||||||
|
|
||||||
|
class FileType(IntEnum):
|
||||||
class FileType(Enum):
|
unk = 0x00 # unknown/typeless
|
||||||
unknown = 0x00, 'UNK'
|
bad = 0x01 # bad blocks
|
||||||
bad_blocks = 0x01, 'BAD'
|
pcd = 0x02 # (SOS) Pascal codefile (may be assembly)
|
||||||
code = 0x02, 'PCD' # SOS only
|
ptx = 0x03 # (SOS) Pascal textfile
|
||||||
pascal_text = 0x03, 'PTX' # SOS only
|
txt = 0x04 # normal ASCII text file
|
||||||
text = 0x04, 'TXT' # normal ASCII text file
|
pda = 0x05 # (SOS) Pascal data
|
||||||
pascal_data = 0x05, 'PDA' # SOS only
|
bin = 0x06 # binary, subtype has load address
|
||||||
binary = 0x06, 'BIN'
|
fnt = 0x07 # (SOS) font
|
||||||
font = 0x07, 'FNT' # SOS only
|
fot = 0x08 # screen image
|
||||||
screen_image = 0x08, 'FOT'
|
ba3 = 0x09 # (SOS) Business BASIC program
|
||||||
business_basic_program = 0x09, 'BA3' # SOS only
|
da3 = 0x0a # (SOS) Business BASIC data
|
||||||
business_basic_data = 0x0a, 'DA3' # SOS only
|
wpf = 0x0b # (SOS) word processor
|
||||||
word_processor = 0x0b, 'WPF' # SOS only
|
sos = 0x0c # (SOS) system file
|
||||||
sos_system = 0x0c, 'SOS' # SOS only
|
|
||||||
# 0x0d..0x0e reserved for SOS
|
# 0x0d..0x0e reserved for SOS
|
||||||
subdirectory = 0x0f, 'DIR'
|
dir = 0x0f # subdirectory
|
||||||
rps_data = 0x10, 'RPD' # SOS only
|
rpd = 0x10 # (SOS) RPS_data
|
||||||
rps_index = 0x11, 'RPI' # SOS only
|
rpi = 0x11 # (SOS) RPS index
|
||||||
applefile_discard = 0x12, 'AFD' # SOS only
|
afd = 0x12 # (SOS) AppleFile discard
|
||||||
applefile_model = 0x13, 'AFM' # SOS only
|
afm = 0x13 # (SOS) AppleFile model
|
||||||
applefile_report_format = 0x14, 'AFR' # SOS only
|
afr = 0x14 # (SOS) AppleFile report
|
||||||
screen_library = 0x15, 'SCL' # SOS only
|
scl = 0x15 # (SOS) screen library
|
||||||
# 0x16..0x18 reserved for SOS
|
# 0x16..0x18 reserved for SOS
|
||||||
appleworks_data_base = 0x19, 'ADB'
|
adb = 0x19 # AppleWorks database
|
||||||
appleworks_word_proc = 0x1a, 'AWP'
|
awp = 0x1a # AppleWorks word processor
|
||||||
appleworks_spreadsheet = 0x1b, 'ASP'
|
asp = 0x1b # AppleWorks spreadsheet
|
||||||
# 0xe0..0xff are ProDOS only
|
r16 = 0xee # (ProDOS) EDASM 816 reolcatable
|
||||||
edasm_816_reolcatable = 0xee, 'R16'
|
par = 0xef # Apple Pascal area
|
||||||
pascal_area = 0xef, 'PAR'
|
cmd = 0xf0 # (ProDOS) added command
|
||||||
prodos_ci_added_command = 0xf0, 'CMD'
|
ovl = 0xf1 # (ProDOS) user defined 1, overlay
|
||||||
# 0xf1..0xf8 are ProDOS user-defined file types 1-8
|
ud2 = 0xf2 # (ProDOS) user defined 2
|
||||||
user_defined_1 = 0xf1, 'OVL'
|
ud3 = 0xf3 # (ProDOS) user defined 3
|
||||||
user_defined_2 = 0xf2, 'UD2'
|
ud4 = 0xf4 # (ProDOS) user defined 4
|
||||||
user_defined_3 = 0xf3, 'UD3'
|
bat = 0xf5 # (ProDOS) user defined 5, batch
|
||||||
user_defined_4 = 0xf4, 'UD4'
|
ud6 = 0xf6 # (ProDOS) user defined 6
|
||||||
user_defined_5 = 0xf5, 'BAT'
|
ud7 = 0xf7 # (ProDOS) user defined 7
|
||||||
user_defined_6 = 0xf6, 'UD6'
|
prg = 0xf8 # (ProDOS) user defined 8
|
||||||
user_defined_7 = 0xf7, 'UD7'
|
p16 = 0xf9 # (ProDOS 16) system
|
||||||
user_defined_8 = 0xf8, 'PRG'
|
int = 0xfa # (None) Integer BASIC program
|
||||||
prodos_16_system = 0xf9, 'P16'
|
ivr = 0xfb # (None) Integer BASIC variables
|
||||||
integer_basic_program = 0xfa, 'INT'
|
bas = 0xfc # (ProDOS) Applesoft BASIC program
|
||||||
integer_basic_variables = 0xfb, 'IVR'
|
var = 0xfd # (ProDOS) Applesoft BASIC variables
|
||||||
applesoft_program = 0xfc, 'BAS'
|
rel = 0xfe # (ProDOS) EDASM relocatable
|
||||||
applesoft_variables = 0xfd, 'VAR'
|
sys = 0xff # (ProDOS) system
|
||||||
relocatable_code = 0xfe, 'REL' # EDASM
|
|
||||||
prodos_system = 0xff, 'SYS'
|
|
||||||
|
|
||||||
def __new__(cls, int_value, abbrev):
|
|
||||||
obj = object.__new__(cls)
|
|
||||||
obj._value_ = int_value
|
|
||||||
obj.abbrev = abbrev
|
|
||||||
return obj
|
|
||||||
|
|
||||||
def __int__(self):
|
|
||||||
return self.value
|
|
||||||
|
|
||||||
|
|
||||||
class FileAttributes(IntFlag):
|
class FileAttributes(IntFlag):
|
||||||
|
@ -269,11 +257,11 @@ class SOSFileEntry(SOSDirectoryEntry):
|
||||||
self.name = bytes_to_sos_filename(name_length, name_b)
|
self.name = bytes_to_sos_filename(name_length, name_b)
|
||||||
self.creation = u32_to_sos_timestamp(creation_b)
|
self.creation = u32_to_sos_timestamp(creation_b)
|
||||||
if self.storage_type == StorageType.subdirectory:
|
if self.storage_type == StorageType.subdirectory:
|
||||||
assert self.file_type == int(FileType.subdirectory)
|
assert self.file_type == FileType.dir
|
||||||
self.subdir = SOSDirectory(disk, self.key_pointer)
|
self.subdir = SOSDirectory(disk, self.key_pointer)
|
||||||
else:
|
else:
|
||||||
assert self.storage_type in set([StorageType.seedling, StorageType.sapling, StorageType.tree])
|
assert self.storage_type in set([StorageType.seedling, StorageType.sapling, StorageType.tree])
|
||||||
assert self.file_type != int(FileType.subdirectory)
|
assert self.file_type != FileType.dir
|
||||||
self.storage = SOSStorage.create(self.disk, self.storage_type, self.key_pointer)
|
self.storage = SOSStorage.create(self.disk, self.storage_type, self.key_pointer)
|
||||||
|
|
||||||
|
|
||||||
|
@ -296,11 +284,10 @@ class SOSFileEntry(SOSDirectoryEntry):
|
||||||
else:
|
else:
|
||||||
attrs += '.'
|
attrs += '.'
|
||||||
try:
|
try:
|
||||||
ft = FileType(self.file_type)
|
ft = FileType(self.file_type).name
|
||||||
fts = ft.abbrev
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
fts = '$%02x' % self.file_type
|
ft = '$%02x' % self.file_type
|
||||||
print(' %s %s %s %6d' % (self.creation, fts, attrs, self.eof), end = '', file = file)
|
print(' %s %s %s %6d' % (self.creation, ft, attrs, self.eof), end = '', file = file)
|
||||||
print(' %s' % (prefix + self.name), file = file)
|
print(' %s' % (prefix + self.name), file = file)
|
||||||
if recursive and self.storage_type == StorageType.subdirectory:
|
if recursive and self.storage_type == StorageType.subdirectory:
|
||||||
self.subdir.print(prefix + self.name + '/',
|
self.subdir.print(prefix + self.name + '/',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user