diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2016-09-21 17:19:40 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2016-09-21 17:19:40 +0200 |
commit | d3fd76cb12f9080cc49c7d9cb1bfab5b2d574aef (patch) | |
tree | 5dd2a98c23536fb0951414ff709cab6696471c44 /extractArchive.py | |
parent | 12989393311cdca62f376bea6883ee36e8fa43ac (diff) | |
download | eumel-tools-d3fd76cb12f9080cc49c7d9cb1bfab5b2d574aef.tar.gz eumel-tools-d3fd76cb12f9080cc49c7d9cb1bfab5b2d574aef.tar.bz2 eumel-tools-d3fd76cb12f9080cc49c7d9cb1bfab5b2d574aef.zip |
Add position of file in archive to name
Some archive disks are organized into “sections” and file order should
be preserved in those cases. Add a simple commandline switch.
Diffstat (limited to 'extractArchive.py')
-rwxr-xr-x | extractArchive.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/extractArchive.py b/extractArchive.py index 2e66879..f14a6b6 100755 --- a/extractArchive.py +++ b/extractArchive.py @@ -46,6 +46,8 @@ if __name__ == '__main__': parser.add_argument ('-f', '--force', help='Overwrite existing files', action='store_true') parser.add_argument ('-o', '--output', help='Output directory, defaults to archive name') parser.add_argument ('-v', '--verbose', help='Enable debugging messages', action='store_true') + parser.add_argument ('-n', '--number', help='Number files based on their position in the archive', + action='store_true') parser.add_argument ('file', help='Input file') args = parser.parse_args () @@ -69,6 +71,7 @@ if __name__ == '__main__': except FileExistsError: pass + i = 1 while True: # file header dataspace fileheader = FileHeaderDataspace (BytesIO (next (entries))) @@ -92,6 +95,8 @@ if __name__ == '__main__': logging.debug ('skipping quirks') e = e[pagesize:] + if args.number: + filename = '{:03d}_{}'.format (i, filename) outfile = os.path.join (args.output, filename) if os.path.exists (outfile) and not args.force: logging.info ('File {} exists, skipping'.format (outfile)) @@ -101,4 +106,5 @@ if __name__ == '__main__': outfd.write (e) stamp = mtime.timestamp () os.utime (outfile, (stamp, stamp)) + i += 1 |