parser=argparse.ArgumentParser(prog="atrcopy DISK_IMAGE",description="Manipulate files on several types of 8-bit computer disk images. Type '%(prog)s COMMAND --help' for list of options available for each command.")
list_parser=subparsers.add_parser(command,help="List files on the disk image. This is the default if no command is specified",aliases=command_aliases[command])
list_parser.add_argument("-m","--metadata",action="store_true",default=False,help="show extra metadata for named files")
list_parser.add_argument("files",metavar="FILENAME",nargs="*",help="an optional list of files to display")
command="extract"
extract_parser=subparsers.add_parser(command,help="Copy files from the disk image to the local filesystem",aliases=command_aliases[command])
extract_parser.add_argument("-a","--all",action="store_true",default=False,help="operate on all files on disk image")
extract_parser.add_argument("-l","--lower",action="store_true",default=False,help="convert extracted filenames to lower case")
#extract_parser.add_argument("-n", "--no-sys", action="store_true", default=False, help="only extract things that look like games (no DOS or .SYS files)")
extract_parser.add_argument("-e","--ext",action="store",nargs=1,default=False,help="add the specified extension")
extract_parser.add_argument("-f","--force",action="store_true",default=False,help="allow file overwrites on local filesystem")
extract_parser.add_argument("files",metavar="FILENAME",nargs="*",help="if not using the -a/--all option, a file (or list of files) to extract from the disk image.")
command="add"
add_parser=subparsers.add_parser(command,help="Add files to the disk image",aliases=command_aliases[command])
add_parser.add_argument("-f","--force",action="store_true",default=False,help="allow file overwrites in the disk image")
add_parser.add_argument("-t","--filetype",action="store",default="",help="file type metadata for writing to disk images that require it (e.g. DOS 3.3)")
add_parser.add_argument("files",metavar="FILENAME",nargs="+",help="a file (or list of files) to copy to the disk image")
# command = "create"
# create_parser = subparsers.add_parser(command, help="Create a new disk image", aliases=command_aliases[command])
# create_parser.add_argument("-f", "--force", action="store_true", default=False, help="replace disk image file if it exists")
# create_parser.add_argument("-s", "--sys", action="store_true", default=False, help="include system files (e.g. DOS.SYS and DUP.SYS for Atari DOS 2")
# create_parser.add_argument("-33", "--dos33", default="dos2", const="dos33", dest="image_type", action="store_const", help="blank Apple DOS 3.3")
command="assemble"
assembly_parser=subparsers.add_parser(command,help="Create a new binary file in the disk image",aliases=command_aliases[command])
assembly_parser.add_argument("-f","--force",action="store_true",default=False,help="allow file overwrites in the disk image")
assembly_parser.add_argument("-s","--asm",nargs="*",action="append",help="source file(s) to assemble using pyatasm")
assembly_parser.add_argument("-d","-b","--data",nargs="*",action="append",help="binary data file(s) to add to assembly, specify as file@addr. Only a portion of the file may be included; specify the subset using standard python slice notation: file[subset]@addr")
assembly_parser.add_argument("-r","--run-addr","--brun",action="store",default="",help="run address of binary file if not the first byte of the first segment")
assembly_parser.add_argument("-o","--output",action="store",default="",required=True,help="output file name in disk image")
command="delete"
delete_parser=subparsers.add_parser(command,help="Delete files from the disk image",aliases=command_aliases[command])
delete_parser.add_argument("-f","--force",action="store_true",default=False,help="remove the file even if it is write protected ('locked' in Atari DOS 2 terms), if write-protect is supported disk image")
delete_parser.add_argument("files",metavar="FILENAME",nargs="+",help="a file (or list of files) to remove from the disk image")
command="vtoc"
vtoc_parser=subparsers.add_parser(command,help="Show a formatted display of sectors free in the disk image",aliases=command_aliases[command])
vtoc_parser.add_argument("-e","--clear-empty",action="store_true",default=False,help="fill empty sectors with 0")
command="segments"
vtoc_parser=subparsers.add_parser(command,help="Show the list of parsed segments in the disk image",aliases=command_aliases[command])
# argparse doesn't seem to allow an argument fixed to item 1, so have to
# hack with the arg list to get arg #1 to be the disk image. Because of
# this hack, we have to perform an additional hack to figure out what the
# --help option applies to if it's in the argument list.
args=list(sys.argv[1:])
iflen(args)>0:
found_help=-1
first_non_dash=0
num_non_dash=0
foriinrange(len(args)):
ifargs[i].startswith("-"):
ifi==0:
first_non_dash=-1
ifargs[i]=="-h"orargs[i]=="--help":
found_help=i
else:
num_non_dash+=1
iffirst_non_dash<0:
first_non_dash=i
iffound_help>=0orfirst_non_dash<0:
iffound_help==0orfirst_non_dash<0:
# put dummy argument so help for entire script will be shown