sparseutils

utilities for interacting with sparse files
Log | Files | Refs | README | LICENSE

commit bf541343ecc270e0e24ce7f7807a8f67da83dad3
parent a1fa69eaf52b4b1ca55577ad0e7c9f397ac7089d
Author: Richard Ipsum <richardipsum@fastmail.co.uk>
Date:   Sun,  2 Apr 2017 13:21:43 +0100

sparsemap: Use argparse

Diffstat:
Msparseutils/sparsemap.py | 23+++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/sparseutils/sparsemap.py b/sparseutils/sparsemap.py @@ -21,6 +21,19 @@ import sys import os import stat import errno +import argparse + +DESCRIPTION = '''Print the structure of a sparse file to stdout. + +The file is interpreted as a sequence of data and holes, for example +given a file with 8192 bytes of data followed by a 4096 byte hole followed +by 8192 bytes of data the output of sparsemap would be: + +DATA 8192 +HOLE 4096 +DATA 8192 + +''' def sparsemap(fd): @@ -58,11 +71,13 @@ def sparsemap(fd): what = os.SEEK_DATA if what == os.SEEK_HOLE else os.SEEK_HOLE def main(): - if len(sys.argv) != 2: - print('usage: {} FILE'.format(sys.argv[0]), file=sys.stderr) - sys.exit(1) + parser = argparse.ArgumentParser( + description=DESCRIPTION, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('FILE') - path = sys.argv[1] + args = vars(parser.parse_args()) + path = args['FILE'] try: mode = os.stat(path).st_mode