Skip to content

Commit

Permalink
Remove the -f/--force option from snapmod.py
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed Jul 10, 2023
1 parent 126dd23 commit c306599
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
7 changes: 1 addition & 6 deletions skoolkit/snapmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ def main(args):
parser.add_argument('infile', help=argparse.SUPPRESS, nargs='?')
parser.add_argument('outfile', help=argparse.SUPPRESS, nargs='?')
group = parser.add_argument_group('Options')
group.add_argument('-f', '--force', dest='force', action='store_true',
help="Overwrite an existing snapshot.")
group.add_argument('-m', '--move', dest='moves', metavar='src,size,dest', action='append', default=[],
help='Move a block of bytes of the given size from src to dest. This option may be used multiple times.')
group.add_argument('-p', '--poke', dest='pokes', metavar='a[-b[-c]],[^+]v', action='append', default=[],
Expand Down Expand Up @@ -89,7 +87,4 @@ def main(args):

if outfile is None:
outfile = infile
if namespace.force or not os.path.isfile(outfile):
run(infile, namespace, outfile)
else:
write_line('{}: file already exists; use -f to overwrite'.format(outfile))
run(infile, namespace, outfile)
1 change: 0 additions & 1 deletion sphinx/source/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,6 @@ To list the options supported by `snapmod.py`, run it with no arguments::
Modify a 48K Z80 snapshot.

Options:
-f, --force Overwrite an existing snapshot.
-m src,size,dest, --move src,size,dest
Move a block of bytes of the given size from src to
dest. This option may be used multiple times.
Expand Down
5 changes: 1 addition & 4 deletions sphinx/source/man/snapmod.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ DESCRIPTION

OPTIONS
=======
-f, --force
Overwrite an existing snapshot.

-m, --move `src,size,dest`
Move a block of bytes of the given size from 'src' to 'dest'. This option may
be used multiple times. 'src', 'size' and 'dest' must each be a decimal
Expand Down Expand Up @@ -87,7 +84,7 @@ EXAMPLES
1. Set the value of the HL register pair to 0 in ``game.z80``:

|
| ``snapmod.py -f -r hl=0 game.z80``
| ``snapmod.py -r hl=0 game.z80``
2. POKE the value 23 into address 32768 in ``game.z80``, and write the
resultant snapshot to ``poked.z80``:
Expand Down
7 changes: 7 additions & 0 deletions sphinx/source/migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ This can be redefined by using the ``#DEF`` macro::

#DEF(#MIN(a,b) #IF($a<$b)($a,$b))

snapmod.py
----------
In SkoolKit 8, :ref:`snapmod.py` would refuse to overwrite an existing snapshot
unless the ``--force`` option was given. In SkoolKit 9, `snapmod.py` will
overwrite an existing snapshot by default, and the ``--force`` option is no
longer supported.

tap2sna.py
----------
In SkoolKit 8, :ref:`tap2sna.py` performed a
Expand Down
20 changes: 4 additions & 16 deletions tests/test_snapmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,40 +108,28 @@ def test_nonexistent_input_file(self):
self.run_snapmod('-r hl=0 {}'.format(infile))
self.assertEqual(cm.exception.args[0], '{}: file not found'.format(infile))

def test_no_clobber_input_file(self):
infile = self.write_bin_file(suffix='.z80')
output, error = self.run_snapmod('-p 16384,0 {}'.format(infile))
self.assertEqual(output, '{}: file already exists; use -f to overwrite\n'.format(infile))
self.assertEqual(error, '')

def test_no_clobber_output_file(self):
outfile = self.write_bin_file(suffix='.z80')
output, error = self.run_snapmod('-p 16384,0 in.z80 {}'.format(outfile))
self.assertEqual(output, '{}: file already exists; use -f to overwrite\n'.format(outfile))
self.assertEqual(error, '')

def test_option_f_clobber_input_file(self):
def test_overwrite_input_file(self):
header = [0] * 30
header[6] = 1 # PC > 0
exp_header = header[:]
exp_header[12] |= 34 # RAM block compressed, BORDER 1
ram = [0] * 49152
infile = self.write_z80_file(header, ram, 1)
output, error = self.run_snapmod('-f -s border=1 {}'.format(infile))
output, error = self.run_snapmod('-s border=1 {}'.format(infile))
self.assertEqual(output, '')
self.assertEqual(error, '')
z80_header = list(read_bin_file(infile, len(exp_header)))
self.assertEqual(exp_header, z80_header)

def test_option_force_clobber_output_file(self):
def test_overwrite_output_file(self):
header = [0] * 30
header[6] = 1 # PC > 0
exp_header = header[:]
exp_header[12] |= 36 # RAM block compressed, BORDER 2
ram = [0] * 49152
infile = self.write_z80_file(header, ram, 1)
outfile = self.write_bin_file(suffix='.z80')
output, error = self.run_snapmod('--force -s border=2 {} {}'.format(infile, outfile))
output, error = self.run_snapmod('-s border=2 {} {}'.format(infile, outfile))
self.assertEqual(output, '')
self.assertEqual(error, '')
z80_header = list(read_bin_file(outfile, len(exp_header)))
Expand Down

0 comments on commit c306599

Please sign in to comment.