From 61e07307f2e42eae885028fc10d24106d0bf620e Mon Sep 17 00:00:00 2001 From: Martin Langhoff Date: Tue, 24 Jul 2012 19:14:23 +0000 Subject: sugar_activity_group: add support for cacheonly To sidestep messing with bitfrost, we cache the parsed microformat using pickle. --- 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: -- cgit v0.9.1