another ugly hack is gone
[myplc.git] / bin / plc-kml.py
index 2a1ecf9..b246300 100755 (executable)
@@ -1,7 +1,5 @@
 #!/usr/bin/env plcsh
 #
-# $Id$
-
 # this script generates a kml file, located under the default location below
 # you should crontab this job from your myplc image
 # you can then use the googlemap.js javascript for creating your applet
@@ -48,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:
@@ -77,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
@@ -102,43 +101,9 @@ class KmlMap:
         baseurl='http://%s'%api.config.PLC_WWW_HOST
         peer_id=site['peer_id']
 
-        # open description
-        description='<ul>'
-        # Name and URL
-        description += '<li>'
-        description += '<a href="%(apiurl)s/db/sites/index.php?id=%(site_id)d"> Site page </a>'%locals()
-        if site['url']:
-            site_url=site['url']
-            description += ' -- <a href="%(site_url)s"> %(site_url)s </a>'%locals()
-        description += '</li>'
-        # NODES
-        if nb_nodes:
-            description += '<li>'
-            description += '<a href="%(apiurl)s/db/nodes/index.php?site_id=%(site_id)d">%(nb_nodes)d node(s)</a>'%locals()
-            description += '<a href="%(apiurl)s/db/nodes/comon.php?site_id=%(site_id)d"> (in Comon)</a>'%locals()
-            description += '</li>'
-        else:
-            description += '<li>No node</li>'
-        #SLICES
-        if nb_slices:
-            description += '<li><a href="%(apiurl)s/db/slices/index.php?site_id=%(site_id)d">%(nb_slices)d slice(s)</a></li>'%locals()
-        else:
-            description += '<li>No slice</li>'
-        # PEER
-        if peer_id:
-            peername = self.peer_name(site,peers)
-            description += '<li>'
-            description += '<a href="%(apiurl)s/db/peers/index.php?id=%(peer_id)d">At peer %(peername)s</a>'%locals()
-            description += '</li>'
-        # close description
-        description +='</ul>'
-
-        if not self.options.labels:
-            name=""
-            description=""
-
         # STYLE
-        if self.options.use_google_icons:
+        # the size for google icons
+        if not self.options.use_custom_icons:
             if not peer_id:
                 # local sites
                 iconfile=default_local_builtin
@@ -148,6 +113,7 @@ class KmlMap:
                 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
@@ -158,6 +124,64 @@ class KmlMap:
 
         iconspec="<href>%(iconurl)s</href>%(xyspec)s"%locals()
 
+        # open description
+        description  = "<br/><table style='border: 1px solid black; padding: 5px;' width='500px'>"
+
+        # TESTBED
+        description += "<tr><td></td><td>&nbsp;</td><td></td></tr>"
+        description += "<tr><td align='center'>"
+        description += "<b>Testbed</b>"
+        description += "</td><td>"
+        (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>"
+        description += "<img src='%(iconurl)s'/>"%locals()
+       description += "</td></tr>"
+
+       # URL
+        if site['url']:
+            site_url=site['url']
+            description += "<tr><td align='center'>"
+            description += "<b>Website</b>"
+            description += "</td><td>"
+            description += "<a style='text-decoration: none;' href='%(site_url)s'> %(site_url)s </a>"%locals()
+            description += "</td><td></td></tr>"
+
+        description += "<tr><td></td><td>&nbsp;</td><td></td></tr>"
+        description += "<tr><td align='center'>Usage details:</td><td></td><td></td></tr>"
+        description += "<tr><td></td><td>&nbsp;</td><td></td></tr>"
+
+        # NODES
+        description += "<tr><td align='center'>"
+        description += "<img src='%(apiurl)s/sites/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()
+            #description += "<a style='text-decoration: none;' href='%(apiurl)s/db/nodes/comon.php?site_id=%(site_id)d'> (in Comon)</a>"%locals()
+        else:
+            description += "<i>No node</i>"
+        description += "</td><td></td></tr>"
+
+        #SLICES
+        description += "<tr><td align='center'>"
+        description += "<img src='%(apiurl)s/sites/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()
+        else:
+            description += "<i>No slice</i>"
+        description += "</td><td></td></tr>"
+
+        description += "<tr><td></td><td>&nbsp;</td><td></td></tr>"
+
+        # close description
+        description += "</table>"
+
+        if not self.options.labels:
+            name=""
+            description=""
+
         # set the camera 50km high
         template="""<Placemark>
 <Style><IconStyle><Icon>%(iconspec)s</Icon></IconStyle></Style>
@@ -186,15 +210,16 @@ def main () :
     parser.add_option("-n","--no-label",action="store_false",dest="labels",
                       default=True,
                       help="outputs only geographic positions, no labels")
-    parser.add_option("-c","--custom",action="store_false",dest="use_google_icons",
-                      default=True,
-                      help="use locally customized icons rather than the google-provided defaults")
+    # default - for private depls. - is to use google-provided icons like palette-3
+    parser.add_option("-c","--custom",action="store_true",dest="use_custom_icons",
+                      default=False,
+                      help="use locally customized icons rather than the %s and %s defaults"%(default_local_builtin,default_foreign_builtin))
     parser.add_option("-l","--local",action="store",dest="local_icon",
                       default=default_local_icon,
-                      help="set icon url to use for local sites marker -- default is %s"%default_local_icon)
+                      help="set icon url to use for local sites marker -- requires -c -- default is %s"%default_local_icon)
     parser.add_option("-f","--foreign",action="store",dest="foreign_icon",
                       default=default_foreign_icon,
-                      help="set icon url to use for foreign sites marker -- default is %s"%default_foreign_icon)
+                      help="set icon url to use for foreign sites marker -- requires -c -- default is %s"%default_foreign_icon)
 
     (options, args) = parser.parse_args()
     if len(args) != 0: