summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2016-09-21 17:19:40 +0200
committerLars-Dominik Braun <lars@6xq.net>2016-09-21 17:19:40 +0200
commitd3fd76cb12f9080cc49c7d9cb1bfab5b2d574aef (patch)
tree5dd2a98c23536fb0951414ff709cab6696471c44
parent12989393311cdca62f376bea6883ee36e8fa43ac (diff)
downloadeumel-tools-d3fd76cb12f9080cc49c7d9cb1bfab5b2d574aef.zip
eumel-tools-d3fd76cb12f9080cc49c7d9cb1bfab5b2d574aef.tar.gz
eumel-tools-d3fd76cb12f9080cc49c7d9cb1bfab5b2d574aef.tar.bz2
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.
-rwxr-xr-xextractAll.sh2
-rwxr-xr-xextractArchive.py6
2 files changed, 7 insertions, 1 deletions
diff --git a/extractAll.sh b/extractAll.sh
index 6139475..8b8649f 100755
--- a/extractAll.sh
+++ b/extractAll.sh
@@ -9,7 +9,7 @@ while read -r F; do
destdir="${base}.extracted"
echo "Extracting $F to $destdir"
$root/linearizeDisk.py "$F" "$linear"
- $root/extractArchive.py -o "$destdir" "$linear"
+ $root/extractArchive.py -n -o "$destdir" "$linear"
pushd "$destdir" || continue
for G in ./*; do
echo "Converting $G to ${G}.txt"
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