diff options
| author | JF | 2019-07-09 14:56:21 -0700 |
|---|---|---|
| committer | jvoisin | 2019-07-09 14:56:21 -0700 |
| commit | 06346e19464c376c0c2ca13ef4218559f9df4212 (patch) | |
| tree | 94db98bcfbcd68dffdec0fa60239baef278510a8 /utils.py | |
| parent | 9d155d171e916cd3c2c34f6c50955745f8929e79 (diff) | |
added a docker dev environment
Signed-off-by: Jan Friedli <jan.friedli@immerda.ch>
Diffstat (limited to 'utils.py')
| -rw-r--r-- | utils.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..fb2fb08 --- /dev/null +++ b/utils.py | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | import os | ||
| 2 | import hashlib | ||
| 3 | |||
| 4 | |||
| 5 | def get_allow_origin_header_value(): | ||
| 6 | return os.environ.get('MAT2_ALLOW_ORIGIN_WHITELIST', '*').split(" ") | ||
| 7 | |||
| 8 | |||
| 9 | def hash_file(filepath: str) -> str: | ||
| 10 | sha256 = hashlib.sha256() | ||
| 11 | with open(filepath, 'rb') as f: | ||
| 12 | while True: | ||
| 13 | data = f.read(65536) # read the file by chunk of 64k | ||
| 14 | if not data: | ||
| 15 | break | ||
| 16 | sha256.update(data) | ||
| 17 | return sha256.hexdigest() | ||
| 18 | |||
| 19 | |||
| 20 | def check_upload_folder(upload_folder): | ||
| 21 | if not os.path.exists(upload_folder): | ||
| 22 | os.mkdir(upload_folder) \ No newline at end of file | ||
