Author: remi
Date: 2009-07-08 11:15:58 +0200 (Wed, 08 Jul 2009)
New Revision: 5080

Modified:
   
software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/02_resourceGagdetsServer.py
   
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetsContainer.py
   
software_suite_v3/smart-core/smart-server/trunk/util/misc/DirectoriesAndFilesTools.py
Log:
* Added a function copy a file.
* Added a method to export gadgets data to a directory.
  (The resulting data structure will be used for the online gadgets download)
* Added a service to the method. example : 
(http://127.0.0.1:270/gadgets_server/export_gadgets?dest_path=c:\gadgets)

Modified: 
software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/02_resourceGagdetsServer.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/02_resourceGagdetsServer.py
    2009-07-08 07:26:04 UTC (rev 5079)
+++ 
software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/02_resourceGagdetsServer.py
    2009-07-08 09:15:58 UTC (rev 5080)
@@ -464,3 +464,29 @@
 
 # Register the service into the resource
 resourceGadgetsServer.addService(TDSServiceGadgetsServerRemoveGadget)
+
+# 
------------------------------------------------------------------------------
+# Declaration of the service "export_gadgets".
+# 
------------------------------------------------------------------------------
+class TDSServiceGadgetsServerExportGadgets(TDSService):
+
+    def configure(self):
+        self.parametersDict = {
+            'dest_path' : 'string',
+        }
+        self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+        self.exclusiveExecution = True
+        self.name = "export_gadgets"
+        self.comment = "Export gadgets data to an external directory."
+
+    def execute(self, id, parameters):
+        headersStruct = self.getDefaultHeadersStruct()
+        contentStruct = self.getDefaultContentStruct()
+        contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+        destPath = parameters['dest_path']
+        resourceGadgetsServer.getGadgetsContainer().exportGadgets(destPath)
+        return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceGadgetsServer.addService(TDSServiceGadgetsServerExportGadgets)
+

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-08 07:26:04 UTC (rev 5079)
+++ 
software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetsContainer.py
   2009-07-08 09:15:58 UTC (rev 5080)
@@ -8,7 +8,10 @@
 
 from util.filesystem.AutoDeployer import AutoDeployer
 from util.xml.XmlSerializer import XmlSerializer
+from util.misc import DirectoriesAndFilesTools
+from util.applicationserver.plugin.Plugin import SUPPORTED_LANGUAGES_LIST
 from Gadget import Gadget
+from GadgetGenerator import GadgetGenerator
 
 # 
------------------------------------------------------------------------------
 # Gadgets container class.
@@ -110,6 +113,64 @@
             gadgetName = "%s (%d)" % (baseGadgetName, i)
         return gadgetName
 
+    # 
--------------------------------------------------------------------------
+    # Export gadgets data to an external directory.
+    # 
--------------------------------------------------------------------------
+    def exportGadgets(self, destDirectory = "c:/gadgetsV3"):
+        """Export gadgets data to an external directory.
+        @param destDirectory: Directory how to export the data.
+        """
+        baseDir = destDirectory
+        deflatedDir = os.path.join(baseDir, "deflated")
+        scgDir = os.path.join(baseDir, "scg")
+        gadgetXmlFile = os.path.join(baseDir, "gadgets.xml")
+        # Create directories arch
+        DirectoriesAndFilesTools.MKDirsF(baseDir)
+        if not os.path.isdir(baseDir):
+            return
+        DirectoriesAndFilesTools.MKDirs(deflatedDir)
+        DirectoriesAndFilesTools.MKDirs(scgDir)
+        # Loop on gadgets data
+        gadgetsXmlDict = {
+            'gadgets' : {
+                'count' : self.getCount(),
+            },
+        }
+        for i, gadget in enumerate(self.getGadgets()):
+            # Export scg file
+            src = gadget.getScgFile()
+            scgName = os.path.split(src)[-1]
+            dest = os.path.join(scgDir, scgName)
+            DirectoriesAndFilesTools.CPFile(src, dest)
+            # Export deflated directory
+            src = gadget.getWorkingPath()
+            symbolicName = os.path.split(gadget.getWorkingPath())[-1]
+            dest = os.path.join(deflatedDir, symbolicName)
+            DirectoriesAndFilesTools.CPDir(src, dest)
+            # Get some informations about the gadget
+            gadgetData = {}
+            gadgetData['symbolicName'] = symbolicName
+            gadgetData['version'] = gadget.getDescription().getVersion()
+            gadgetData['defaultLanguage'] = 
gadget.getDescription().getDefaultLanguage()
+            gadgetData['category'] = gadget.getDescription().getCategory()
+            gadgetData['author'] = gadget.getDescription().getAuthor()
+            gadgetData['name'] = {}
+            gadgetData['description'] = {}
+            gadgetData['helpFile'] = {}
+            for lang in SUPPORTED_LANGUAGES_LIST:
+                name = gadget.getDescription().getTranslatedName(lang)
+                gadgetData['name'][lang] = name
+                description = gadget.getDescription().getDescription(lang)
+                gadgetData['description'][lang] = description
+                helpFile = 
os.path.split(gadget.getDescription().getHelpFile(lang))[-1]
+                gadgetData['helpFile'][lang] = helpFile
+            gadgetsXmlDict['gadgets']['gadget_%.4d' % i] = gadgetData
+        # Export gadgets.xml file
+        gadgetsXmlFileContent = GadgetGenerator.gadgetDictToXml(gadgetsXmlDict)
+        f = open(gadgetXmlFile, "w")
+        f.write(gadgetsXmlFileContent)
+        f.close()
+
     # 
==========================================================================
     # AUTO-DEPLOYER
     # 
==========================================================================

Modified: 
software_suite_v3/smart-core/smart-server/trunk/util/misc/DirectoriesAndFilesTools.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/trunk/util/misc/DirectoriesAndFilesTools.py
       2009-07-08 07:26:04 UTC (rev 5079)
+++ 
software_suite_v3/smart-core/smart-server/trunk/util/misc/DirectoriesAndFilesTools.py
       2009-07-08 09:15:58 UTC (rev 5080)
@@ -138,6 +138,23 @@
     shutil.copytree(src, dest)
 
 # 
------------------------------------------------------------------------------
+# Copy a file.
+# 
------------------------------------------------------------------------------
+def CPFile(src, dest):
+    """Copy a file.
+    @param src: Source file path.
+    @param dest: Destination file path.
+    @return: True or False.
+    """
+    if not os.path.isfile(src):
+        return False
+    try:
+        shutil.copy(src, dest)
+    except:
+        return False
+    return True
+
+# 
------------------------------------------------------------------------------
 # Retrieve the OS temporary directory.
 # 
------------------------------------------------------------------------------
 def GetOSTMPDir():


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to