GUI to deploy/undeploy Tomcat webapps (Python/Tkinter)

Don't forget top update your Tomcat folder path and your Projects folder path at the beginning of the script.

#!/usr/bin/python
 
from os import *
from Tkinter import *
 
tomcatWebappsFolderPath="/usr/share/tomcat5.5/webapps"
projectsFolderPath="/home/jerome/projects"
 
 
class App:
 
    def __init__(self, master):
 
	# title
        titleFrame = Frame(master)
        titleFrame.pack()
	titleLabel = Label(titleFrame, text="Tomcat Web applications")
        titleLabel.pack(side=LEFT) 
 
 
	# web app list	
	listBoxFrame = Frame(master)
        listBoxFrame.pack()
 
	scrollbar = Scrollbar(listBoxFrame, orient=VERTICAL)
	self.listbox = Listbox(listBoxFrame, selectmode=MULTIPLE, yscrollcommand=scrollbar.set, height=20)
	self.listbox.pack()
	scrollbar.config(command=self.listbox.yview)
	scrollbar.pack(side=RIGHT, fill=Y)
	self.listbox.pack(side=LEFT, fill=BOTH, expand=1)
 
	self.refresh()
 
	# buttons
	frame = Frame(master)
        frame.pack()
 
        self.button = Button(frame, text="Quit", fg="red", command=frame.quit)
        self.button.pack(side=LEFT)
 
        self.hi_there = Button(frame, text="Update", command=self.update)
        self.hi_there.pack(side=LEFT)
 
 
 
    def update(self):
    	i = 0
	for webApp in self.listbox.get(0, END):
		isSelected = self.listbox.selection_includes(i)
		isDeployed = webApp in self.deployedWebApps
 
		if isSelected and not(isDeployed):
			self.deploy(webApp)			
		elif not(isSelected) and isDeployed:
			self.undeploy(webApp)
 
		i = i + 1
	self.refresh()
 
 
    def refresh(self):
	self.allWebApps = listdir(projectsFolderPath)
	self.allWebApps.sort()
	self.deployedWebApps = listdir(tomcatWebappsFolderPath)	
 
	self.listbox.delete(0, END)
	i = 0
	for webApp in self.allWebApps:
		el = self.listbox.insert(END, webApp)
		if webApp in self.deployedWebApps:
			self.listbox.selection_set(i)
		i = i+1
	print "Done!"
	print "------------------------------------------------"
 
 
    def deploy(self, webApp):
    	print "deploying " + webApp + "..."
    	chdir(tomcatWebappsFolderPath)
    	src = projectsFolderPath + "/" + webApp
	dest = webApp
	symlink(src, dest)
 
 
    def undeploy(self, webApp):
    	print "undeploying " + webApp + "..."
    	path = tomcatWebappsFolderPath + "/" + webApp
	remove(path)
 
root = Tk()
app = App(root)
root.mainloop()

Feedback

aaaa
wwww
May 31, 2009
#1