[totem] opensubtitles: Use Gio introspection
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem] opensubtitles: Use Gio introspection
- Date: Mon, 12 Sep 2011 14:29:16 +0000 (UTC)
commit 9dcaa8e710db8be808e843f99dea3998b644291d
Author: Bastien Nocera <hadess hadess net>
Date: Mon Sep 12 15:18:39 2011 +0100
opensubtitles: Use Gio introspection
And use Python's OS module to implement the reading
as we won't be getting a working "read()" for Gio from
Python any time soon (see bug #621915)
https://bugzilla.gnome.org/show_bug.cgi?id=658269
src/plugins/opensubtitles/hash.py | 28 ++++++++++++++++------------
1 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/src/plugins/opensubtitles/hash.py b/src/plugins/opensubtitles/hash.py
index 1ae7158..d81e588 100644
--- a/src/plugins/opensubtitles/hash.py
+++ b/src/plugins/opensubtitles/hash.py
@@ -1,5 +1,6 @@
import struct
-import gio
+import os
+from gi.repository import Gio
SIZE_ERROR = -1
SEEK_ERROR = -2
@@ -10,9 +11,9 @@ def hash_file (name):
longlongformat = 'q' # long long
bytesize = struct.calcsize (longlongformat)
- file_to_hash = gio.File (name)
+ file_to_hash = Gio.File.new_for_uri (name)
- file_info = file_to_hash.query_info ('standard::size', 0)
+ file_info = file_to_hash.query_info ('standard::size', 0, None)
filesize = file_info.get_attribute_uint64 ('standard::size')
file_hash = filesize
@@ -20,27 +21,30 @@ def hash_file (name):
if filesize < 65536 * 2:
return SIZE_ERROR, 0
- data = file_to_hash.read ()
+ f = file(file_to_hash.get_path(), "rb")
- if data.can_seek () != True:
- return SEEK_ERROR, 0
-
- for _ in range (65536/bytesize):
- buf = data.read (bytesize)
+ for _ in range (65536 / bytesize):
+ buf = f.read (bytesize)
(l_value,) = struct.unpack (longlongformat, buf)
file_hash += l_value
file_hash = file_hash & 0xFFFFFFFFFFFFFFFF #to remain as 64bit number
- if data.seek (max (0, filesize-65536), 1) != True:
+ f.seek (max (0, filesize - 65536), os.SEEK_SET)
+
+ if f.tell() != max (0, filesize - 65536):
return SEEK_ERROR, 0
for _ in range (65536/bytesize):
- buf = data.read (bytesize)
+ buf = f.read (bytesize)
(l_value,) = struct.unpack (longlongformat, buf)
file_hash += l_value
file_hash = file_hash & 0xFFFFFFFFFFFFFFFF
- data.close ()
+ f.close ()
returnedhash = "%016x" % file_hash
+
+ print returnedhash
+ print filesize
+
return returnedhash, filesize
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]