Skip to content

Commit

Permalink
tzxls accepts multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
shred committed Sep 5, 2016
1 parent 3883d62 commit d011cf2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/tzxls.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Ths tool shows the block numbers, block types and some block contents of a TZX f
## Usage

```
tzxls [-h] [-s] [file]
tzxls [-h] [-s] file [file ...]
```

* `file`: TZX file to read from, or `stdin` if not given.
* `file`: TZX file or files to read from, or `stdin` if not given.
* `-s`, `--short`: Only shows the names found in ZX Spectrum file headers.
* `-h`, `--help`: Show help message and exit.

Expand Down
29 changes: 16 additions & 13 deletions tzxls
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,26 @@ from tzxlib.tzxfile import TzxFile

parser = argparse.ArgumentParser(description='List the contents of a TZX file')
parser.add_argument('file',
nargs='?',
default='/dev/stdin',
help='TZX file, stdin if omitted')
nargs='*',
help='TZX files, stdin if omitted')
parser.add_argument('-s', '--short',
dest='short',
action='store_true',
help='list only the ZX Spectrum header names')
args = parser.parse_args()

file = TzxFile()
file.read(args.file)
for f in args.file if len(args.file) > 0 else ['/dev/stdin']:
if len(args.file) > 1:
print('\n%s:' % (f))

cnt = 0
for b in file.blocks:
if args.short:
if hasattr(b, 'tap') and isinstance(b.tap, TapHeader):
print('%s: %s' % (b.tap.type(), b.tap.name()))
else:
print('%3d %-27s %s' % (cnt, b.type, str(b)))
cnt += 1
tzx = TzxFile()
tzx.read(f)

cnt = 0
for b in tzx.blocks:
if args.short:
if hasattr(b, 'tap') and isinstance(b.tap, TapHeader):
print('%s: %s' % (b.tap.type(), b.tap.name()))
else:
print('%3d %-27s %s' % (cnt, b.type, str(b)))
cnt += 1

0 comments on commit d011cf2

Please sign in to comment.