[tuxdroid-svn] r5900 - in software_suite_v3/smart-core/smart-server/trunk: . resources/00_smart_se
Status: Beta
Brought to you by:
ks156
Author: ks156 Date: 2009-11-18 11:25:08 +0100 (Wed, 18 Nov 2009) New Revision: 5900 Added: software_suite_v3/smart-core/smart-server/trunk/util/misc/systemPaths.py Modified: software_suite_v3/smart-core/smart-server/trunk/TDSConfiguration.py software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/04_resourceMenu.py software_suite_v3/smart-core/smart-server/trunk/resources/05_user_configurations/00_resourceUsers.py software_suite_v3/smart-core/smart-server/trunk/tuxhttpserver.py software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetGenerator.py software_suite_v3/smart-core/smart-server/trunk/util/daemonizer/Daemonizer.py software_suite_v3/smart-core/smart-server/trunk/util/logger/SimpleLogger.py Log: * Merged the user_mode branch from rev 5345 in the trunk. This branch is now done and discontinued. Modified: software_suite_v3/smart-core/smart-server/trunk/TDSConfiguration.py =================================================================== --- software_suite_v3/smart-core/smart-server/trunk/TDSConfiguration.py 2009-11-18 10:21:55 UTC (rev 5899) +++ software_suite_v3/smart-core/smart-server/trunk/TDSConfiguration.py 2009-11-18 10:25:08 UTC (rev 5900) @@ -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 @@ -89,19 +91,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/trunk/resources/00_smart_server_base/04_resourceMenu.py =================================================================== --- software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/04_resourceMenu.py 2009-11-18 10:21:55 UTC (rev 5899) +++ software_suite_v3/smart-core/smart-server/trunk/resources/00_smart_server_base/04_resourceMenu.py 2009-11-18 10:25:08 UTC (rev 5900) @@ -224,7 +224,9 @@ self.__logPath = os.path.join(os.environ['ALLUSERSPROFILE'], "Kysoh", "Tux Droid", "logs") else: - self.__logPath = "/var/log/tuxdroid" + from util.misc.systemPaths import systemPaths + path = systemPaths.getLogPath() + self.__logPath = path # -------------------------------------------------------------------------- # Execute the service. Modified: software_suite_v3/smart-core/smart-server/trunk/resources/05_user_configurations/00_resourceUsers.py =================================================================== --- software_suite_v3/smart-core/smart-server/trunk/resources/05_user_configurations/00_resourceUsers.py 2009-11-18 10:21:55 UTC (rev 5899) +++ software_suite_v3/smart-core/smart-server/trunk/resources/05_user_configurations/00_resourceUsers.py 2009-11-18 10:25:08 UTC (rev 5900) @@ -70,6 +70,33 @@ """ 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 systemPaths.isUser() and os.name != 'nt': + if not os.path.isfile(userConfFile): + os.system("cp /etc/tuxdroid/users_conf/default/user.conf %s"%userConfFile) + else: + try: + f_sys = open("/etc/tuxdroid/users_conf/default/user.conf", "r") + dict = eval(f_sys.read()) + f_sys.close() + lang_sys = dict['language1'] + except: + lang_sys = None + try: + path = os.path.join(systemPaths.getUserConfPath(), "default", "user.conf") + f_user = open(path, "r") + dict = eval(f_user.read()) + f_user.close() + lang_user = dict['language1'] + except: + lang_user = None + + if lang_user != lang_sys and lang_user != None and lang_sys != None: + 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/trunk/tuxhttpserver.py =================================================================== --- software_suite_v3/smart-core/smart-server/trunk/tuxhttpserver.py 2009-11-18 10:21:55 UTC (rev 5899) +++ software_suite_v3/smart-core/smart-server/trunk/tuxhttpserver.py 2009-11-18 10:25:08 UTC (rev 5900) @@ -108,7 +108,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/trunk/util/applicationserver/gadget/GadgetGenerator.py =================================================================== --- software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetGenerator.py 2009-11-18 10:21:55 UTC (rev 5899) +++ software_suite_v3/smart-core/smart-server/trunk/util/applicationserver/gadget/GadgetGenerator.py 2009-11-18 10:25:08 UTC (rev 5900) @@ -442,7 +442,10 @@ tmpFile = open(os.path.join(tmpRootDir, "help.wiki"), "w") tmpFile.write(helpFileContent) tmpFile.close() - tmpGadgetFile = "gadget_%s.scg" % gadgetUuid + if os.name == 'nt': + tmpGadgetFile = "gadget_%s.scg" % gadgetUuid + else: + tmpGadgetFile = "/tmp/gadget_%s.scg" % gadgetUuid zout = zipfile.ZipFile(tmpGadgetFile, "w") zout.write(os.path.join(tmpRootDir, "gadget.xml"), "gadget.xml") zout.write(os.path.join(tmpRootDir, "gadget.png"), "gadget.png") Modified: software_suite_v3/smart-core/smart-server/trunk/util/daemonizer/Daemonizer.py =================================================================== --- software_suite_v3/smart-core/smart-server/trunk/util/daemonizer/Daemonizer.py 2009-11-18 10:21:55 UTC (rev 5899) +++ software_suite_v3/smart-core/smart-server/trunk/util/daemonizer/Daemonizer.py 2009-11-18 10:25:08 UTC (rev 5900) @@ -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/trunk/util/logger/SimpleLogger.py =================================================================== --- software_suite_v3/smart-core/smart-server/trunk/util/logger/SimpleLogger.py 2009-11-18 10:21:55 UTC (rev 5899) +++ software_suite_v3/smart-core/smart-server/trunk/util/logger/SimpleLogger.py 2009-11-18 10:25:08 UTC (rev 5900) @@ -16,6 +16,8 @@ import threading import time +from util.misc.systemPaths import systemPaths + # Levels LOG_LEVEL_DEBUG = 0 LOG_LEVEL_INFO = 1 @@ -61,9 +63,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 Copied: software_suite_v3/smart-core/smart-server/trunk/util/misc/systemPaths.py (from rev 5894, software_suite_v3/smart-core/smart-server/branches/user_mode/util/misc/systemPaths.py) =================================================================== --- software_suite_v3/smart-core/smart-server/trunk/util/misc/systemPaths.py (rev 0) +++ software_suite_v3/smart-core/smart-server/trunk/util/misc/systemPaths.py 2009-11-18 10:25:08 UTC (rev 5900) @@ -0,0 +1,123 @@ +# -*- 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", "resources_conf") + else: + h = os.getenv("HOME") + path = os.path.join(h, ".tuxdroid", "resources_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.name == "nt": + return True + else: + 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) |