diff options
author | Martin Langhoff <martin@laptop.org> | 2012-07-24 19:14:23 (GMT) |
---|---|---|
committer | Daniel Drake <dsd@laptop.org> | 2012-08-20 20:32:31 (GMT) |
commit | 61e07307f2e42eae885028fc10d24106d0bf620e (patch) | |
tree | b827308096220f86ae10f156109b320f157e667b | |
parent | e3c6a9d7350d95f94e0d6ed5b18d7e8956893049 (diff) |
sugar_activity_group: add support for cacheonly
To sidestep messing with bitfrost, we cache the parsed
microformat using pickle.
-rw-r--r-- | modules/sugar_activity_group/kspost.60.nochroot.activities.py | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/modules/sugar_activity_group/kspost.60.nochroot.activities.py b/modules/sugar_activity_group/kspost.60.nochroot.activities.py index 1bda46a..401e3c7 100644 --- a/modules/sugar_activity_group/kspost.60.nochroot.activities.py +++ b/modules/sugar_activity_group/kspost.60.nochroot.activities.py @@ -10,6 +10,7 @@ import urllib import urllib2 import urlparse import time +import pickle from bitfrost.update import microformat @@ -35,24 +36,49 @@ if install_activities: for suffix in suffixes: if len(suffix) > 0: grpurl = urlparse.urljoin(baseurl + "/", urllib.quote(suffix)) + grpurlcache = os.path.join(cache, os.path.basename(baseurl) + + '-' + suffix + ".html") else: grpurl = baseurl - - print >>sys.stderr, "Trying group URL", grpurl - try: - name, desc, results = microformat.parse_url(grpurl) - except urllib2.HTTPError, e: - if e.code == 404: + grpurlcache = os.path.join(cache, os.path.basename(baseurl) + + ".html") + + if ooblib.cacheonly: + print >>sys.stderr, "Trying group URL cache file", grpurlcache + if os.path.exists(grpurlcache): + name, desc, results = pickle.load(open(grpurlcache)) + else: + continue + else: + print >>sys.stderr, "Trying group URL", grpurl + try: + name, desc, results = microformat.parse_url(grpurl) + except urllib2.HTTPError, e: + if e.code == 404: + continue + raise e + if len(results) == 0 or (name is None and desc is None): continue - raise e - if len(results) == 0 or (name is None and desc is None): - continue - print >>sys.stderr, "Found activity group:", name + print >>sys.stderr, "Found activity group:", name + pickle.dump([name, desc, results], open(grpurlcache, 'w')) for name, info in results.items(): (version, url) = microformat.only_best_update(info) print >>sys.stderr, "Examining %s v%s: %s" % (name, version, url) + if ooblib.cacheonly: + path = urlparse.urlsplit(url)[2] + path = os.path.basename(path) + + localpath = os.path.join(cache, path) + if os.path.exists(localpath): + print >>sys.stderr, "Using: ", localpath + ooblib.install_sugar_bundle(localpath) + continue + else: + print >>sys.stderr, "Cannot find cache for ", url + sys.exit(1) + fd = None for attempts in range(5): if attempts > 0: |