Author: ks156
Date: 2009-09-14 12:07:31 +0200 (Mon, 14 Sep 2009)
New Revision: 5365

Added:
   
software_suite_v3/smart-core/smart-server/branches/user_mode/util/misc/systemPaths.py
Modified:
   
software_suite_v3/smart-core/smart-server/branches/user_mode/TDSConfiguration.py
   
software_suite_v3/smart-core/smart-server/branches/user_mode/resources/05_user_configurations/00_resourceUsers.py
   software_suite_v3/smart-core/smart-server/branches/user_mode/tuxhttpserver.py
   
software_suite_v3/smart-core/smart-server/branches/user_mode/util/daemonizer/Daemonizer.py
   
software_suite_v3/smart-core/smart-server/branches/user_mode/util/logger/SimpleLogger.py
Log:
* Added a set of function to determines if the server has been started as
  normal user or not.
  This version can be started as normal user, and accessed with the port
  "54321".  
  All the configurations, logs, and so on are located on ~/.tuxdroid.


Modified: 
software_suite_v3/smart-core/smart-server/branches/user_mode/TDSConfiguration.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/branches/user_mode/TDSConfiguration.py
    2009-09-14 09:53:42 UTC (rev 5364)
+++ 
software_suite_v3/smart-core/smart-server/branches/user_mode/TDSConfiguration.py
    2009-09-14 10:07:31 UTC (rev 5365)
@@ -16,6 +16,7 @@
 
 from util.logger import *
 from util.misc.tuxPaths import *
+from util.misc.systemPaths import systemPaths
 
 # 
==============================================================================
 # Class to retrieve the py file path.
@@ -37,8 +38,9 @@
     TDS_CONF_HOST_ADDRESS = '127.0.0.1'
 else:
     TDS_CONF_HOST_ADDRESS = ''
+
 # HTTP server Port
-TDS_HTTP_PORT = 270
+TDS_HTTP_PORT = systemPaths.getServerPort()
 # Use 50msec delay in request (CPU optimisation)
 TDS_50MSEC_OPTIMISATION = False
 # Use asynchronous requests treatment
@@ -51,7 +53,7 @@
 # TCP/IP server configuration
 # 
------------------------------------------------------------------------------
 # Raw data server port
-TDS_RAW_DATA_PORT = 271
+TDS_RAW_DATA_PORT = systemPaths.getServerPort() + 1
 
 # 
------------------------------------------------------------------------------
 # Loggers configuration
@@ -86,19 +88,22 @@
 if os.name == 'nt':
     TDS_RESOURCES_CONF_PATH = os.path.join(ALLUSERSBASEDIR, "configurations", 
"resources")
 else:
-    TDS_RESOURCES_CONF_PATH = os.path.join("/etc/tuxdroid", "resources_conf")
+    TDS_RESOURCES_CONF_PATH = systemPaths.getResourcesConfPath()
 # Path of the user configurations
 if os.name == 'nt':
     TDS_USERS_CONF_PATH = os.path.join(ALLUSERSBASEDIR, "configurations", 
"users_conf")
 else:
-    TDS_USERS_CONF_PATH = os.path.join("/etc/tuxdroid", "users_conf")
+    TDS_USERS_CONF_PATH = systemPaths.getUserConfPath()
 # Path of the default content of the server
 if os.name == 'nt':
     TDS_DEFAULT_CONTENT_PATH = os.path.join(ALLUSERSBASEDIR, "resources")
 else:
     TDS_DEFAULT_CONTENT_PATH = os.path.join(TUXDROID_BASE_PATH, "resources")
 # Path of the server updates
-TDS_UPDATES_PATH = os.path.join(TDS_DEFAULT_CONTENT_PATH, "updates")
+if os.name == 'nt':
+    TDS_UPDATES_PATH = os.path.join(TDS_DEFAULT_CONTENT_PATH, "updates")
+else:
+    TDS_UPDATES_PATH = systemPaths.getUpdateContentPath()
 
 # 
------------------------------------------------------------------------------
 # Resources configuration

Modified: 
software_suite_v3/smart-core/smart-server/branches/user_mode/resources/05_user_configurations/00_resourceUsers.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/branches/user_mode/resources/05_user_configurations/00_resourceUsers.py
   2009-09-14 09:53:42 UTC (rev 5364)
+++ 
software_suite_v3/smart-core/smart-server/branches/user_mode/resources/05_user_configurations/00_resourceUsers.py
   2009-09-14 10:07:31 UTC (rev 5365)
@@ -70,6 +70,14 @@
         """
         userName = self.__lastUser
         userConfFile = os.path.join(TDS_USERS_CONF_PATH, userName, "user.conf")
+
+        # If the server has been started as normal user on Linux and
+        # if the user configuration file doesn't exists, copy the master 
+        # configuration located in /etc/tuxdroid/users_conf/default/user.conf
+        if not os.path.isfile(userConfFile) and os.name != 'nt':
+            if systemPaths.isUser():
+                os.system("cp /etc/tuxdroid/users_conf/default/user.conf 
%s"%userConfFile)
+
         if not os.path.isfile(userConfFile):
             # Create default configuration
             splitedLC = TUXDROID_LANGUAGE.split("_")

Modified: 
software_suite_v3/smart-core/smart-server/branches/user_mode/tuxhttpserver.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/branches/user_mode/tuxhttpserver.py   
    2009-09-14 09:53:42 UTC (rev 5364)
+++ 
software_suite_v3/smart-core/smart-server/branches/user_mode/tuxhttpserver.py   
    2009-09-14 10:07:31 UTC (rev 5365)
@@ -86,7 +86,8 @@
         else: # Linux
             if __daemon:
                 from util.daemonizer import Daemonizer
-                tuxDroidDaemon = Daemonizer('tuxhttpserver', 
'/var/log/tuxdroid',
+                from util.misc.systemPaths import systemPaths
+                tuxDroidDaemon = Daemonizer('tuxhttpserver', 
systemPaths.getLogPath(),
                     runServer, True)
                 tuxDroidDaemon.start()
             else:

Modified: 
software_suite_v3/smart-core/smart-server/branches/user_mode/util/daemonizer/Daemonizer.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/branches/user_mode/util/daemonizer/Daemonizer.py
  2009-09-14 09:53:42 UTC (rev 5364)
+++ 
software_suite_v3/smart-core/smart-server/branches/user_mode/util/daemonizer/Daemonizer.py
  2009-09-14 10:07:31 UTC (rev 5365)
@@ -14,6 +14,7 @@
 import os
 import sys
 import errno
+from util.misc.systemPaths import systemPaths
 
 # 
==============================================================================
 # Public class
@@ -37,6 +38,11 @@
         @param name: name of the daemon.
         @param path: path of the pid file.
         """
+        # Search where the PID file must be placed
+        path = systemPaths.getPidPath()
+        if not os.path.isdir(path):
+            os.makedirs(path, mode=0755)
+
         self.__PIDFILE = "%s/%s.pid" % (path, name)
 
     # 
--------------------------------------------------------------------------

Modified: 
software_suite_v3/smart-core/smart-server/branches/user_mode/util/logger/SimpleLogger.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/branches/user_mode/util/logger/SimpleLogger.py
    2009-09-14 09:53:42 UTC (rev 5364)
+++ 
software_suite_v3/smart-core/smart-server/branches/user_mode/util/logger/SimpleLogger.py
    2009-09-14 10:07:31 UTC (rev 5365)
@@ -16,6 +16,8 @@
 import threading
 import time
 
+from util.misc.systemPaths import systemPaths
+
 # Levels
 LOG_LEVEL_DEBUG             = 0
 LOG_LEVEL_INFO              = 1
@@ -59,9 +61,10 @@
                 if not os.path.isdir(self.__logPath):
                     os.makedirs(self.__logPath)
             else:
-                if not os.path.isdir("/var/log/tuxdroid"):
-                    os.makedirs("/var/log/tuxdroid", mode=0755)
-                self.__logPath = "/var/log/tuxdroid/"
+                path = systemPaths.getLogPath()
+                if not os.path.isdir(path):
+                    os.makedirs(path, mode=0755)
+                self.__logPath = path
         else:
             self.__logPath = logPath
 

Added: 
software_suite_v3/smart-core/smart-server/branches/user_mode/util/misc/systemPaths.py
===================================================================
--- 
software_suite_v3/smart-core/smart-server/branches/user_mode/util/misc/systemPaths.py
                               (rev 0)
+++ 
software_suite_v3/smart-core/smart-server/branches/user_mode/util/misc/systemPaths.py
       2009-09-14 10:07:31 UTC (rev 5365)
@@ -0,0 +1,120 @@
+# -*- coding: latin1 -*-
+
+#    Copyright (C) 2009 Kysoh SA (http://www.kysoh.com)
+#    Paul Rathgeb ( paul dot rathgeb at kysoh dot com )
+#    Distributed under the terms of the GNU General Public License
+#    http://www.gnu.org/copyleft/gpl.html
+
+import os
+
+class systemPaths(object):
+
+
+    def getServerPort():
+        """Get the server port
+        """
+        if os.name == "nt":
+            return 270
+        else:
+            if os.geteuid() == 0:
+                return 270
+            else:
+                return 54321
+
+    def getLogPath():
+        """Get the logs path
+        """
+        if os.name == "nt":
+            #Default Path
+            print "FIXME: Add the log path for Windows"
+            return "None"
+        else:
+            if os.geteuid() == 0:
+                #root
+                return "/var/log/tuxdroid/"
+            else:
+                # Retrieve the HOME directory
+                h = os.getenv("HOME")
+                path = os.path.join(h, ".tuxdroid", "logs")
+                if not os.path.isdir(path):
+                    os.makedirs(path, mode=0755)
+                return path
+
+    def getPidPath():
+        """Get the PID file Path
+        """
+        if os.name == "nt":
+            print "FIXME: Add the PID file path for Windows"
+            return "None"
+        else:
+            if os.geteuid() == 0:
+                return "/var/run/"
+            else:
+                # Retrieve the HOME directory
+                h = os.getenv("HOME")
+                path = os.path.join(h, ".tuxdroid", "run")
+                if not os.path.isdir(path):
+                    os.makedirs(path, mode=0755)
+                return path
+
+    def getResourcesConfPath():
+        """Get the resource configuration path
+        """
+        if os.name == "nt":
+            print "FIXME: Add the resource configuration PATH for Windows"
+            return "None"
+        else:
+            if os.geteuid() == 0:
+                return os.path.join("/etc/tuxdroid", "resource_conf")
+            else:
+                h = os.getenv("HOME")
+                path = os.path.join(h, ".tuxdroid", "resource_conf")
+                if not os.path.isdir(path):
+                    os.makedirs(path, mode=0755)
+                return path
+    
+    def getUserConfPath():
+        """Get the user configuration path
+        """
+        if os.name == "nt":
+            print "FIXME: Add the user configuration PATH for Windows"
+            return "None"
+        else:
+            if os.geteuid() == 0:
+                return os.path.join("/etc/tuxdroid", "users_conf")
+            else:
+                h = os.getenv("HOME")
+                path = os.path.join(h, ".tuxdroid", "users_conf")
+                if not os.path.isdir(path):
+                    os.makedirs(path, mode=0755)
+                return path
+    
+    def getUpdateContentPath():
+        """Get the user configuration path
+        """
+        if os.name == "nt":
+            print "FIXME: Add the user configuration PATH for Windows"
+            return "None"
+        else:
+            if os.geteuid() == 0:
+                return os.path.join("/usr/share/tuxdroid/resources", "updates")
+            else:
+                h = os.getenv("HOME")
+                path = os.path.join(h, ".tuxdroid", "updates")
+                if not os.path.isdir(path):
+                    os.makedirs(path, mode=0755)
+                return path
+
+    def isUser():
+        if os.geteuid() == 0:
+            return False
+        else:
+            return True
+    
+    getServerPort = staticmethod(getServerPort)
+    getLogPath = staticmethod(getLogPath)
+    getPidPath = staticmethod(getPidPath)
+    getResourcesConfPath = staticmethod(getResourcesConfPath)
+    getUserConfPath = staticmethod(getUserConfPath)
+    getUpdateContentPath = staticmethod(getUpdateContentPath)
+    isUser = staticmethod(isUser)


Property changes on: 
software_suite_v3/smart-core/smart-server/branches/user_mode/util/misc/systemPaths.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + text/x-python
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to