[GRASS-SVN] r47295 - grass-addons/grass7/gui/wxpython/wx.wms
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 28 08:33:34 EDT 2011
Author: sudeepsingh
Date: 2011-07-28 05:33:34 -0700 (Thu, 28 Jul 2011)
New Revision: 47295
Modified:
grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py
grass-addons/grass7/gui/wxpython/wx.wms/bgenerateDOM.py
Log:
error checking in updating server info data added
Modified: grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py 2011-07-28 12:22:53 UTC (rev 47294)
+++ grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py 2011-07-28 12:33:34 UTC (rev 47295)
@@ -1,35 +1,50 @@
from BeautifulSoup import BeautifulSoup, Tag, BeautifulStoneSoup
def addServerInfo(soup, serverinfo, snamevalue, urlvalue, unamevalue, passwordvalue):
+ elements = soup.findAll(id = snamevalue)
+ if(len(elements)!=0):
+ return False
+ else:
+ server = Tag(soup, "server")
+ serverinfo.insert(0,server)
+
+ #Creating server info tags
+ servername = Tag(soup, "servername")
+ serverurl = Tag(soup, "serverurl")
+ username = Tag(soup, "username")
+ password = Tag(soup, "password")
+
+ #Inserting server info fields
+ server.insert(0, servername)
+ server.insert(1, serverurl)
+ server.insert(2, username)
+ server.insert(3, password)
- server = Tag(soup, "server")
- serverinfo.insert(0,server)
+ #Adding attribute to server tag
+ server['id'] = snamevalue
- #Creating server info tags
- servername = Tag(soup, "servername")
- serverurl = Tag(soup, "serverurl")
- username = Tag(soup, "username")
- password = Tag(soup, "password")
-
- #Inserting server info fields
- server.insert(0, servername)
- server.insert(1, serverurl)
- server.insert(2, username)
- server.insert(3, password)
+ #Adding text values to the server info fields
+ servername.insert(0,snamevalue)
+ serverurl.insert(0, urlvalue)
+ username.insert(0, unamevalue)
+ password.insert(0, passwordvalue)
+ return True
- #Adding attribute to server tag
- server['id'] = snamevalue
-
- #Adding text values to the server info fields
- servername.insert(0,snamevalue)
- serverurl.insert(0, urlvalue)
- username.insert(0, unamevalue)
- password.insert(0, passwordvalue)
-
-def removerServerInfo(soup, serverID):
+def removeServerInfo(soup, serverID):
elements = soup.findAll(id = serverID)
- for element in elements:
- element.extract()
-
+ if(len(elements)==0):
+ return False
+ else:
+ for element in elements:
+ element.extract()
+ return True
-
\ No newline at end of file
+def updateServerInfo(soup, serverinfo, snamevalue, urlvalue, unamevalue, passwordvalue):
+ if(removeServerInfo(soup, snamevalue)):
+ print "1"
+ if(addServerInfo(soup, serverinfo, snamevalue, urlvalue, unamevalue, passwordvalue)):
+ return True
+ else:
+ return False
+ else:
+ return False
Modified: grass-addons/grass7/gui/wxpython/wx.wms/bgenerateDOM.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/bgenerateDOM.py 2011-07-28 12:22:53 UTC (rev 47294)
+++ grass-addons/grass7/gui/wxpython/wx.wms/bgenerateDOM.py 2011-07-28 12:33:34 UTC (rev 47295)
@@ -1,5 +1,5 @@
from BeautifulSoup import BeautifulSoup, Tag, NavigableString, BeautifulStoneSoup
-from ServerInfoAPIs import addServerInfo, removerServerInfo
+from ServerInfoAPIs import addServerInfo, removeServerInfo, updateServerInfo
try:
f = open('out.xml','r+')
@@ -10,14 +10,20 @@
except:
f = open('out.xml','w')
serverinfolist = []
-
+ soup = BeautifulSoup()
+
if(len(serverinfolist) == 0):
serverinfo = Tag(soup, "serverinfo")
soup.insert(0, serverinfo)
-
-addServerInfo(soup, soup.serverinfo, 'a1', 'b1', 'c1', 'd1')
-addServerInfo(soup, soup.serverinfo, 'a2', 'b2', 'c2', 'd2')
-removerServerInfo(soup, "a2")
+
+
+print addServerInfo(soup, soup.serverinfo, 'a1', 'b1', 'c1', 'd1')
+print addServerInfo(soup, soup.serverinfo, 'a2', 'b2', 'c2', 'd2')
+print addServerInfo(soup, soup.serverinfo, 'a1', 'b1', 'c1', 'd1')
+print updateServerInfo(soup, soup.serverinfo, 'a1', 'b112', 'c112', 'd112')
+print removeServerInfo(soup, "a2")
+
+
xml = soup.prettify()
f.write(xml)
f.close()
More information about the grass-commit
mailing list