create-update: support multiple repos 26/8226/2 accepted/tizen/ivi/genivi accepted/tizen/ivi/stable accepted/tizen_3.0.2014.q3_common accepted/tizen_3.0.m14.3_ivi accepted/tizen_3.0_common accepted/tizen_3.0_ivi accepted/tizen_4.0_unified accepted/tizen_common accepted/tizen_generic accepted/tizen_ivi accepted/tizen_ivi_panda accepted/tizen_mobile accepted/tizen_tv accepted/tizen_unified accepted/tizen_wearable tizen_3.0 tizen_3.0.2014.q3_common tizen_3.0.2014.q4_common tizen_3.0.2015.q1_common tizen_3.0.2015.q2_common tizen_3.0.m14.2_ivi tizen_3.0.m14.3_ivi tizen_3.0.m1_mobile tizen_3.0.m1_tv tizen_3.0.m2 tizen_3.0_ivi tizen_4.0 tizen_ivi_genivi tizen_ivi_panda accepted/tizen/20130912.185729 accepted/tizen/20130912.193925 accepted/tizen/20130913.030914 accepted/tizen/3.0/common/20161114.111858 accepted/tizen/3.0/ivi/20161011.065220 accepted/tizen/4.0/unified/20170816.011857 accepted/tizen/4.0/unified/20170828.221804 accepted/tizen/ivi/20160218.025838 accepted/tizen/ivi/genivi/20140131.032833 accepted/tizen/ivi/panda/20140403.014111 accepted/tizen/unified/20170309.040829 ivi_oct_m2 submit/tizen/20130912.080421 submit/tizen/20130912.090720 submit/tizen_3.0.m2/20170104.093755 submit/tizen_3.0_common/20161104.104000 submit/tizen_3.0_ivi/20161010.000007 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170828.100007 submit/tizen_common/20151023.083358 submit/tizen_common/20151026.085049 submit/tizen_ivi/20160217.000000 submit/tizen_ivi/20160217.000007 submit/tizen_ivi_genivi/20140131.032837 submit/tizen_ivi_panda/20140403.012115 submit/tizen_mobile/20141120.000000 submit/tizen_unified/20170308.100417 tizen_3.0.2014.q3_common_release tizen_3.0.m14.2_ivi_release tizen_3.0.m14.3_ivi_release tizen_3.0.m1_mobile_release tizen_3.0.m1_tv_release tizen_3.0.m2.a1_mobile_release tizen_3.0.m2.a1_tv_release tizen_3.0_ivi_release tizen_4.0.m1_release
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 24 Jul 2013 13:14:04 +0000 (16:14 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 14 Aug 2013 07:16:55 +0000 (10:16 +0300)
Support multiple RPM repos by re-trying download of an rpm from another
repo if the download fails.

Multiple repos can be configured by listing multiple
white-space-separated URLs in the 'repo-url' config item in swup.conf.

Change-Id: Id02fa02cf596f2e615d5c8655496a17b6458a414
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
tools/updateinfo/create-update.py
tools/updateinfo/updateutils.py

index 2fe1bb1..85be5d7 100755 (executable)
@@ -91,15 +91,19 @@ else:
 tmp_dir = tempfile.mkdtemp(dir=".")
 
 # Get packages files
-download(config.get(opts.product, 'packages-file', False, {'build-id': opts.old}),
-         credentials, tmp_dir, packages_files_dir, "packages")
-download(config.get(opts.product, 'packages-file', False, {'build-id': opts.new}),
-         credentials, patch_dir, packages_files_dir, "packages")
+url = config.get(opts.product, 'packages-file', False, {'build-id': opts.old}).rsplit('/', 1)
+download(url[0], url[1], credentials, tmp_dir, packages_files_dir, "packages")
+url = config.get(opts.product, 'packages-file', False, {'build-id': opts.new}).rsplit('/', 1)
+download(url[0], url[1], credentials, patch_dir, packages_files_dir, "packages")
 
 with open(os.path.join(tmp_dir, "repourl"), "w") as repourlfile:
-    repourlfile.write("%s\n" % config.get(opts.product, 'repo-url', False, {'build-id': opts.old}))
+    urls = config.get(opts.product, 'repo-url', False, {'build-id': opts.old}).split()
+    for url in urls:
+         repourlfile.write("%s\n" % url)
 with open(os.path.join(patch_dir, "repourl"), "w") as repourlfile:
-    repourlfile.write("%s\n" % config.get(opts.product, 'repo-url', False, {'build-id': opts.new}))
+    urls = config.get(opts.product, 'repo-url', False, {'build-id': opts.new}).split()
+    for url in urls:
+         repourlfile.write("%s\n" % url)
 
 
 blacklist = patch['BlacklistPkgs'] if 'BlacklistPkgs' in patch else []
index 63575f3..ee4135a 100755 (executable)
@@ -25,13 +25,26 @@ def http_get(url, credentials=(None, None)):
     html_page = urllib2.urlopen(request)
     return html_page
 
-def download(url, credentials, outdir, cachedir, target_fname=None):
-    fname = os.path.basename(url)
+def download(baseurls, path, credentials, outdir, cachedir, target_fname=None):
+    fname = os.path.basename(path)
     cached_file = os.path.join(cachedir, fname)
     if os.path.exists(cached_file):
         print "File cache hit: %s" % fname
     else:
-        ret = http_get(url, credentials)
+        if type(baseurls) == str:
+            baseurls = [baseurls]
+        for ind, baseurl in enumerate(baseurls):
+            url = "%s/%s" % (baseurl, path)
+            try:
+                ret = http_get(url, credentials)
+            except urllib2.HTTPError as err:
+                if ind < len(baseurls) - 1:
+                    print "Trying next URL, download failed with: %s" % err
+                else:
+                    raise
+            else:
+                break
+
         with open(cached_file, "w") as cache:
             cache.write(ret.read())
     if outdir:
@@ -76,9 +89,9 @@ def create_delta_repo(baseline_dir, target_dir, pkg_cache_dir, tmp_dir,
     new_pkgs_dir = changed_pkgs_dir
 
     with open(os.path.join(baseline_dir, "repourl"), "r") as repourlfile:
-        old_repourl = repourlfile.read().strip()
+        old_repourls = [url.strip() for url in repourlfile.readlines()]
     with open(os.path.join(target_dir, "repourl"), "r") as repourlfile:
-        new_repourl = repourlfile.read().strip()
+        new_repourls = [url.strip() for url in repourlfile.readlines()]
 
     for p in newpkgs:
         if p in blacklist:
@@ -86,7 +99,7 @@ def create_delta_repo(baseline_dir, target_dir, pkg_cache_dir, tmp_dir,
             continue
         rpm = "%s-%s.%s.rpm" % (p, p2[p]['version'], p2[p]['arch'])
         arch = p2[p]['arch']
-        download("%s/%s/%s" % (new_repourl, arch, rpm), credentials, new_pkgs_dir, pkg_cache_dir)
+        download(new_repourls, "%s/%s" % (arch, rpm), credentials, new_pkgs_dir, pkg_cache_dir)
 
     for p in changedpkgs:
         if p in blacklist:
@@ -94,16 +107,16 @@ def create_delta_repo(baseline_dir, target_dir, pkg_cache_dir, tmp_dir,
             continue
         rpm = "%s-%s.%s.rpm" % (p, p1[p]['version'], p1[p]['arch'])
         arch = p1[p]['arch']
-        download("%s/%s/%s" % (old_repourl, arch, rpm), credentials, old_pkgs_dir, pkg_cache_dir)
+        download(old_repourls, "%s/%s" % (arch, rpm), credentials, old_pkgs_dir, pkg_cache_dir)
         rpm = "%s-%s.%s.rpm" % (p, p2[p]['version'], p2[p]['arch'])
-        download("%s/%s/%s" % (new_repourl, arch, rpm), credentials, changed_pkgs_dir, pkg_cache_dir)
+        download(new_repourls, "%s/%s" % (arch, rpm), credentials, changed_pkgs_dir, pkg_cache_dir)
 
     for p in product_pkgs:
         if p in blacklist:
             raise Exception("Cannot blacklist a product package: %s" % p)
         rpm = "%s-%s.%s.rpm" % (p, p2[p]['version'], p2[p]['arch'])
         arch = p2[p]['arch']
-        download("%s/%s/%s" % (new_repourl, arch, rpm), credentials, product_pkgs_dir, pkg_cache_dir)
+        download(new_repourls, "%s/%s" % (arch, rpm), credentials, product_pkgs_dir, pkg_cache_dir)
 
     products = create_product_info(product_pkgs_dir)
     products_fn = os.path.join(tmp_dir, 'products.xml')