aboutsummaryrefslogtreecommitdiff
path: root/inc/sum.py
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-11-12 17:28:30 +0000
committerng0 <ng0@n0.is>2019-11-12 17:28:30 +0000
commit98690996582e0e511a8e8611b3db5080be6e75b0 (patch)
tree8b5ddd042d8d76d329e79451f70f14c4c52aafc3 /inc/sum.py
parent4a4839075452c7527ce87775d08428e5cb433957 (diff)
downloadwww-98690996582e0e511a8e8611b3db5080be6e75b0.tar.gz
www-98690996582e0e511a8e8611b3db5080be6e75b0.zip
split up template.py, make site generation a class.
Diffstat (limited to 'inc/sum.py')
-rw-r--r--inc/sum.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/inc/sum.py b/inc/sum.py
new file mode 100644
index 00000000..9addf78f
--- /dev/null
+++ b/inc/sum.py
@@ -0,0 +1,35 @@
1def sha256sum(_):
2 sha256 = hashlib.sha256()
3 with io.open(_, mode="rb") as fd:
4 content = fd.read()
5 sha256.update(content)
6 return sha256.hexdigest()
7
8
9def walksum(_):
10 sha256 = hashlib.sha256()
11 x = Path(_)
12 if not x.exists():
13 return -1
14 try:
15 for root, directories, files in os.walk(_):
16 for names in sorted(files):
17 filepath = os.path.join(root, names)
18 try:
19 fl = open(filepath, 'rb')
20 except:
21 fl.close()
22 continue
23 while 1:
24 buf = fl.read(4096)
25 if not buf:
26 break
27 sha256.update(hashlib.sha256(buf).hexdigest())
28 fl.close()
29 except:
30 import traceback
31 traceback.print_exc()
32 return -2
33 return sha256.hexdigest()
34
35