aboutsummaryrefslogtreecommitdiff
path: root/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'util.py')
-rw-r--r--util.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/util.py b/util.py
index 9fca80c..5e0ccce 100644
--- a/util.py
+++ b/util.py
@@ -7,6 +7,37 @@ import os
import numpy as np
from queue import Queue
from threading import Thread, Lock
+import hashlib
+import datetime
+
+BUF_SIZE = 65535
+
+def rename(old, new_base):
+ ext = os.path.splitext(os.path.basename(old))[1]
+ new_fpath = os.path.join(os.path.dirname(old), new_base + ext)
+ os.rename(old, new_fpath)
+ return new_fpath
+
+def rename_hash(fpath, hash):
+ with open(fpath, 'rb') as f:
+ while True:
+ data = f.read(BUF_SIZE)
+ if not data:
+ break
+ hash.update(data)
+ return rename(fpath, hash.hexdigest())
+
+def rename_sha1(fpath):
+ return rename_hash(fpath, hashlib.sha1())
+
+def rename_sha256(fpath):
+ return rename_hash(fpath, hashlib.sha256())
+
+def rename_cdate(fpath):
+ return rename(fpath, datetime.datetime.fromtimestamp(os.path.getctime(fpath)).strftime("%Y-%m-%d_%H:%M:%S:%f"))
+
+def rename_mdate(fpath):
+ return rename(fpath, datetime.datetime.fromtimestamp(os.path.getmtime(fpath)).strftime("%Y-%m-%d_%H:%M:%S:%f"))
def image_resize(image, width = None, height = None, inter = cv2.INTER_AREA):
# initialize the dimensions of the image to be resized and