Author: remi
Date: 2009-07-25 12:09:25 +0200 (Sat, 25 Jul 2009)
New Revision: 5168
Added:
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetOnline.py
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetsOnlineContainer.py
Modified:
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetsContainer.py
Log:
* Added classes to retrieve online gadgets informations.
Added:
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetOnline.py
===================================================================
---
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetOnline.py
(rev 0)
+++
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetOnline.py
2009-07-25 10:09:25 UTC (rev 5168)
@@ -0,0 +1,132 @@
+# Copyright (C) 2009 C2ME Sa
+# Remi Jocaille <[email protected]>
+# Distributed under the terms of the GNU General Public License
+# http://www.gnu.org/copyleft/gpl.html
+
+ONLINE_GADGETS_BASE_URL = "http://ftp.kysoh.com/ssv3/content/gadgets/"
+
+#
------------------------------------------------------------------------------
+# Gadget online class.
+#
------------------------------------------------------------------------------
+class GadgetOnline(object):
+ """Gadget online class.
+ """
+
+ #
--------------------------------------------------------------------------
+ # Constructor of the class.
+ #
--------------------------------------------------------------------------
+ def __init__(self, gadgetsOnlineContainer, dictionary):
+ """Constructor of the class.
+ @param gadgetsOnlineContainer: Gadgets online container object.
+ @param dictionary: Data dictionary.
+ """
+ self.__dictionary = dictionary
+
+ #
--------------------------------------------------------------------------
+ # Get the author.
+ #
--------------------------------------------------------------------------
+ def getAuthor(self):
+ """Get the author.
+ @return: A string.
+ """
+ return self.__dictionary['author']
+
+ #
--------------------------------------------------------------------------
+ # Get the category.
+ #
--------------------------------------------------------------------------
+ def getCategory(self):
+ """Get the category.
+ @return: A string.
+ """
+ return self.__dictionary['category']
+
+ #
--------------------------------------------------------------------------
+ # Get the default language.
+ #
--------------------------------------------------------------------------
+ def getDefaultLanguage(self):
+ """Get the default language.
+ @return: A string.
+ """
+ return self.__dictionary['defaultLanguage']
+
+ #
--------------------------------------------------------------------------
+ # Get the symbolic name.
+ #
--------------------------------------------------------------------------
+ def getSymbolicName(self):
+ """Get the symbolic name.
+ @return: A string.
+ """
+ return self.__dictionary['symbolicName']
+
+ #
--------------------------------------------------------------------------
+ # Get the version.
+ #
--------------------------------------------------------------------------
+ def getVersion(self):
+ """Get the version.
+ @return: A string.
+ """
+ return self.__dictionary['version']
+
+ #
--------------------------------------------------------------------------
+ # Get the description.
+ #
--------------------------------------------------------------------------
+ def getDescription(self, language):
+ """Get the description.
+ @param language: Language.
+ @return: A string.
+ """
+ if self.__dictionary['description'].has_key(language):
+ return self.__dictionary['description'][language]
+ else:
+ return self.__dictionary['description']['en']
+
+ #
--------------------------------------------------------------------------
+ # Get the name.
+ #
--------------------------------------------------------------------------
+ def getName(self, language):
+ """Get the name.
+ @param language: Language.
+ @return: A string.
+ """
+ if self.__dictionary['name'].has_key(language):
+ return self.__dictionary['name'][language]
+ else:
+ return self.__dictionary['name']['en']
+
+ #
--------------------------------------------------------------------------
+ # Get the help file url.
+ #
--------------------------------------------------------------------------
+ def getHelpFile(self, language):
+ """Get the help file url.
+ @param language: Language.
+ @return: A string.
+ """
+ if self.__dictionary['helpFile'].has_key(language):
+ fileName = self.__dictionary['helpFile'][language]
+ else:
+ fileName = self.__dictionary['helpFile']['en']
+ result = "%sdeflated/%s/%s" % (ONLINE_GADGETS_BASE_URL,
+ self.getSymbolicName(), fileName)
+ return result
+
+ #
--------------------------------------------------------------------------
+ # Get the icon url.
+ #
--------------------------------------------------------------------------
+ def getIconFile(self):
+ """Get the icon url.
+ @return: A string.
+ """
+ result = "%sdeflated/%s/gadget.png" % (ONLINE_GADGETS_BASE_URL,
+ self.getSymbolicName())
+ return result
+
+ #
--------------------------------------------------------------------------
+ # Get the scg file.
+ #
--------------------------------------------------------------------------
+ def getScgFile(self):
+ """Get the scg file.
+ @return: A string.
+ """
+ result = "%sscg/%s.scg" % (ONLINE_GADGETS_BASE_URL,
+ self.getSymbolicName())
+ return result
Modified:
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetsContainer.py
===================================================================
---
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetsContainer.py
2009-07-24 12:33:51 UTC (rev 5167)
+++
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetsContainer.py
2009-07-25 10:09:25 UTC (rev 5168)
@@ -9,9 +9,11 @@
from util.filesystem.AutoDeployer import AutoDeployer
from util.xml.XmlSerializer import XmlSerializer
from util.misc import DirectoriesAndFilesTools
+from util.misc import URLTools
from util.applicationserver.plugin.Plugin import SUPPORTED_LANGUAGES_LIST
from Gadget import Gadget
from GadgetGenerator import GadgetGenerator
+from GadgetsOnlineContainer import GadgetsOnlineContainer
#
------------------------------------------------------------------------------
# Gadgets container class.
@@ -38,6 +40,7 @@
self.__onGadgetDeployedCallback = None
self.__onGadgetDeploymentErrorCallback = None
self.__onGadgetUndeployedCallback = None
+ self.__gadgetsOnlineContainer = GadgetsOnlineContainer(self)
#
--------------------------------------------------------------------------
# Configure the locale values of the gadgets container.
@@ -88,6 +91,15 @@
return self.__pluginsContainer.getPitch()
#
--------------------------------------------------------------------------
+ # Get the online gadgets container.
+ #
--------------------------------------------------------------------------
+ def getGadgetsOnlineContainer(self):
+ """Get the online gadgets container.
+ @return: A GadgetsOnlineContainer object.
+ """
+ return self.__gadgetsOnlineContainer
+
+ #
--------------------------------------------------------------------------
# Generate a single name.
#
--------------------------------------------------------------------------
def generateSingleName(self, gadgetName, language):
Added:
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetsOnlineContainer.py
===================================================================
---
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetsOnlineContainer.py
(rev 0)
+++
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetsOnlineContainer.py
2009-07-25 10:09:25 UTC (rev 5168)
@@ -0,0 +1,90 @@
+# Copyright (C) 2009 C2ME Sa
+# Remi Jocaille <[email protected]>
+# Distributed under the terms of the GNU General Public License
+# http://www.gnu.org/copyleft/gpl.html
+
+import os
+import threading
+
+from util.xml.XmlSerializer import XmlSerializer
+from util.misc import DirectoriesAndFilesTools
+from util.misc import URLTools
+from GadgetOnline import GadgetOnline
+from GadgetOnline import ONLINE_GADGETS_BASE_URL
+
+#
------------------------------------------------------------------------------
+# Gadgets online container class.
+#
------------------------------------------------------------------------------
+class GadgetsOnlineContainer(object):
+ """Gadgets online container class.
+ """
+
+ #
--------------------------------------------------------------------------
+ # Constructor of the class.
+ #
--------------------------------------------------------------------------
+ def __init__(self, gadgetsContainer):
+ """Constructor of the class.
+ @param gadgetsContainer: Gadgets container object.
+ """
+ self.__gadgetsOnline = []
+ self.__gadgetsCount = 0
+ self.__mutex = threading.Lock()
+
+ #
--------------------------------------------------------------------------
+ # Update gadget structures with dictionary.
+ #
--------------------------------------------------------------------------
+ def update(self):
+ """Update gadget structures with dictionary.
+ """
+ self.__mutex.acquire()
+ self.__gadgetsOnline = []
+ self.__gadgetsCount = 0
+ gadgetsXmlFile = os.path.join(DirectoriesAndFilesTools.GetOSTMPDir(),
+ "gadgets.xml")
+ # Download the xml file from the ftp
+ gadgetsXmlUrl = ONLINE_GADGETS_BASE_URL + "gadgets.xml"
+ if not URLTools.URLDownloadToFile(gadgetsXmlUrl, gadgetsXmlFile):
+ self.__mutex.release()
+ return
+ # Parse the xml file
+ gadgetsXmlFileContent = XmlSerializer.deserializeEx(gadgetsXmlFile)
+ DirectoriesAndFilesTools.RMFile(gadgetsXmlFile)
+ if gadgetsXmlFileContent == None:
+ self.__mutex.release()
+ return
+ try:
+ count = int(gadgetsXmlFileContent['count'])
+ for i in range(count):
+ onlineGadget = GadgetOnline(self,
+ gadgetsXmlFileContent['gadget_%.4d' % i])
+ self.__gadgetsOnline.append(onlineGadget)
+ self.__gadgetsCount = count
+ except:
+ pass
+ self.__mutex.release()
+
+ #
--------------------------------------------------------------------------
+ # Get the number of online gadgets.
+ #
--------------------------------------------------------------------------
+ def getCount(self):
+ """Get the number of online gadgets.
+ @return: An integer.
+ """
+ self.__mutex.acquire()
+ result = self.__gadgetsCount
+ self.__mutex.release()
+ return result
+
+ #
--------------------------------------------------------------------------
+ # Get the online gadgets.
+ #
--------------------------------------------------------------------------
+ def getOnlineGadgets(self):
+ """Get the online gadgets.
+ @return: A list of OnlineGadget.
+ """
+ self.__mutex.acquire()
+ result = []
+ for onlineGadget in self.__gadgetsOnline:
+ result.append(onlineGadget)
+ self.__mutex.release()
+ return result
------------------------------------------------------------------------------
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn