resolve right url for attachment package
authorGui Chen <gui.chen@intel.com>
Tue, 5 Jun 2012 07:56:30 +0000 (15:56 +0800)
committerGui Chen <gui.chen@intel.com>
Tue, 5 Jun 2012 10:54:33 +0000 (18:54 +0800)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/imager/baseimager.py
plugins/backend/zypppkgmgr.py

index ce8160f..daa39d0 100644 (file)
@@ -858,7 +858,10 @@ class BaseImageCreator(object):
             if not url:
                 msger.warning("Can't get url from repo for %s" % item)
                 continue
-            proxies = proxy.get_proxy_for(url)
+            proxies = None
+            aproxy = proxy.get_proxy_for(url)
+            if aproxy:
+                proxies = {url.split(':')[0]: aproxy}
             fpath = os.path.join(self.cachedir, os.path.basename(url))
             if not os.path.exists(fpath):
                 # download pkgs
index 15e1850..a7e3c12 100755 (executable)
@@ -825,6 +825,29 @@ class Zypp(BackendPlugin):
             repourl = str(repoinfo.baseUrls()[0])
             return get_proxy_for(repourl)
 
+    def _get_url(self, pobj):
+        if not pobj:
+            return None
+
+        name = str(pobj.repoInfo().name())
+        try:
+            repo = filter(lambda r: r.name == name, self.repos)[0]
+        except IndexError:
+            return None
+
+        baseurl = repo.baseurl[0]
+
+        index = baseurl.find("?")
+        if index > -1:
+            baseurl = baseurl[:index]
+
+        location = zypp.asKindPackage(pobj).location()
+        location = str(location.filename())
+        if location.startswith("./"):
+            location = location[2:]
+
+        return os.path.join(baseurl, location)
+
     def package_url(self, pkg):
 
         def cmpEVR(ed1, ed2):
@@ -844,8 +867,6 @@ class Zypp(BackendPlugin):
                        reverse=True)
 
         if items:
-            baseurl = items[0].repoInfo().baseUrls()[0]
-            location = zypp.asKindPackage(items[0]).location()
-            return os.path.join(str(baseurl), str(location.filename()))
+            return self._get_url(items[0])
 
         return None