Merge pull request #3 from chris-torrence/master

Add po2dsk.py to go other direction
This commit is contained in:
Paul Hagstrom 2021-05-02 18:27:07 -04:00 committed by GitHub
commit 2f199f601c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 4 deletions

View File

@ -6,15 +6,19 @@ into those of a .po (ProDOS-order) file. Most Apple II emulators can handle bot
but certain utilities (with which I wanted to use existing .dsk images) assume but certain utilities (with which I wanted to use existing .dsk images) assume
ProDOS-ordered files. ProDOS-ordered files.
Usage is just (assuming you've done chmod 755 dsk2po.py, else precede with python command): Usage is just (assuming you've done `chmod 755 dsk2po.py`, else precede with python command):
./dsk2po.py image.dsk ./dsk2po.py image.dsk
This will create image.dsk.po alongside it. Pretty much no checking is done. This will create image.dsk.po alongside it. Pretty much no checking is done.
It just goes through 35 tracks and converts them, then ends. It just goes through 35 tracks and converts them, then ends.
This can be used as an action for find, like so: This can be used as an action for find, like so:
find imagefolders/\*/\*.dsk -exec ./dsk2po.py {} \; find imagefolders/\*/\*.dsk -exec ./dsk2po.py {} \;
...which was mostly the point. ...which was mostly the point.
You can also go the opposite direction:
./po2dsk.py image.po

35
po2dsk.py Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env python3
# scramble po back into dsk
# Chris Torrence, Oct 2020
import sys, getopt, re
from dsk2po import dsk2po
def main(argv=None):
print("po2dsk - convert po files to dsk files")
try:
opts, args = getopt.getopt(sys.argv[1:], '')
except getopt.GetoptError as err:
print(str(err))
usage()
return 1
try:
filenameIn = args[0]
except:
print('You need to provide the name of a PO file to begin.')
return 1
tracks = []
# Note that the same algorithm can be used to convert in either direction
with open(filenameIn, mode="rb") as fileIn:
for track in range(35):
trackbuffer = fileIn.read(4096)
tracks.append(dsk2po(trackbuffer))
dskfilename = re.sub('\.po$', '', filenameIn, flags=re.IGNORECASE) + ".dsk"
print('Writing dsk image to {}'.format(dskfilename))
with open(dskfilename, mode="wb") as file:
for track in tracks:
file.write(track)
return 1
if __name__ == "__main__":
sys.exit(main())