[GRASS-SVN] r47776 - grass-addons/grass7/gui/wxpython/wx.wms

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 19 09:59:20 EDT 2011


Author: sudeepsingh
Date: 2011-08-19 06:59:20 -0700 (Fri, 19 Aug 2011)
New Revision: 47776

Modified:
   grass-addons/grass7/gui/wxpython/wx.wms/LoadConfig.py
   grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py
   grass-addons/grass7/gui/wxpython/wx.wms/TODO
   grass-addons/grass7/gui/wxpython/wx.wms/WMSMapDisplay.py
   grass-addons/grass7/gui/wxpython/wx.wms/__init__.py
   grass-addons/grass7/gui/wxpython/wx.wms/addserver.py
   grass-addons/grass7/gui/wxpython/wx.wms/config
   grass-addons/grass7/gui/wxpython/wx.wms/parse.py
   grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py
Log:
Integerated Stable version.Most Bugs Fixed, Certian features to be added soon in next commit in TODO file

Modified: grass-addons/grass7/gui/wxpython/wx.wms/LoadConfig.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/LoadConfig.py	2011-08-19 12:02:02 UTC (rev 47775)
+++ grass-addons/grass7/gui/wxpython/wx.wms/LoadConfig.py	2011-08-19 13:59:20 UTC (rev 47776)
@@ -1,10 +1,45 @@
+"""!
+ at package LoadConfig.py
+
+ at brief Python function to load configuration file for
+wmsmenu.py and addserver.py.
+
+(C) 2006-2011 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+Functions:
+ - loadConfigFile
+
+ at author: Maris Nartiss (maris.nartiss gmail.com)
+ at author Sudeep Singh Walia (Indian Institute of Technology, Kharagpur , sudeep495 at gmail.com)
+"""
+
 import os
 def loadConfigFile(self):
     try:
-        f=open('./config','r')
+        f=open('config','r')
         lines = f.readlines()
         f.close()
-        self.name_url_delimiter = lines[0].split()[1]
+        print lines
+        #patch4s
+        try:
+            if(len(lines)!=3):
+                print 'Insufficient number of arguments,3 paramters required name_url_delimiter, timeoutValueSeconds, urlLength'
+                raise Exception
+            self.name_url_delimiter = lines[0].split(':')[1]
+            self.timeoutValueSeconds = int(lines[1].split(':')[1])
+            self.urlLength = int(lines[2].split(':')[1])
+            #self.name_url_delimiter = '\n'
+            print self.timeoutValueSeconds
+        except Exception, e:
+            print e
+            print 'Internal exception, config file format error, using default values'
+            self.name_url_delimiter = '#'
+            self.timeoutValueSeconds = 5
+            self.urlLength = 50
+        #patch4e
         print "config file loaded successfully"
         print self.name_url_delimiter
         return True

Modified: grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py	2011-08-19 12:02:02 UTC (rev 47775)
+++ grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py	2011-08-19 13:59:20 UTC (rev 47776)
@@ -1,3 +1,27 @@
+"""!
+ at package ServerInfoAPIs.py
+
+ at brief Python code providing API's for managing the xml
+based file storing of the server information. 
+
+Classes:
+ - ServerData
+Functions:
+ - initServerInfoBase
+ - ifServerNameExists
+ - addServerInfo
+ - removeServerInfo
+ - updateServerInfo
+ - getAllRows
+
+(C) 2006-2011 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author: Maris Nartiss (maris.nartiss gmail.com)
+ at author Sudeep Singh Walia (Indian Institute of Technology, Kharagpur , sudeep495 at gmail.com)
+"""
 from BeautifulSoup import BeautifulSoup, Tag, BeautifulStoneSoup
 import os.path
 

Modified: grass-addons/grass7/gui/wxpython/wx.wms/TODO
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/TODO	2011-08-19 12:02:02 UTC (rev 47775)
+++ grass-addons/grass7/gui/wxpython/wx.wms/TODO	2011-08-19 13:59:20 UTC (rev 47776)
@@ -15,9 +15,9 @@
 6.In case, on adding or removing a server, if the write to file is unsuccessful, the application removes it from the serverlist, even though is not written in the file.
 So when the application restarts, all the changes done are lost, since data was not written to file successfuly. 
 
-7.Name of temporary file to be changed to ServersList.xml~ from tempList.xml
+7.[done]Name of temporary file to be changed to ServersList.xml~ from tempList.xml
 
-8.The Save/Dont Save/Cancel popup works fine for the first time, but for the 2nd time leads to PyDeadObjectError error. This bug is known and is of serious nature. Fix to be done soon. 
+8.[done]The Save/Dont Save/Cancel popup works fine for the first time, but for the 2nd time leads to PyDeadObjectError error. This bug is known and is of serious nature. Fix to be done soon. 
 Some other issues detected with this popup. Like when adding a new server name "</servername>" , and then click on save and then on quit, the popup appears, now click on cancel. After clicking on cancel, another popup appears and this continues. Serious issue. This popups code needs to be checked throughly. 
 
 9.On quiting the application it leads to segmentation error or even after quiting application the console doesnot quits. Need to use ctrl-c right now.
@@ -29,6 +29,23 @@
 12.If ServersList.xml doesnot exist, then when new servers are added in manager servers window, then on selecting getcapabities, somehow the self.map_servernameTouid doesnot gets updated and is shows a key error. 
 
 13.when a server requires username and password, this is not figured out yet. 
+
+14.[done]On giving servername = now++ and url = now++, and then saving it.  it behaves starngely in hitting quit after saving. 
+
+15.[done]To check the getmap functionality (now uses temp file) 
+
+16.To check return values of self.savexml()
+
+17.SUBMITTING_PYTHON point 13 to be implemented
+
+18.ErrorTrace2.log
+
+19.ErrorTrace1.log
+
+20.Add a reduntant blank item in the serverlist which is displayed
+
+21.In integerated version, when the application is started closed and then again started it gives pydeadobject error. this is probably due to improper exiting in the first quit
+
 More to be added...
 
 
@@ -107,9 +124,9 @@
 
 
 
-Issue reported by Maris, Mail 2
+Issues reported by Maris, Mail 2
 
-* To display important error messages to user use wx.MessageDialog
+*[done] To display important error messages to user use wx.MessageDialog
 with standard options (OK, ERROR icon). For example, "fill all fields"
 should be changed to popup dialog and it also should list missing
 fields. Like: "Following required fields are missing: <LIST OF
@@ -117,7 +134,7 @@
 *[done] Saving a new server should send a signal to main windows (wmsFrame)
 server list to update itself.
 *[done] Closing main application window (wmsFrame) should close also AddServer dialog.
-* If user has edited some of server fields without Save or SaveNew,
+*[done] If user has edited some of server fields without Save or SaveNew,
 onClose should ask "There are unsaved changes. Save/SaveNew"
 
 More important:
@@ -134,9 +151,49 @@
 
 
 
+Issues reported by Maris, Mail 3
 
+Add server:
+*[done] Impossible to close window without saving changes ("Don't save" doesn't work)
+*[done, rigorous testing needs to be done] URL field doesn't accept & symbol, still it's a valid URL symbol and
+should be allowed as some WMS URLs require GET parameters and they are
+separated by &
 
+WMS menu:
+*[done] If GetCapabilities times out, it should display a pop-up window with error.
+*[done][requests now time out after time set in config file, default 5 seconds] After GetCapabilities request has timed out, wmsmenu window is
+locked and it's impossible to do anything. It should be back in
+working state.
+* FEATURE: Add ability to stop running request.
+* Current server list implementation:
+**[done] fails to select a new server when it is added to list (one can
+select it, still it fails with "No server selected")
+**[done] long URLs break dropdown list
+**[done] sometimes throws key/value error instead of GetCapabilities action
+OnServerList: done
+key error reported
+{}
 
+* URLs should be pre-processed before using them!
+** URL already might contain some parameters. Here's an list of valid
+URLs. Your code should be ready to use all of them by removing or
+adding necessary URL parts:
+http://www.gisnet.lv/cgi-bin/topo
+http://giz.zpr.gov.lv/glog/Glog/entry.php?class=Mapman.MapmanWms&mapProject=mapproject0&instance=&SERVICE=WMS&REQUEST=GetCapabilities
+http://kaart.maaamet.ee/wms/alus?
+http://deli.dnr.state.mn.us/cgi-bin/wms?map=/mapfiles/contour.map&
 
+* GetMap doesn't check request EPSG code in list of service provided
+EPSG codes. Clients can request only one of servers provided EPSG SRS
+or fail.
+* GetMap doesn't perform WMS version check. Client has to use one of
+servers supported WMS versions or fail.
+* GetMap doesn't perform check of supported output formats. Some
+services might not provide PNG as an output option.
 
+I think it would be enough for now.
 
+
+
+
+

Modified: grass-addons/grass7/gui/wxpython/wx.wms/WMSMapDisplay.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/WMSMapDisplay.py	2011-08-19 12:02:02 UTC (rev 47775)
+++ grass-addons/grass7/gui/wxpython/wx.wms/WMSMapDisplay.py	2011-08-19 13:59:20 UTC (rev 47776)
@@ -1,3 +1,23 @@
+"""!
+ at package WMSMapDisplay.py
+
+ at brief Python code for displaying the fetched map
+from wms server. 
+
+Classes:
+ - ImagePanel
+Functions:
+ - NewImageFrame
+ 
+(C) 2006-2011 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author: Maris Nartiss (maris.nartiss gmail.com)
+ at author Sudeep Singh Walia (Indian Institute of Technology, Kharagpur , sudeep495 at gmail.com)
+"""
+
 import wx
 import  cStringIO
 
@@ -2,6 +22,6 @@
 class ImagePanel(wx.Panel):
-   def __init__(self, parent, id):
+   def __init__(self, parent, id, tempFile):
     wx.Panel.__init__(self, parent, id)
     try:
-        imageFile = 'map.png'
+        imageFile = tempFile
         data = open(imageFile, "rb").read()
@@ -16,9 +36,9 @@
         print "Image file %s not found" % imageFile
         raise SystemExit
 
-def NewImageFrame(): 
+def NewImageFrame(tempFile): 
     NewWindowapp = wx.PySimpleApp()
     NewWindowframe = wx.Frame(None, -1, "Map Display", size = (400, 300))
-    ImagePanel(NewWindowframe,-1)
+    ImagePanel(NewWindowframe,-1,tempFile)
     NewWindowframe.Show(1)
     NewWindowapp.MainLoop()

Modified: grass-addons/grass7/gui/wxpython/wx.wms/__init__.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/__init__.py	2011-08-19 12:02:02 UTC (rev 47775)
+++ grass-addons/grass7/gui/wxpython/wx.wms/__init__.py	2011-08-19 13:59:20 UTC (rev 47776)
@@ -1,9 +1,8 @@
 all = [
-    "addserver",
-    "parse",
-    "passwordPopUp",
-    "ServerInfoAPIs",
-    "WMSMapDisplay",
-    "wmsmenu",
+    "addserver.py",
+    "parse.py",
+    "ServerInfoAPIs.py",
+    "WMSMapDisplay.py",
+    "wmsmenu.py",
     "LoadConfig.py"
 ]

Modified: grass-addons/grass7/gui/wxpython/wx.wms/addserver.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/addserver.py	2011-08-19 12:02:02 UTC (rev 47775)
+++ grass-addons/grass7/gui/wxpython/wx.wms/addserver.py	2011-08-19 13:59:20 UTC (rev 47776)
@@ -1,3 +1,22 @@
+"""!
+ at package addserver.py
+
+ at brief Main Python app for managing the server information. 
+Add a new server, Edit an existing server, Remove an existing
+server.
+
+Classes:
+ - ServerData
+ - ServerAdd
+
+(C) 2006-2011 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author: Maris Nartiss (maris.nartiss gmail.com)
+ at author: Sudeep Singh Walia (Indian Institute of Technology, Kharagpur , sudeep495 at gmail.com)
+"""
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 # generated by wxGlade 0.6.3 on Thu Jul 14 06:22:35 2011
@@ -4,20 +23,24 @@
 
 import wx
 import os
+import popen2
 import uuid
+from grass.script import core as grass
 from wx.lib.pubsub import Publisher
 from BeautifulSoup import BeautifulSoup, Tag, NavigableString, BeautifulStoneSoup
 from ServerInfoAPIs import addServerInfo, removeServerInfo, updateServerInfo, initServerInfoBase, getAllRows
 from LoadConfig import loadConfigFile
-from savepopup import SavePopUp
 
 
+
 # begin wxGlade: extracode
 # end wxGlade
 
 class ServerData():
     pass
 
+class Message():
+    pass
 
 class ServerAdd(wx.Frame):
     def __init__(self, *args, **kwds):
@@ -61,6 +84,7 @@
         #sudeep code starts
         if( not loadConfigFile(self)):
             print 'Config File Error, Unable to start application...'
+            grass.fatal_error('Config File Error, Unable to start application...')
             self.Close()
         
         self.soup, open = initServerInfoBase('ServersList.xml')
@@ -160,10 +184,9 @@
             return
         
         
-        if(not newUrl.startswith('http://')):
-            newUrl = 'http://'+newUrl
         
         
+        
         print newServerName
         print 'check12'
         
@@ -202,11 +225,14 @@
                     if(self.valueExists(self.servers, newServerName)):
                         message = "ServerName already exists. Please enter a different ServerName"
                         self.ShowMessage(message, 'Warning')
+                        grass.warning(message)
                         StatusBar_fields = [message]
                         self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
                         print message
                         return
             #del self.servers[self.selectedUid]
+            if(not newUrl.startswith('http://')):
+                newUrl = 'http://'+newUrl
             serverData.servername = newServerName
             serverData.url = newUrl
             serverData.username = newUserName
@@ -215,21 +241,52 @@
             
             if(update):
                 if(updateServerInfo(self.soup, self.soup.serverinfo, self.selectedUid, newServerName, newUrl, newUserName, newPassword)):
-                    print 'update save successful'
                     
+                    #patch7s
+                    if(not self.saveXMLData()):
+                        oldInfo = self.servers[self.selectedUid]
+                        if(updateServerInfo(self.soup, self.soup.serverinfo, self.selectedUid, oldInfo.servername, oldInfo.url, oldInfo.username, oldInfo.password)):
+                            message = 'Unable to SaveXML, changes reverted back'
+                            print message
+                            grass.warning(message)
+                            return
+                        else:
+                            message = 'Unable to SaveXML, changes will be reverted back on restart'
+                            print message
+                            grass.warning(message)
+                            return
+                    #patch7e
                     #self.StatusBar.setStatusText("Information Updated")
+                    message = 'update save successful'
+                    print message
+                    grass.message(message)
                     self.servers[self.selectedUid] = serverData
                     del self.map_servernameTouid[self.selectedServer.servername]
                     self.selectedServer = serverData
                     self.map_servernameTouid[newServerName] = self.selectedUid
-                    self.saveXMLData()
+                    
+                    #patch5s
                     msg = self.servers
-                    StatusBar_fields = ["Server Info Updated"]
+                    print 'sending serverlist as message'
+                    Publisher().sendMessage(("update.serverList"), msg)
+                    print 'message sent'
+                    
+                    msg = self.map_servernameTouid
+                    print 'sending map_servernameTouid as a message'
+                    Publisher().sendMessage(("update.map_servernameTouid"), msg)
+                    print 'message sent'
+                    #patch5e
+                    message = "Server Info Updated"
+                    print message
+                    grass.message(message)
+                    StatusBar_fields = [message]
                     self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
-                    Publisher().sendMessage(("update.serverList"), msg)
+                    self.setModified(False)
+                    
                 else:
                     message = "Update not Successful"
                     self.ShowMessage(message, 'Warning')
+                    grass.warning(message)
                     StatusBar_fields = [message]
                     self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
                     print message
@@ -237,8 +294,23 @@
                 uid = str(uuid.uuid4())
                 
                 if(addServerInfo(self.soup, self.soup.serverinfo, uid, newServerName, newUrl, newUserName, newPassword)):
-                    print 'soup save successfully'
-                    
+                    #patch7s
+                    if(not self.saveXMLData()):
+                        #oldInfo = self.servers[uid]
+                        if(removeServerInfo(self.soup, uid)):
+                            message = 'Unable to SaveXML, Info not saved'
+                            print message
+                            grass.warning(message)
+                            return
+                        else:
+                            message = 'Unable to SaveXML, changes will be reverted back on restart'
+                            grass.warning(message)
+                            print message
+                            return
+                    #patch7e
+                    message = 'soup save successfully'
+                    print message 
+                    grass.message(message)
                     self.selectedUid = uid
                     self.servers[self.selectedUid] = serverData
                     self.selectedServer = serverData
@@ -246,14 +318,29 @@
                     print 'Onsave(): printing the self.map_servernameTouid'
                     print self.map_servernameTouid
                     print '--------------------------'
-                    self.saveXMLData()
+                    #self.saveXMLData()
+                            #patch5s
                     msg = self.servers
-                    StatusBar_fields = ["Server Info Saved Successfully"]
+                    print 'sending serverlist as message'
+                    Publisher().sendMessage(("update.serverList"), msg)
+                    print 'message sent'
+                    
+                    msg = self.map_servernameTouid
+                    print 'sending map_servernameTouid as a message'
+                    Publisher().sendMessage(("update.map_servernameTouid"), msg)
+                    print 'message sent'
+                    #patch5e
+                    #msg = self.servers
+                    message = "Server Info Saved Successfully"
+                    grass.message(message)
+                    StatusBar_fields = [message]
                     self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
-                    Publisher().sendMessage(("update.serverList"), msg)
+                    self.setModified(False)
+                    #Publisher().sendMessage(("update.serverList"), msg)
                 else:
                     message = "Save not successful"
                     self.ShowMessage(message, 'Warning')
+                    "Server Info Saved Successfully"
                     StatusBar_fields = [message]
                     self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
                     print message
@@ -272,6 +359,7 @@
         else:
             message = "Please fill servername and url fields"
             self.ShowMessage(message, 'Warning')
+            grass.warning(message)
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
             print message
@@ -286,15 +374,18 @@
         if(self.selectedUid == None):
             message = "No Server selected....Remove Unsuccessful"
             self.ShowMessage(message, 'Warning')
+            grass.warning(message)
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
             print message
             return
         else:
             if(removeServerInfo(self.soup, self.selectedUid)):
-                StatusBar_fields = ["Remove Successful"]
+                message = "Remove Successful"
+                StatusBar_fields = [message]
                 self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
-                print 'remove successful'
+                grass.message(message)
+                print message
                 del self.map_servernameTouid[self.selectedServer.servername]
                 if(len(self.servers) > 0):
                     self.ServerList.SetSelection(0)
@@ -303,6 +394,7 @@
             else:
                 message = "Remove Unsuccessful"
                 self.ShowMessage(message, 'Warning')
+                grass.warning(message)
                 StatusBar_fields = [message]
                 self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
                 print message
@@ -327,6 +419,9 @@
         event.Skip()
 
     def OnAddNew(self, event): # wxGlade: ServerAdd.<event_handler>
+        #patch1s
+        self.checkIfModified(event)
+        #patch1e
         print '-------------------------------------------------------------------> OnAddNew'
         #print "Event handler `OnAddNew' not implemented"
         self.selectedUid = None
@@ -336,16 +431,19 @@
         self.UsernameText.Clear()
         self.editOn = False
         self.selectedServer=None
-        StatusBar_fields = [""]
+        #patch3s
+        StatusBar_fields = ["Fill in the Info fields"]
+        #patch3e
         self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
         event.Skip()
     
     def OnQuit(self, event): # wxGlade: ServerAdd.<event_handler>
         print '-------------------------------------------------------------------> OnQuit'
         print 'onQuit pressed'
-        if(self.editOn):
-            print "Do you want to save the unsaved changes ?"
-            SavePopUp()
+        #patch1s
+        if(self.checkIfModified(event) == wx.ID_CANCEL):
+            return
+        #patch1e
         self.saveXMLData()
         msg = self.servers
         Publisher().sendMessage(("Add_Server_Frame_Closed"), msg)
@@ -361,6 +459,9 @@
         event.Skip()
 
     def OnServerList(self, event): # wxGlade: ServerAdd.<event_handler>
+        #patch1s
+        self.checkIfModified(event)
+        #patch1e
         print '-------------------------------------------------------------------> OnServerList'
         #print self.ServerList.CurrentSelection
         url = self.ServerList.GetValue()
@@ -379,9 +480,11 @@
             self.UsernameText.SetValue(self.selectedServer.username)
             self.PasswordText.SetValue(self.selectedServer.password)
         else:
-            StatusBar_fields = ["Wrong format of URL selected"]
+            message = "Wrong format of URL selected"
+            StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
-            print "Wrong format of URL selected"
+            print message
+            grass.fatal_error(message)
             
         #self.ServerNameText.SetValue(self.servers)
         event.Skip()
@@ -392,13 +495,35 @@
     #wxGlade methods ends
     
     #Sudeeps methods start
+    #patch1s
+    def setModified(self, booleanValue):
+        self.ServerNameText.SetModified(booleanValue)
+        self.URLText.SetModified(booleanValue)
+        self.UsernameText.SetModified(booleanValue)
+        self.PasswordText.SetModified(booleanValue)
+        
+    def checkIfModified(self, event):
+        if(self.URLText.IsModified() or self.ServerNameText.IsModified() or self.UsernameText.IsModified() or self.PasswordText.IsModified()):
+            dial = wx.MessageDialog(None, 'You have unsaved changes.\n Do you want to save them ?', 'Quit',
+                                    wx.STAY_ON_TOP | wx.YES_NO | wx.YES_DEFAULT | wx.CANCEL | wx.ICON_QUESTION)
+        
+            val = dial.ShowModal()
+            if val == wx.ID_CANCEL:
+                return val
+            if val == wx.ID_YES:
+                self.OnSave(event) #well, the parameter is unused
+                return val
+    #patch1e
+    
     def ShowMessage(self, message, type = 'Warning'):
         wx.MessageBox(message, type)
         
     def __populate_URL_List(self, ComboBox):
         self.servers, self.map_servernameTouid = getAllRows(self.soup)
         for key, value in self.servers.items():
-            ComboBox.Append(value.servername+self.name_url_delimiter+value.url)
+            #string = '{0}{1}{2}'.format(value.servername,self.name_url_delimiter,value.url[0:self.urlLength])
+            #ComboBox.Append(string)
+            ComboBox.Append(value.servername+self.name_url_delimiter+value.url[0:self.urlLength])
             #ComboBox.Append(value.servername+" "+value.url)
         #print self.servers
         return
@@ -407,21 +532,44 @@
         self.ServerList.Clear()
         for key,value in self.servers.iteritems():
             #name = v.servername+" "+v.url
-            self.ServerList.Append(value.servername+self.name_url_delimiter+value.url)
+            ComboBox = self.ServerList
+            #string = '{0}{1}{2}'.format(value.servername,self.name_url_delimiter,value.url[0:self.urlLength])
+            #ComboBox.Append(string)
+            ComboBox.Append(value.servername+self.name_url_delimiter+value.url[0:self.urlLength])
             #self.ServerList.Append(name)
 
     def saveXMLData(self):
         xml = self.soup.prettify()
+        
         try:
-            f = open('templist.xml','w')
+            TMP = grass.tempfile()
+            if TMP is None:
+                grass.fatal_error("Unable to create temporary files")
+            print TMP
+            f = open(TMP,'w')
             f.write(xml)
             f.close()
         except:
-            print 'Unable to write in templist.xml file, Save not successful'
+            message = 'Unable to write in '+TMP+' file, Save not successful'
+            print message
+            grass.warning(message)
             return False
         try:    
             #os.system('chmod 777 ServersList.xml')
-            os.system("cp templist.xml ServersList.xml")
+            copyCommand = "cp "+TMP+" ServersList.xml"
+            r, w, e = popen2.popen3(copyCommand)
+            if(len(e.readlines())!=0):
+                message = 'Copy failed, raising excpetion in savexml()'
+                grass.warning(message)
+                r.close()
+                w.close()
+                e.close()
+                raise Exception
+            r.close()
+            w.close()
+            e.close()
+
+            #os.system("cp templist.xml ServersList.xml")
             #f = open('ServersList.xml','w')
         except:
             #print 'cant open file in write mode'
@@ -436,6 +584,7 @@
                 StatusBar_fields = [message]
                 self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
                 self.ShowMessage(message, 'Warning')
+                grass.warning(message)
                 print "Warning: UserName cannot consist of "+self.name_url_delimiter
                 print "Please give another username, save failed..."
                 return False
@@ -445,6 +594,7 @@
                 StatusBar_fields = ["Warning: URL Delimiter conflict. Edit config file"]
                 self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
                 self.ShowMessage(message, 'Warning')
+                grass.warning(message)
                 print "Warning: URL cannot consist of "+self.name_url_delimiter
                 print "Change in config file required to use different character as delimeter which doesnot appears in url"
                 return False
@@ -453,6 +603,7 @@
         if(newServerName.count(character) > 0 or newUrl.count(character) > 0 or newUserName.count(character) > 0 or newPassword.count(character) > 0):
             message = character+' is not allowed in a Field'
             self.ShowMessage(message, 'Warning')
+            grass.warning(message)
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
             print message
@@ -462,15 +613,20 @@
         if(newServerName.count(character) > 0 or newUrl.count(character) > 0 or newUserName.count(character) > 0 or newPassword.count(character) > 0):
             message = character+' is not allowed in a Field'
             self.ShowMessage(message, 'Warning')
+            grass.warning(message)
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
             print message
             return False
         
         character = '&'
-        if(newServerName.count(character) > 0 or newUrl.count(character) > 0 or newUserName.count(character) > 0 or newPassword.count(character) > 0):
+        #patch2s
+        #or newUrl.count(character) > 0
+        #patch2e
+        if(newServerName.count(character) > 0  or newUserName.count(character) > 0 or newPassword.count(character) > 0):
             message = character+' is not allowed in a Field'
             self.ShowMessage(message, 'Warning')
+            grass.warning(message)
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
             print message

Modified: grass-addons/grass7/gui/wxpython/wx.wms/config
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/config	2011-08-19 12:02:02 UTC (rev 47775)
+++ grass-addons/grass7/gui/wxpython/wx.wms/config	2011-08-19 13:59:20 UTC (rev 47776)
@@ -1 +1,3 @@
-delimeter_servername_url #
+delimeter_servername_url:--
+timeoutValueSeconds:20
+urlLength:50

Modified: grass-addons/grass7/gui/wxpython/wx.wms/parse.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/parse.py	2011-08-19 12:02:02 UTC (rev 47775)
+++ grass-addons/grass7/gui/wxpython/wx.wms/parse.py	2011-08-19 13:59:20 UTC (rev 47776)
@@ -1,3 +1,27 @@
+"""!
+ at package parse.py
+
+ at brief Python app for parsing the getCapabilties reponse, checking
+service exception in the wms server reply and hierarchical display
+of layers.
+
+Functions:
+ - parsexml
+ - isValidResponse
+ - isServiceException
+ - populateLayerTree
+ - dfs
+
+(C) 2006-2011 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author: Maris Nartiss (maris.nartiss gmail.com)
+ at author Sudeep Singh Walia (Indian Institute of Technology, Kharagpur , sudeep495 at gmail.com)
+"""
+
+from grass.script import core as grass
 from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
 import re
 from urllib2 import Request, urlopen, URLError, HTTPError
@@ -53,11 +77,17 @@
 
    
 def populateLayerTree(xml,LayerTree, layerTreeRoot):
-	f = open('cacheGetCapabilities.xml','w')
+	TMP = grass.tempfile()
+	if TMP is None:
+		grass.fatal("Unable to create temporary files")
+	print '########################'
+	print TMP
+	print '########################'
+	f = open(TMP,'w')
 	f.write(xml)
 	f.close()
 	
-	f = open('cacheGetCapabilities.xml','r')
+	f = open(TMP,'r')
 	xml = f.read()
 	#print xml
 	soup = BeautifulSoup(xml)

Modified: grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py	2011-08-19 12:02:02 UTC (rev 47775)
+++ grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py	2011-08-19 13:59:20 UTC (rev 47776)
@@ -1,3 +1,23 @@
+"""!
+ at package wmsmenu.py
+
+ at brief Main python app for handling wms requests for getCapabilities
+and getMaps.  
+
+Classes:
+ - wmsFrame
+Functions:
+ - DisplayWMSMenu
+ 
+(C) 2006-2011 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author: Maris Nartiss (maris.nartiss gmail.com)
+ at author Sudeep Singh Walia (Indian Institute of Technology, Kharagpur , sudeep495 at gmail.com)
+"""
+
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 # generated by wxGlade 0.6.3 on Mon Jul 11 04:58:20 2011
@@ -4,6 +24,7 @@
 
 import wx
 from wxPython.wx import *
+from grass.script import core as grass
 import imghdr
 from wx.lib.pubsub import Publisher
 from urllib2 import Request, urlopen, URLError, HTTPError
@@ -17,8 +38,9 @@
 # begin wxGlade: extracode
 # end wxGlade
 
+class Message():
+    pass
 
-
 class wmsFrame(wx.Frame):
     def __init__(self, *args, **kwds):
         # begin wxGlade: wmsFrame.__init__
@@ -52,8 +74,10 @@
         #self.urlInput.SetValue('http://www.gisnet.lv/cgi-bin/topo')
         self.usernameInput.Disable()
         self.passwordInput.Disable()
+        print 'new version'
         if( not loadConfigFile(self)):
             print 'Config File Error, Unable to start application...'
+            grass.fatal_error('Config File Error, Unable to start application...')
             self.Close()
             return
 
@@ -66,7 +90,9 @@
         self.layerTreeRoot = self.LayerTree.AddRoot("Layers")
         Publisher().subscribe(self.onAddServerFrameClose, ("Add_Server_Frame_Closed"))
         Publisher().subscribe(self.onUpdateServerListmessage, ("update.serverList"))
+        Publisher().subscribe(self.onUpdateMapListmessage, ("update.map_servernameTouid"))
         
+        
         self.Bind(wx.EVT_CLOSE, self.OnQuit)
         self.AddServerisClosed = True
         self.layerName = ""
@@ -116,7 +142,9 @@
     def __update_Url_List(self, ComboBox):
         ComboBox.Clear()
         for key, value in self.servers.items():
-            ComboBox.Append(value.servername+self.name_url_delimiter+value.url)
+            #string = '{0}{1}{2}'.format(value.servername,self.name_url_delimiter,value.url[0:self.urlLength])
+            #ComboBox.Append(string)
+            ComboBox.Append(value.servername+self.name_url_delimiter+value.url[0:self.urlLength])
             #ComboBox.Append(value.servername+" "+self.name_url_delimiter+" "+value.url)
         #print self.servers
         return
@@ -127,7 +155,9 @@
     def __populate_Url_List(self, ComboBox):
         self.servers, self.map_servernameTouid = getAllRows(self.soup)
         for key, value in self.servers.items():
-            ComboBox.Append(value.servername+self.name_url_delimiter+value.url)
+            #string = '{0}{1}{2}'.format(value.servername,self.name_url_delimiter,value.url[0:self.urlLength])
+            #ComboBox.Append(string)
+            ComboBox.Append(value.servername+self.name_url_delimiter+value.url[0:self.urlLength])
             #ComboBox.Append(value.servername+" "+self.name_url_delimiter+" "+value.url)
         #print self.servers
         return
@@ -151,6 +181,7 @@
             self.ShowMessage(message, 'Warning')
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
+            grass.warning(message)
             print message
             return
         
@@ -167,13 +198,14 @@
         self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
         req = Request(url)
         try:
-            response = urlopen(req)
+            response = urlopen(req, None, self.timeoutValueSeconds)
             xml = response.read()
             if(not isValidResponse(xml)):
                 message = "Invalid GetCapabilities response"
                 self.ShowMessage(message, 'Warning')
                 StatusBar_fields = [message]
                 self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
+                grass.warning(message)
                 print message
                 return
             if(isServiceException(xml)):
@@ -181,6 +213,7 @@
                 self.ShowMessage(message, 'Warning')
                 StatusBar_fields = [message]
                 self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
+                grass.warning(message)
                 print message                
                 return
             #for testing pruposes
@@ -200,16 +233,19 @@
             print message
             #print 'Error code: ', e.code
         except URLError, e: 
-            message = 'We failed to reach a server.'
+            message = 'Failed to reach a server.'
             print message
             #print 'Reason: ', e.reason
         except ValueError, e:
             message = 'Value error'
             print message
             #print 'Reason: ', e.reason
-        except:
+        except Exception, e:
             message = 'urlopen exception, unable to fetch data for getcapabilities'
+            message = str(e)
+            print 'printing exception here'
             print message
+            print 'done'
         else:
             message = 'Successful'
             print message
@@ -218,10 +254,11 @@
                 self.ShowMessage(message, 'Warning')
                 StatusBar_fields = [message]
                 self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
+                grass.warning(message)
         else:
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- 
+            grass.message(message)
             #Sudeep's Code Ends
         event.Skip()
         
@@ -234,6 +271,7 @@
         if(self.selectedURL == "No server selected"):
             message = 'No server selected'
             print message
+            grass.warning(message)
             self.ShowMessage(message, 'Warning')
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
@@ -253,7 +291,7 @@
             message = 'GetMaps request sent. Waiting for response...'
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
-            response = urlopen(req)
+            response = urlopen(req, None, self.timeoutValueSeconds)
             image = response.read()
             #print image
             
@@ -261,25 +299,33 @@
                 message = 'Service Exception has occured'
                 self.ShowMessage(message, 'Warning')
                 print message
+                grass.warning(message)
                 StatusBar_fields = [message]
                 self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
             else:
-                outfile = open('map.png','wb')
+                TMP = grass.tempfile()
+                if TMP is None:
+                    grass.fatal("Unable to create temporary files")
+                print TMP
+                
+                outfile = open(TMP,'wb')
                 outfile.write(image)
                 outfile.close()
-                if(imghdr.what('./map.png') != 'png'):
+                if(imghdr.what(TMP) != 'png'):
                     #print 'uiui'
                     #print imghdr.what('./map.png')
                     message = 'Not a valid PNG Image, Unable to display Map'
                     self.ShowMessage(message, 'Warning')
                     print message
+                    grass.warning(message)
                     StatusBar_fields = [message]
                     self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
                     return
                 message = 'GetMap response obtained'
+                grass.message(message)
                 StatusBar_fields = [message]
                 self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
-                NewImageFrame()
+                NewImageFrame(TMP)
             
             
         except HTTPError, e:
@@ -287,7 +333,7 @@
             print message
             #print 'Error code: ', e.code
         except URLError, e: 
-            message = 'We failed to reach a server.'
+            message = 'Failed to reach a server.'
             print message
             #print 'Reason: ', e.reason
         except ValueError, e:
@@ -304,9 +350,11 @@
         print message
         if(message != 'Successful'):
             self.ShowMessage(message, 'Warning')
+            grass.warning(message)
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
         else:
+            grass.message(message)
             StatusBar_fields = [message]
             self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
         
@@ -359,11 +407,16 @@
             	uid = self.map_servernameTouid[urlarr[0]]
             	self.selectedURL = self.servers[uid].url
             	print self.selectedURL
-            except KeyError:
-            	print 'key error reported'
+            except KeyError,e:
+                print e
+            	message = 'key error reported'
+                print message
             	print self.map_servernameTouid
+                grass.warning(message)
         else:
-            print "Wrong format of URL selected"
+            message = "Wrong format of URL selected"
+            print message
+            grass.warning(message)
         #Sudeep's Code Ends
         event.Skip()
 
@@ -399,9 +452,22 @@
         #frame.Show()
     
     def onUpdateServerListmessage(self, msg):
+        #patch5s
         self.servers = msg.data
+        print 'in update serverlistmessage()'
+        print 'printing serverlist'
+        self.printDict(self.servers)
+        #patch5e
         self.__update_Url_List(self.ServerList)
         
+        #patch5s
+    def onUpdateMapListmessage(self, msg):
+        print 'in update maplistmessage()' 
+        self.map_servernameTouid = msg.data
+        print 'printing map_servernametouid'
+        self.printDict(self.map_servernameTouid)
+        #patch5e
+        
     def OnAddServer(self, event): # wxGlade: wmsFrame.<event_handler>
         print 'before add server call'
         self.AddServerisClosed = False
@@ -427,6 +493,7 @@
 
 #Sudeep's Code Starts
 def DisplayWMSMenu():
+        print 'DisplayWMSMenu loaded...'
         app = wx.PySimpleApp(0)
         wx.InitAllImageHandlers()
         wms_Frame = wmsFrame(None, -1, "")



More information about the grass-commit mailing list