fetch resources in url /googlemap/ - would come with plewww
[myplc.git] / bin / plc-kml.py
index 460c0d9..edcf035 100755 (executable)
@@ -46,7 +46,7 @@ class KmlMap:
         self.open()
         self.write_header()
         # cache peers 
-        peers = GetPeers({},['peer_id','peername'])
+        peers = GetPeers()
         all_sites = GetSites({'enabled':True,'is_public':True})
         all_sites.sort(KmlMap.site_compare)
         for site in all_sites:
@@ -75,12 +75,13 @@ class KmlMap:
         self.write("""</Document></kml>
 """)
 
-    def peer_name (self,site, peers):
+    def peer_info (self,site, peers):
         if not site['peer_id']:
-            return "local"
+            return (api.config.PLC_NAME, "http://%s/"%api.config.PLC_API_HOST,)
         for peer in peers:
             if peer['peer_id'] == site['peer_id']:
-                return peer['peername']
+                return (peer['peername'],peer['peer_url'].replace("PLCAPI/",""),)
+        return "Unknown peer_name"
 
     def write_site (self, site, peers):
         # discard sites with missing lat or lon
@@ -100,6 +101,29 @@ class KmlMap:
         baseurl='http://%s'%api.config.PLC_WWW_HOST
         peer_id=site['peer_id']
 
+        # STYLE
+        # the size for google icons
+        if not self.options.use_custom_icons:
+            if not peer_id:
+                # local sites
+                iconfile=default_local_builtin
+                xyspec="<x>128</x><y>0</y><w>32</w><h>32</h>"
+            else:
+                # remote
+                iconfile=default_foreign_builtin
+                xyspec="<x>160</x><y>0</y><w>32</w><h>32</h>"
+            iconurl="root://icons/%(iconfile)s"%locals()
+        # the size for our own brew of icons
+        else:
+            if not peer_id:
+                iconfile=self.options.local_icon
+            else:
+                iconfile=self.options.foreign_icon
+            iconurl="%(baseurl)s/%(iconfile)s"%locals()
+            xyspec=""
+
+        iconspec="<href>%(iconurl)s</href>%(xyspec)s"%locals()
+
         # open description
         description  = "<br/><table style='border: 1px solid black; padding: 5px;' width='500px'>"
 
@@ -108,20 +132,11 @@ class KmlMap:
         description += "<tr><td align='center'>"
         description += "<b>Testbed</b>"
         description += "</td><td>"
-        if peer_id:
-            peername = 'PlanetLab Central'
-           peerurl = 'http://www.planet-lab.org'
-            #self.peer_name(site,peers)
-        else:
-            peername = 'PlanetLab Europe'
-           peerurl = 'http://www.planet-lab.eu'
+        (peername,peerurl) = self.peer_info (site,peers)
         description += "<a style='text-decoration: none;' href='%(peerurl)s'> %(peername)s </a>"%locals()
         #description += "<a style='text-decoration: none;' href='%(apiurl)s/db/peers/index.php?id=%(peer_id)d'>[description]</a>"%locals()
         description += "</td><td>"
-        if peer_id:
-            description += "<img src='%(apiurl)s/sites/plc24-32.png'/>"%locals()
-        else:
-            description += "<img src='%(apiurl)s/sites/ple24-32.png'/>"%locals()
+        description += "<img src='%(iconurl)s'/>"%locals()
        description += "</td></tr>"
 
        # URL
@@ -139,7 +154,7 @@ class KmlMap:
 
         # NODES
         description += "<tr><td align='center'>"
-        description += "<img src='%(apiurl)s/sites/node.png'/>"%locals()
+        description += "<img src='%(apiurl)s/googlemap/node.png'/>"%locals()
         description += "</td><td>"
         if nb_nodes:
             description += "<a style='text-decoration: none;' href='%(apiurl)s/db/nodes/index.php?site_id=%(site_id)d'>%(nb_nodes)d node(s)</a>"%locals()
@@ -150,7 +165,7 @@ class KmlMap:
 
         #SLICES
         description += "<tr><td align='center'>"
-        description += "<img src='%(apiurl)s/sites/slice.png'/>"%locals()
+        description += "<img src='%(apiurl)s/googlemap/slice.png'/>"%locals()
         description += "</td><td>"
         if nb_slices:
             description += "<a style='text-decoration: none;' href='%(apiurl)s/db/slices/index.php?site_id=%(site_id)d'>%(nb_slices)d slice(s)</a>"%locals()
@@ -167,29 +182,6 @@ class KmlMap:
             name=""
             description=""
 
-        # STYLE
-        # the size for google icons
-        if not self.options.use_custom_icons:
-            if not peer_id:
-                # local sites
-                iconfile=default_local_builtin
-                xyspec="<x>128</x><y>0</y><w>32</w><h>32</h>"
-            else:
-                # remote
-                iconfile=default_foreign_builtin
-                xyspec="<x>160</x><y>0</y><w>32</w><h>32</h>"
-            iconurl="root://icons/%(iconfile)s"%locals()
-        # the size for our own brew of icons
-        else:
-            if not peer_id:
-                iconfile=self.options.local_icon
-            else:
-                iconfile=self.options.foreign_icon
-            iconurl="%(baseurl)s/%(iconfile)s"%locals()
-            xyspec=""
-
-        iconspec="<href>%(iconurl)s</href>%(xyspec)s"%locals()
-
         # set the camera 50km high
         template="""<Placemark>
 <Style><IconStyle><Icon>%(iconspec)s</Icon></IconStyle></Style>