Skip to content

Commit 079bd65

Browse files
author
barry warsaw
committed
convenience function
1 parent 4bbaa17 commit 079bd65

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

size.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#! /usr/bin/python3
2+
3+
"""Dump the sizes for the given files, suitable for pasting into content.ht"""
4+
5+
import os
6+
import sys
7+
import hashlib
8+
9+
DOT = '.'
10+
11+
12+
# For consistency with historical use.
13+
sort_order = dict((ext, i) for i, ext in enumerate(
14+
('tgz', 'tar.bz2', 'amd64.msi', 'msi', 'dmg')))
15+
16+
17+
def key(filename):
18+
parts = filename.split(DOT)
19+
# Try 2 parts first.
20+
ext = DOT.join(parts[-2:])
21+
if ext not in sort_order:
22+
ext = parts[-1]
23+
# Let KeyError propagate.
24+
return sort_order[ext]
25+
26+
27+
for filename in sorted(sys.argv[1:], key=key):
28+
md5 = hashlib.md5()
29+
with open(filename, 'rb') as fp:
30+
md5.update(fp.read())
31+
size = os.stat(filename).st_size
32+
print(' {} {:8} {}'.format(md5.hexdigest(), size, filename))

0 commit comments

Comments
 (0)