[pitivi/ges] utils/misc: Add utility to compute the hash of a file
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/ges] utils/misc: Add utility to compute the hash of a file
- Date: Mon, 23 Apr 2012 18:05:00 +0000 (UTC)
commit e0a98dedb0e3c2cd34353c7fa0030dc1d223fe3d
Author: Daniel Thul <daniel thul googlemail com>
Date: Mon Apr 23 19:17:36 2012 +0200
utils/misc: Add utility to compute the hash of a file
pitivi/utils/misc.py | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index 45e2e4b..0103a51 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -26,6 +26,7 @@ import sys
import gobject
import gst
import gtk
+import hashlib
import bisect
import os
import struct
@@ -204,6 +205,18 @@ class PathWalker(Thread):
self.stopme.set()
+def hash_file(uri):
+ """Hashes the first 256KB of the specified file"""
+ sha256 = hashlib.sha256()
+ with open(uri, "rb") as file:
+ for _ in range(1024):
+ chunk = file.read(256)
+ if not chunk:
+ break
+ sha256.update(chunk)
+ return sha256.hexdigest()
+
+
#------------------------------ Gst helpers --------------------------------#
def get_controllable_properties(element):
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]