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
commit7c82f9b52fe65b72f9d757c88f4615b1cf706447 (patch)
tree7f88a7561ffa4b384d5ec3033c5981d42ff5d250
parentf45ef2ae39c610aac375f4e5aa7c7a51158238fe (diff)
downloadeumel-7c82f9b52fe65b72f9d757c88f4615b1cf706447.tar.gz
eumel-7c82f9b52fe65b72f9d757c88f4615b1cf706447.tar.bz2
eumel-7c82f9b52fe65b72f9d757c88f4615b1cf706447.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.
-rwxr-xr-xtools/extractAll.sh2
-rwxr-xr-xtools/extractArchive.py6
2 files changed, 7 insertions, 1 deletions
diff --git a/tools/extractAll.sh b/tools/extractAll.sh
index 6139475..8b8649f 100755
--- a/tools/extractAll.sh
+++ b/tools/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/tools/extractArchive.py b/tools/extractArchive.py
index 2e66879..f14a6b6 100755
--- a/tools/extractArchive.py
+++ b/tools/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