[rhythmbox/wip/python3: 11/35] Port rb to python 3
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox/wip/python3: 11/35] Port rb to python 3
- Date: Sun, 21 Apr 2013 00:03:43 +0000 (UTC)
commit 0d18c4466055b134e4ceda00fef97f0fea8d6516
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Mon Apr 15 10:42:00 2013 +0200
Port rb to python 3
plugins/rb/Loader.py | 10 +++++-----
plugins/rb/URLCache.py | 36 ++++++++++++++++++------------------
plugins/rb/rb.py | 7 +++----
3 files changed, 26 insertions(+), 27 deletions(-)
---
diff --git a/plugins/rb/Loader.py b/plugins/rb/Loader.py
index 868b63f..1d6bc7d 100644
--- a/plugins/rb/Loader.py
+++ b/plugins/rb/Loader.py
@@ -33,7 +33,7 @@ def callback_with_gdk_lock(callback, data, args):
v = callback(data, *args)
Gdk.threads_leave()
return v
- except Exception, e:
+ except Exception as e:
sys.excepthook(*sys.exc_info())
Gdk.threads_leave()
@@ -49,7 +49,7 @@ class Loader(object):
callback_with_gdk_lock(self.callback, contents, self.args)
else:
callback_with_gdk_lock(self.callback, None, self.args)
- except Exception, e:
+ except Exception as e:
sys.excepthook(*sys.exc_info())
callback_with_gdk_lock(self.callback, None, self.args)
@@ -60,7 +60,7 @@ class Loader(object):
try:
file = Gio.file_new_for_uri(url)
file.load_contents_async(self._cancel, self._contents_cb, None)
- except Exception, e:
+ except Exception as e:
sys.excepthook(*sys.exc_info())
callback(None, *args)
@@ -78,7 +78,7 @@ class UpdateCheck(object):
rfi = file.query_info_finish(result)
remote_mod = rfi.get_attribute_uint64(Gio.FILE_ATTRIBUTE_TIME_MODIFIED)
callback_with_gdk_lock(self.callback, remote_mod != self.local_mod, self.args)
- except Exception, e:
+ except Exception as e:
sys.excepthook(*sys.exc_info())
callback_with_gdk_lock(self.callback, False, self.args)
@@ -95,7 +95,7 @@ class UpdateCheck(object):
rf = Gio.file_new_for_uri(remote)
rf.query_info_async(Gio.FILE_ATTRIBUTE_TIME_MODIFIED, Gio.FileQueryInfoFlags.NONE,
GLib.PRIORITY_DEFAULT, self._cancel, self._file_info_cb, None)
- except Exception, e:
+ except Exception as e:
sys.excepthook(*sys.exc_info())
self.callback(True, *self.args)
diff --git a/plugins/rb/URLCache.py b/plugins/rb/URLCache.py
index 462882e..979252e 100644
--- a/plugins/rb/URLCache.py
+++ b/plugins/rb/URLCache.py
@@ -65,11 +65,11 @@ class URLCache(object):
"""
now = time.time()
if os.path.exists(self.path) == False:
- print "cache directory %s does not exist" % self.path
+ print("cache directory %s does not exist" % self.path)
return
- print "cleaning cache directory %s" % self.path
+ print("cleaning cache directory %s" % self.path)
for f in os.listdir(self.path):
try:
path = os.path.join(self.path, f)
@@ -77,20 +77,20 @@ class URLCache(object):
if self.lifetime != -1:
if stat.st_ctime + (self.lifetime * SECS_PER_DAY) < now:
- print "removing stale cache file %s:%s: age %s (past lifetime limit)" % (self.name,
f, int(now - stat.st_ctime))
+ print("removing stale cache file %s:%s: age %s (past lifetime limit)" % (self.name,
f, int(now - stat.st_ctime)))
os.unlink(path)
continue
if self.discard != -1:
# hmm, noatime mounts will break this, probably
if stat.st_atime + (self.discard * SECS_PER_DAY) < now:
- print "removing stale cache file %s:%s: age %s (past discard limit)" % (self.name,
f, int(now - stat.st_atime))
+ print("removing stale cache file %s:%s: age %s (past discard limit)" % (self.name,
f, int(now - stat.st_atime)))
os.unlink(path)
continue
- except Exception, e:
- print "error while checking cache entry %s:%s: %s" % (self.name, f, str(e))
- print "finished cleaning cache directory %s" % self.path
+ except Exception as e:
+ print("error while checking cache entry %s:%s: %s" % (self.name, f, str(e)))
+ print("finished cleaning cache directory %s" % self.path)
def cachefile(self, key):
"""
@@ -129,15 +129,15 @@ class URLCache(object):
stale = True
if stale:
- print "removing stale cache entry %s:%s" % (self.name, key)
+ print("removing stale cache entry %s:%s" % (self.name, key))
os.unlink(path)
return None
return path
- except Exception, e:
+ except Exception as e:
if hasattr(e, 'errno') is False or (e.errno != errno.ENOENT):
- print "error checking cache for %s:%s: %s" % (self.name, key, e)
+ print("error checking cache for %s:%s: %s" % (self.name, key, e))
return None
@@ -148,7 +148,7 @@ class URLCache(object):
try:
# construct cache filename
if not os.path.exists(self.path):
- os.makedirs(self.path, mode=0700)
+ os.makedirs(self.path, mode=0o700)
path = self.cachefile(key)
# consider using gio set contents async?
@@ -156,9 +156,9 @@ class URLCache(object):
f.write(data)
f.close()
- print "stored cache data %s:%s" % (self.name, key)
- except Exception, e:
- print "exception storing cache data %s:%s: %s" % (self.name, key, e)
+ print("stored cache data %s:%s" % (self.name, key))
+ except Exception as e:
+ print("exception storing cache data %s:%s: %s" % (self.name, key, e))
def __fetch_cb(self, data, url, key, callback, args):
@@ -169,13 +169,13 @@ class URLCache(object):
data = f.read()
f.close()
if callback(data, *args) is False:
- print "cache entry %s:%s invalidated by callback" % (self.name, key)
+ print("cache entry %s:%s invalidated by callback" % (self.name, key))
os.unlink(cachefile)
else:
callback(None, *args)
else:
if callback(data, *args) is False:
- print "cache entry %s:%s invalidated by callback" % (self.name, key)
+ print("cache entry %s:%s invalidated by callback" % (self.name, key))
else:
self.store(key, data)
@@ -190,7 +190,7 @@ class URLCache(object):
from the origin site will result in valid data.
"""
# check if we've got a fresh entry in the cache
- print "fetching cache entry %s:%s [%s]" % (self.name, key, url)
+ print("fetching cache entry %s:%s [%s]" % (self.name, key, url))
cachefile = self.check(key, True)
if cachefile is not None:
# could use a loader here, maybe
@@ -200,7 +200,7 @@ class URLCache(object):
if callback(data, *args) is not False:
return
- print "cache entry %s:%s invalidated by callback" % (self.name, key)
+ print("cache entry %s:%s invalidated by callback" % (self.name, key))
os.unlink(cachefile)
ld = rb.Loader()
diff --git a/plugins/rb/rb.py b/plugins/rb/rb.py
index a06b493..6fdc6c2 100644
--- a/plugins/rb/rb.py
+++ b/plugins/rb/rb.py
@@ -30,7 +30,6 @@ import sys
import os.path
import os
import time
-import thread
from gi.repository import RB
@@ -70,7 +69,7 @@ def find_plugin_file(plugin, filename):
info = plugin.plugin_info
data_dir = info.get_data_dir()
path = os.path.join(data_dir, filename)
- print "looking for " + filename + " in " + data_dir
+ print("looking for " + filename + " in " + data_dir)
if os.path.exists(path):
return path
@@ -112,8 +111,8 @@ class _rbdebugfile:
def readline(self): return ''
def readlines(self): return []
writelines = write
- def seek(self, a): raise IOError, (29, 'Illegal seek')
- def tell(self): raise IOError, (29, 'Illegal seek')
+ def seek(self, a): raise IOError((29, 'Illegal seek'))
+ def tell(self): raise IOError((29, 'Illegal seek'))
truncate = tell
sys.stdout = _rbdebugfile(sys.stdout.fileno())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]