conduit r1698 - in trunk: . conduit/platform conduit/utils test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1698 - in trunk: . conduit/platform conduit/utils test/python-tests
- Date: Fri, 29 Aug 2008 23:39:37 +0000 (UTC)
Author: jstowers
Date: Fri Aug 29 23:39:37 2008
New Revision: 1698
URL: http://svn.gnome.org/viewvc/conduit?rev=1698&view=rev
Log:
* conduit/platform/FileGio.py:
* conduit/utils/__init__.py:
* test/python-tests/TestCoreUtil.py: Work around stupid gvfs bug 547133
by adding an urllib2 based implementation of get_mtime
Modified:
trunk/ (props changed)
trunk/ChangeLog
trunk/conduit/platform/FileGio.py
trunk/conduit/utils/__init__.py
trunk/test/python-tests/TestCoreUtil.py
Modified: trunk/conduit/platform/FileGio.py
==============================================================================
--- trunk/conduit/platform/FileGio.py (original)
+++ trunk/conduit/platform/FileGio.py Fri Aug 29 23:39:37 2008
@@ -74,13 +74,19 @@
return None
def get_mtime(self):
- self._get_file_info()
- mtime = self.fileInfo.get_attribute_uint64('time::modified')
- if mtime:
- return mtime
+ #FIXME: Workaround for
+ #http://bugzilla.gnome.org/show_bug.cgi?id=547133
+ if self._file.get_uri_scheme() in ("http", "ftp"):
+ from conduit.utils import get_http_resource_last_modified
+ return get_http_resource_last_modified(self._file.get_uri())
else:
- #convert 0L -> None
- return None
+ self._get_file_info()
+ mtime = self.fileInfo.get_attribute_uint64('time::modified')
+ if mtime:
+ return mtime
+ else:
+ #convert 0L -> None
+ return None
def get_filename(self):
self._get_file_info()
Modified: trunk/conduit/utils/__init__.py
==============================================================================
--- trunk/conduit/utils/__init__.py (original)
+++ trunk/conduit/utils/__init__.py Fri Aug 29 23:39:37 2008
@@ -11,11 +11,32 @@
import os.path
import socket
import datetime
+import urllib2
import time
import re
import logging
log = logging.getLogger("Utils")
+def get_http_resource_last_modified(url):
+ """
+ Returns the last modified date of the http resource at the given URL.
+ @returns: A Float timestamp or None
+ """
+ try:
+ request = urllib2.Request(url)
+ a = urllib2.build_opener().open(request)
+ except urllib2.HTTPError:
+ log.info("URL does not exist: %s" % url)
+ return None
+ except Exception, e:
+ log.warn("Error getting url last modified: %s" % e)
+ return None
+
+ date = a.headers.getdate('Last-Modified')
+ if date:
+ date = time.mktime(date)
+ return date
+
def get_proportional_resize(desiredW, desiredH, currentW, currentH):
"""
Returns proportionally resized co-ordinates for an image
Modified: trunk/test/python-tests/TestCoreUtil.py
==============================================================================
--- trunk/test/python-tests/TestCoreUtil.py (original)
+++ trunk/test/python-tests/TestCoreUtil.py Fri Aug 29 23:39:37 2008
@@ -10,6 +10,13 @@
import os.path
import sys
+if is_online():
+ date = Utils.get_http_resource_last_modified("http://files.conduit-project.org/Conduit-0.3.0-screencast-small.mpeg")
+ ok("Got mtime of http resource", date == datetime.datetime(2007,5,6,14,47,36))
+
+date1 = Utils.get_http_resource_last_modified("http://foo.com/1/2/3")
+ok("Got no mtime from missing http resource", date1 == None)
+
#Test facebook dimensions
# 1024x768 -> 604x453
w,h = Utils.get_proportional_resize(604,604,1024,768)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]