[tuxdroid-svn] r4689 - in software_suite_v3/smart-core/smart-server/trunk/resources: 03_content_se
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-05-27 14:08:36
|
Author: remi
Date: 2009-05-27 16:08:31 +0200 (Wed, 27 May 2009)
New Revision: 4689
Added:
software_suite_v3/smart-core/smart-server/trunk/resources/04_user_configurations/00_resourceUsers.py
Modified:
software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/01_resourcePluginsServer.py
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/03_resourceUgcServer.py
Log:
* added base to support multi-users
* updated plugins, gadgets and ugc resources to be configured for the current user
Modified: software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/01_resourcePluginsServer.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/01_resourcePluginsServer.py 2009-05-27 14:06:34 UTC (rev 4688)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/01_resourcePluginsServer.py 2009-05-27 14:08:31 UTC (rev 4689)
@@ -77,7 +77,7 @@
def stop(self):
self.logger.logInfo("Undeploy the plugins container")
- self.__PluginsContainer.undeploy()
+ self.__pluginsContainer.undeploy()
# --------------------------------------------------------------------------
# Plugins container events
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-05-27 14:06:34 UTC (rev 4688)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/02_resourceGagdetsServer.py 2009-05-27 14:08:31 UTC (rev 4689)
@@ -46,7 +46,7 @@
self.logger.logInfo("Licence : GPL")
self.logger.logInfo("-----------------------------------------------")
- def start(self):
+ def startServer(self):
# Create a gadgets container
self.__gadgetsContainer = GadgetsContainer(resourcePluginsServer.getPluginsContainer())
self.__gadgetsContainer.setOnDirectoryDeployedCallback(self.__onDirectoryDeployed)
@@ -64,7 +64,7 @@
def stop(self):
self.logger.logInfo("Undeploy the gadgets container")
- self.__GadgetsContainer.undeploy()
+ self.__gadgetsContainer.undeploy()
# --------------------------------------------------------------------------
# Gadgets container events
Modified: software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/03_resourceUgcServer.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/03_resourceUgcServer.py 2009-05-27 14:06:34 UTC (rev 4688)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/03_content_servers/03_resourceUgcServer.py 2009-05-27 14:08:31 UTC (rev 4689)
@@ -47,13 +47,12 @@
self.logger.logInfo("Licence : GPL")
self.logger.logInfo("-----------------------------------------------")
- def start(self):
+ def startServer(self, ugcPath):
# Create a UGC container and start the UGC server
self.__ugcContainer = UgcContainer(resourceGadgetsServer.getGadgetsContainer())
self.__ugcContainer.setOnUgcDeployedCallback(self.__onUgcDeployed)
self.__ugcContainer.setOnUgcDeploymentErrorCallback(self.__onUgcDeploymentError)
self.__ugcContainer.setOnUgcUndeployedCallback(self.__onUgcUndeployed)
- ugcPath = os.path.join(TDS_APPLICATION_PATH, "content", "ugcs")
self.logger.logInfo("Set directory in the UGC container [%s]." % ugcPath)
self.__ugcContainer.setDirectory(ugcPath)
self.logger.logInfo("Deploy the UGC container.")
Added: software_suite_v3/smart-core/smart-server/trunk/resources/04_user_configurations/00_resourceUsers.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/resources/04_user_configurations/00_resourceUsers.py (rev 0)
+++ software_suite_v3/smart-core/smart-server/trunk/resources/04_user_configurations/00_resourceUsers.py 2009-05-27 14:08:31 UTC (rev 4689)
@@ -0,0 +1,176 @@
+# ==============================================================================
+# Users resource.
+# ==============================================================================
+
+from util.misc.tuxPaths import TUXDROID_LANGUAGE
+from util.misc.tuxPaths import TUXDROID_DEFAULT_LOCUTOR
+
+# ------------------------------------------------------------------------------
+# Declaration of the resource "users".
+# ------------------------------------------------------------------------------
+class TDSResourceUsers(TDSResource):
+
+ # --------------------------------------------------------------------------
+ # Inherited methods from TDSResource
+ # --------------------------------------------------------------------------
+
+ def configure(self):
+ self.name = "users"
+ self.comment = "Resource to manage the users configurations."
+ self.fileName = RESOURCE_FILENAME
+ # Ensure that the users_conf directory exists
+ DirectoriesAndFilesTools.MKDirs(TDS_USERS_CONF_PATH)
+
+ def start(self):
+ # Read the last logged user name
+ self.__lastUser = self.getLastLoggedUserName()
+ # Create user directories if not exists
+ self.createUserIfNotExists()
+ # Load the user configuration
+ self.__userConfiguration = self.loadUserConfiguration()
+
+ # --------------------------------------------------------------------------
+ # Shared methods
+ # --------------------------------------------------------------------------
+
+ def getLastLoggedUserName(self):
+ """Get the name of the last logged user.
+ @return: A string.
+ """
+ lastUserConf = os.path.join(TDS_USERS_CONF_PATH, "last_user.name")
+ if not os.path.isfile(lastUserConf):
+ f = open(lastUserConf, "w")
+ f.write("default")
+ f.close()
+ f = open(lastUserConf, "r")
+ result = f.read()
+ f.close()
+ return result
+
+ def createUserIfNotExists(self):
+ """Create the user configuration of the last selected user if not
+ exists.
+ """
+ userName = self.__lastUser
+ DirectoriesAndFilesTools.MKDirs(os.path.join(TDS_USERS_CONF_PATH,
+ userName))
+ DirectoriesAndFilesTools.MKDirs(os.path.join(TDS_USERS_CONF_PATH,
+ userName, "gadgets"))
+ DirectoriesAndFilesTools.MKDirs(os.path.join(TDS_USERS_CONF_PATH,
+ userName, "attitunes"))
+ DirectoriesAndFilesTools.MKDirs(os.path.join(TDS_USERS_CONF_PATH,
+ userName, "ugcs"))
+
+ def loadUserConfiguration(self):
+ """Load an user configuration.
+ @return: The user configuration as dictionary.
+ """
+ userName = self.__lastUser
+ userConfFile = os.path.join(TDS_USERS_CONF_PATH, userName, "user.conf")
+ if not os.path.isfile(userConfFile):
+ # Create default configuration
+ splitedLC = TUXDROID_LANGUAGE.split("_")
+ language = splitedLC[0]
+ if len(splitedLC) > 1:
+ country = splitedLC[1]
+ else:
+ country = language.upper()
+ locutor = TUXDROID_DEFAULT_LOCUTOR
+ pitch = 130
+ defaultConfDict = {
+ 'name' : userName,
+ 'login' : None,
+ 'password' : None,
+ 'language1' : language,
+ 'language2' : language,
+ 'country' : country,
+ 'locutor1' : locutor,
+ 'locutor2' : locutor,
+ 'pitch' : pitch,
+ }
+ f = open(userConfFile, "w")
+ f.write(str(defaultConfDict))
+ f.close()
+ # Load user configuration
+ f = open(userConfFile, "r")
+ result = eval(f.read())
+ f.close()
+ # Reference the user attitunes directory
+ resourceAttituneManager.getAttitunesContainer().addDirectory(
+ os.path.join(TDS_USERS_CONF_PATH, userName, "attitunes"))
+ # Set locales in the plugins server
+ resourcePluginsServer.getPluginsContainer().setLocales(
+ result['language1'], result['country'],
+ result['locutor1'], result['pitch'])
+ # Start gadgets server
+ resourceGadgetsServer.startServer()
+ # Reference user gadgets directory
+ resourceGadgetsServer.getGadgetsContainer().addDirectory(
+ os.path.join(TDS_USERS_CONF_PATH, userName, "gadgets"))
+ # Start ugc server
+ resourceUgcServer.startServer(os.path.join(TDS_USERS_CONF_PATH,
+ userName, "ugcs"))
+ return result
+
+ def getCurrentUserConfiguration(self):
+ """Get the current user configuration.
+ @return: The current user configuration as string.
+ """
+ return self.__userConfiguration
+
+ def updateCurrentUserConfiguration(self, userConfiguration):
+ """Update the current user configuration.
+ @param userConfiguration: New configuration as dictionary.
+ - This function will restart the server.
+ """
+ # Update configuration file
+ userConfFile = os.path.join(TDS_USERS_CONF_PATH, self.__lastUser,
+ "user.conf")
+ f = open(userConfFile, "w")
+ f.write(str(userConfiguration))
+ f.close()
+ # Restart the server
+ resourceServer.restartServer()
+
+ def switchUser(self, userName):
+ """Switch to an other user.
+ @param userName: Name of the requested user.
+ - This function will restart the server.
+ """
+ # Store the requested user name
+ lastUserConf = os.path.join(TDS_USERS_CONF_PATH, "last_user.name")
+ f = open(lastUserConf, "w")
+ f.write(userName)
+ f.close()
+ # Restart the server
+ resourceServer.restartServer()
+
+# Create an instance of the resource
+resourceUsers = TDSResourceUsers("resourceUsers")
+# Register the resource into the resources manager
+resourcesManager.addResource(resourceUsers)
+
+# ------------------------------------------------------------------------------
+# Declaration of the service "switch_user".
+# ------------------------------------------------------------------------------
+class TDSServiceUsersSwitchUser(TDSService):
+
+ def configure(self):
+ self.parametersDict = {
+ 'name' : 'string',
+ }
+ self.minimalUserLevel = TDS_CLIENT_LEVEL_ANONYMOUS
+ self.exclusiveExecution = False
+ self.name = "switch_user"
+ self.comment = "Switch to another user."
+
+ def execute(self, id, parameters):
+ headersStruct = self.getDefaultHeadersStruct()
+ contentStruct = self.getDefaultContentStruct()
+ contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
+ name = parameters['name']
+ resourceUsers.switchUser(name)
+ return headersStruct, contentStruct
+
+# Register the service into the resource
+resourceUsers.addService(TDSServiceUsersSwitchUser)
Property changes on: software_suite_v3/smart-core/smart-server/trunk/resources/04_user_configurations/00_resourceUsers.py
___________________________________________________________________
Name: svn:keywords
+ Id
|