Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Langhoff <martin@laptop.org>2012-07-24 19:22:18 (GMT)
committer Daniel Drake <dsd@laptop.org>2012-10-14 19:30:03 (GMT)
commit2dc2f40a2f128c573c8265e8a8f5bbb408911489 (patch)
tree5421d57cb0ba7af97457575c63c26d2f4d7c2cfb
parent5022236a8a6bdb5ce26527753f9a08a91a0b8d20 (diff)
sugar_activity_group: break down an unwieldy loop
Break out of the loop once we find the first good group URL. Removes indenting, puts the "break" in a more natural place and allows error handling.
-rw-r--r--modules/sugar_activity_group/kspost.60.nochroot.activities.py106
1 files changed, 55 insertions, 51 deletions
diff --git a/modules/sugar_activity_group/kspost.60.nochroot.activities.py b/modules/sugar_activity_group/kspost.60.nochroot.activities.py
index 401e3c7..594d951 100644
--- a/modules/sugar_activity_group/kspost.60.nochroot.activities.py
+++ b/modules/sugar_activity_group/kspost.60.nochroot.activities.py
@@ -62,64 +62,68 @@ if install_activities:
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:
- print >>sys.stderr, 'Retrying.'
- time.sleep(1)
- try:
- fd = urllib2.urlopen(url)
- break
- except urllib2.HTTPError, e:
- print >>sys.stderr, 'HTTP error: ', e.code
- except urllib2.URLError, e:
- print >>sys.stderr, 'Network or server error: ', e.reason
-
- if not fd:
- print >>sys.stderr, 'Could not reach ', url
- sys.exit(1)
+ if results:
+ break #process only the first URL (or cached file)
+
+ if not results:
+ print >>sys.stderr, "No Activity Group URL found"
+ sys.exit(1)
- headers = fd.info()
- if not 'Content-length' in headers:
- raise Exception("No content length for %s" % url)
- length = int(headers['Content-length'])
- path = urlparse.urlsplit(fd.geturl())[2]
+ 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):
- localsize = os.stat(localpath).st_size
- if localsize == length:
- print >>sys.stderr, "Not downloading, already in cache."
- ooblib.install_sugar_bundle(localpath)
- continue
+ print >>sys.stderr, "Using: ", localpath
+ ooblib.install_sugar_bundle(localpath)
+ continue
+ else:
+ print >>sys.stderr, "Cannot find cache for ", url
+ sys.exit(1)
- print >>sys.stderr, "Downloading (%dkB)..." % (length/1024)
- localfd = open(localpath, 'w')
- localfd.write(fd.read())
- fd.close()
- localfd.close()
- ooblib.install_sugar_bundle(localpath)
+ fd = None
+ for attempts in range(5):
+ if attempts > 0:
+ print >>sys.stderr, 'Retrying.'
+ time.sleep(1)
+ try:
+ fd = urllib2.urlopen(url)
+ break
+ except urllib2.HTTPError, e:
+ print >>sys.stderr, 'HTTP error: ', e.code
+ except urllib2.URLError, e:
+ print >>sys.stderr, 'Network or server error: ', e.reason
+
+ if not fd:
+ print >>sys.stderr, 'Could not reach ', url
+ sys.exit(1)
+
+ headers = fd.info()
+ if not 'Content-length' in headers:
+ raise Exception("No content length for %s" % url)
+ length = int(headers['Content-length'])
+ path = urlparse.urlsplit(fd.geturl())[2]
+ path = os.path.basename(path)
+
+ localpath = os.path.join(cache, path)
+ if os.path.exists(localpath):
+ localsize = os.stat(localpath).st_size
+ if localsize == length:
+ print >>sys.stderr, "Not downloading, already in cache."
+ ooblib.install_sugar_bundle(localpath)
+ continue
- # only process the first working URL
- break
+ print >>sys.stderr, "Downloading (%dkB)..." % (length/1024)
+ localfd = open(localpath, 'w')
+ localfd.write(fd.read())
+ fd.close()
+ localfd.close()
+ ooblib.install_sugar_bundle(localpath)
if systemwide:
print "mkdir -p $INSTALL_ROOT/etc/olpc-update"