Author: remi
Date: 2009-03-23 11:18:22 +0100 (Mon, 23 Mar 2009)
New Revision: 4176
Modified:
software_suite_v2/tuxware/tuxdroidserver/trunk/util/filesystem/AutoDeployer.py
software_suite_v2/tuxware/tuxdroidserver/trunk/util/filesystem/DirectoryContentObserver.py
Log:
* added doc comments.
Modified:
software_suite_v2/tuxware/tuxdroidserver/trunk/util/filesystem/AutoDeployer.py
===================================================================
---
software_suite_v2/tuxware/tuxdroidserver/trunk/util/filesystem/AutoDeployer.py
2009-03-23 09:28:43 UTC (rev 4175)
+++
software_suite_v2/tuxware/tuxdroidserver/trunk/util/filesystem/AutoDeployer.py
2009-03-23 10:18:22 UTC (rev 4176)
@@ -15,18 +15,19 @@
from DirectoryContentObserver import DirectoryContentObserver
#
------------------------------------------------------------------------------
-#
+# Class to auto-deploy plugins from a directories list.
#
------------------------------------------------------------------------------
class AutoDeployer(object):
+ """Class to auto-deploy plugins from a directories list.
+ Supported plugins must be a zipped directory like *.tgf and *.att.
"""
- """
#
--------------------------------------------------------------------------
- #
+ # Constructor of the class.
#
--------------------------------------------------------------------------
def __init__(self):
+ """Constructor of the class.
"""
- """
self.__dirMutex = threading.Lock()
self.__isDeployed = False
self.__eventMutex = threading.Lock()
@@ -44,11 +45,11 @@
self.__onPluginUndeployedCallback = None
#
--------------------------------------------------------------------------
- #
+ # Deploy the plugins from the referenced directories.
#
--------------------------------------------------------------------------
def deploy(self):
+ """Deploy the plugins from the referenced directories.
"""
- """
self.__dirMutex.acquire()
if self.__isDeployed:
self.__dirMutex.release()
@@ -61,11 +62,11 @@
self.__dirMutex.release()
#
--------------------------------------------------------------------------
- #
+ # Undeploy the plugins from the referenced directories.
#
--------------------------------------------------------------------------
def undeploy(self):
+ """Undeploy the plugins from the referenced directories.
"""
- """
self.__dirMutex.acquire()
if not self.__isDeployed:
self.__dirMutex.release()
@@ -79,11 +80,15 @@
self.__dirMutex.release()
#
--------------------------------------------------------------------------
- #
+ # Add a directory in the directories list to deploy.
#
--------------------------------------------------------------------------
def addDirectory(self, directory, filters = []):
+ """Add a directory in the directories list to deploy.
+ @param directory: Directory path.
+ @param filters: Plugin extension list.
+ @return: The success of the directory add.
+ If the auto-deployment is started, the directory is directly deployed.
"""
- """
if not os.path.isdir(directory):
return False
self.__dirMutex.acquire()
@@ -112,11 +117,12 @@
return True
#
--------------------------------------------------------------------------
- #
+ # Remove a directory from the directories list to deploy.
#
--------------------------------------------------------------------------
def removeDirectory(self, directory):
+ """Remove a directory from the directories list to deploy.
+ @param directory: Directory path.
"""
- """
self.__dirMutex.acquire()
for directoryObserver in self.__directoryObservers:
if directoryObserver[0].getDirectory() == directory:
@@ -128,51 +134,71 @@
self.__dirMutex.release()
#
--------------------------------------------------------------------------
- #
+ # Set the directory deployed event callback.
#
--------------------------------------------------------------------------
def setOnDirectoryDeployedCallback(self, funct):
+ """Set the directory deployed event callback.
+ @param funct: Function pointer.
+ Function prototype:
+ def onDirectoryDeployed(observerName):
+ pass
"""
- """
self.__onDirectoryDeployedCallback = funct
#
--------------------------------------------------------------------------
- #
+ # Set the directory undeployed event callback.
#
--------------------------------------------------------------------------
def setOnDirectoryUndeployedCallback(self, funct):
+ """Set the directory undeployed event callback.
+ @param funct: Function pointer.
+ Function prototype:
+ def onDirectoryUndeployed(observerName):
+ pass
"""
- """
self.__onDirectoryUndeployedCallback = funct
#
--------------------------------------------------------------------------
- #
+ # Set the plugin deployed event callback.
#
--------------------------------------------------------------------------
def setOnPluginDeployedCallback(self, funct):
+ """Set the plugin deployed event callback.
+ @param funct: Function pointer.
+ Function prototype:
+ def onPluginDeployed(observerName, fileName, pluginPath, pluginName):
+ pass
"""
- """
self.__onPluginDeployedCallback = funct
#
--------------------------------------------------------------------------
- #
+ # Set the plugin deployment error event callback.
#
--------------------------------------------------------------------------
def setOnPluginDeploymentErrorCallback(self, funct):
+ """Set the plugin deployment error event callback.
+ @param funct: Function pointer.
+ Function prototype:
+ def onPluginDeploymentError(observerName, pluginName):
+ pass
"""
- """
self.__onPluginDeploymentErrorCallback = funct
#
--------------------------------------------------------------------------
- #
+ # Set the plugin undeployed event callback.
#
--------------------------------------------------------------------------
def setOnPluginUndeployedCallback(self, funct):
+ """Set the plugin undeployed event callback.
+ @param funct: Function pointer.
+ Function prototype:
+ def onPluginUndeployed(observerName, fileName, pluginPath, pluginName):
+ pass
"""
- """
self.__onPluginUndeployedCallback = funct
#
--------------------------------------------------------------------------
- #
+ # Event on directory oberver : added file.
#
--------------------------------------------------------------------------
def __onObserverAddedFile(self, observerName, fileName):
+ """Event on directory oberver : added file.
"""
- """
self.__eventMutex.acquire()
pluginName = fileName.split(os.sep)[-1].split(".")[0]
pluginPath = os.path.join(self.__baseWorkingDirectory, observerName,
@@ -193,11 +219,11 @@
return result
#
--------------------------------------------------------------------------
- #
+ # Event on directory oberver : removed file.
#
--------------------------------------------------------------------------
def __onObserverRemovedFile(self, observerName, fileName):
+ """Event on directory oberver : removed file.
"""
- """
self.__eventMutex.acquire()
pluginName = fileName.split(os.sep)[-1].split(".")[0]
pluginPath = os.path.join(self.__baseWorkingDirectory, observerName,
@@ -209,11 +235,13 @@
self.__eventMutex.release()
#
--------------------------------------------------------------------------
- #
+ # Uncompress a plugin.
#
--------------------------------------------------------------------------
def __uncompressPlugin(self, zippedFile, outputPath):
+ """Uncompress a plugin.
+ @param zippedFile: Zipped plugin file.
+ @param outputPath: Uncompressed output directory.
"""
- """
try:
zf = ZipFile(zippedFile, 'r')
except:
Modified:
software_suite_v2/tuxware/tuxdroidserver/trunk/util/filesystem/DirectoryContentObserver.py
===================================================================
---
software_suite_v2/tuxware/tuxdroidserver/trunk/util/filesystem/DirectoryContentObserver.py
2009-03-23 09:28:43 UTC (rev 4175)
+++
software_suite_v2/tuxware/tuxdroidserver/trunk/util/filesystem/DirectoryContentObserver.py
2009-03-23 10:18:22 UTC (rev 4176)
@@ -16,18 +16,20 @@
from md5 import md5
#
------------------------------------------------------------------------------
-#
+# Class to observe the files events from a directory. (file removed, file
added)
#
------------------------------------------------------------------------------
class DirectoryContentObserver(object):
+ """Class to observe the files events from a directory. (file removed,
+ file added)
"""
- """
#
--------------------------------------------------------------------------
# Constructor of the class.
#
--------------------------------------------------------------------------
def __init__(self, name):
+ """Constructor of the class.
+ @param name: Name of the instance of the class.
"""
- """
self.__name = name
self.__mutex = threading.Lock()
self.__isStarted = False
@@ -40,49 +42,51 @@
self.__onRemovedFileCallback = None
#
--------------------------------------------------------------------------
- #
+ # Destructor of the class.
#
--------------------------------------------------------------------------
def __del__(self):
+ """Destructor of the class.
"""
- """
self.stop()
#
--------------------------------------------------------------------------
- #
+ # Get the instance name.
#
--------------------------------------------------------------------------
def getName(self):
+ """Get the instance name.
+ @return: A string.
"""
- """
self.__mutex.acquire()
name = self.__name
self.__mutex.release()
return name
#
--------------------------------------------------------------------------
- #
+ # Start the observation of the selected directory.
#
--------------------------------------------------------------------------
def start(self):
+ """Start the observation of the selected directory.
+ @return: The start success as boolean.
"""
- """
if self.getDirectory() == None:
return False
if self.isStarted():
return False
self.__checkForUpdate()
- self.setStarted(True)
+ self.__setStarted(True)
self.__observerThread = threading.Thread(target = self.__observerLoop)
self.__observerThread.start()
return True
#
--------------------------------------------------------------------------
- #
+ # Stop the current directory observation.
#
--------------------------------------------------------------------------
def stop(self):
+ """Stop the current directory observation.
"""
- """
if not self.isStarted():
return
- self.setStarted(False)
+ self.__setStarted(False)
if self.__observerThread.isAlive():
if not self.__observerThread.join(self.__rate * 2):
self.__observerThread._Thread__stop()
@@ -93,112 +97,129 @@
self.__onRemovedFileCallback(self.getName(), fileName)
#
--------------------------------------------------------------------------
- #
+ # Set the directory to observe.
#
--------------------------------------------------------------------------
def setDirectory(self, directory):
+ """Set the directory to observe.
+ @param directory: Directory path.
"""
- """
if os.path.isdir(directory):
self.__mutex.acquire()
self.__directory = directory
self.__mutex.release()
#
--------------------------------------------------------------------------
- #
+ # Get the current directory to observe.
#
--------------------------------------------------------------------------
def getDirectory(self):
+ """Get the current directory to observe.
+ @return: A string.
"""
- """
self.__mutex.acquire()
directory = self.__directory
self.__mutex.release()
return directory
#
--------------------------------------------------------------------------
- #
+ # Set the file filters.
#
--------------------------------------------------------------------------
def setFilters(self, filters = ['.tgf',]):
+ """Set the file filters.
+ Only the files of the referenced extensions will be observed.
+ @param filters: filters as list of strings.
"""
- """
self.__mutex.acquire()
self.__filters = filters
self.__mutex.release()
#
--------------------------------------------------------------------------
- #
+ # Get the file filters.
#
--------------------------------------------------------------------------
def getFilters(self):
+ """ Get the file filters.
+ @return: A list of strings.
"""
- """
self.__mutex.acquire()
filters = self.__filters
self.__mutex.release()
return filters
#
--------------------------------------------------------------------------
- #
+ # Set the speed rate of the observation.
#
--------------------------------------------------------------------------
def setRate(self, rate):
+ """Set the speed rate of the observation.
+ @param rate: Speed rate in seconds as float.
"""
- """
self.__mutex.acquire()
self.__rate = rate
self.__mutex.release()
#
--------------------------------------------------------------------------
- #
+ # Get the speed rate of the observation.
#
--------------------------------------------------------------------------
def getRate(self):
+ """Get the speed rate of the observation.
+ @return: A float.
"""
- """
self.__mutex.acquire()
rate = self.__rate
self.__mutex.release()
return rate
#
--------------------------------------------------------------------------
- #
+ # Get if the observation is started or not.
#
--------------------------------------------------------------------------
def isStarted(self):
+ """Get if the observation is started or not.
+ @return: A boolean.
"""
- """
self.__mutex.acquire()
isStarted = self.__isStarted
self.__mutex.release()
return isStarted
#
--------------------------------------------------------------------------
- #
+ # Set if the started flag value.
#
--------------------------------------------------------------------------
- def setStarted(self, isStarted):
+ def __setStarted(self, isStarted):
+ """Set if the started flag value.
+ @param isStarted: Flag value as boolean.
"""
- """
self.__mutex.acquire()
self.__isStarted = isStarted
self.__mutex.release()
#
--------------------------------------------------------------------------
- #
+ # Set the added file event callback.
#
--------------------------------------------------------------------------
def setOnAddedFileCallback(self, funct):
+ """Set the added file event callback.
+ @param funct: Function pointer.
+ Function prototype:
+ def onAddedFile(observerName, fileName):
+ pass
"""
- """
self.__onAddedFileCallback = funct
#
--------------------------------------------------------------------------
- #
+ # Set the removed file event callback.
#
--------------------------------------------------------------------------
def setOnRemovedFileCallback(self, funct):
+ """Set the removed file event callback.
+ @param funct: Function pointer.
+ Function prototype:
+ def onRemovedFile(observerName, fileName):
+ pass
"""
- """
self.__onRemovedFileCallback = funct
#
--------------------------------------------------------------------------
- #
+ # Observe the directory.
#
--------------------------------------------------------------------------
def __checkForUpdate(self):
+ """Observe the directory.
"""
- """
directory = self.getDirectory()
if directory == None:
return
@@ -243,11 +264,11 @@
self.__filesInfo = currentContent
#
--------------------------------------------------------------------------
- #
+ # Observation loop.
#
--------------------------------------------------------------------------
def __observerLoop(self):
+ """Observation loop.
"""
- """
while self.isStarted():
self.__checkForUpdate()
time.sleep(self.__rate)
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn