diff --git a/config/Desktop.py b/config/Desktop.py index 2de3c93..bbba6f1 100644 --- a/config/Desktop.py +++ b/config/Desktop.py @@ -4,6 +4,10 @@ import cherrypy from tempfile import gettempdir +username_postfix = os.environ.get( "USER" ) +username_postfix = username_postfix and "_%s" % username_postfix or "" + + settings = { "global": { "server.thread_pool": 4, @@ -11,8 +15,8 @@ settings = { "session_filter.timeout": 60 * 24 * 365, # one year "static_filter.root": os.getcwd(), "server.log_to_screen": False, - "server.log_file": os.path.join( gettempdir(), "luminotes_error.log" ), - "server.log_access_file": os.path.join( gettempdir(), "luminotes.log" ), + "server.log_file": os.path.join( gettempdir(), "luminotes_error%s.log" % username_postfix ), + "server.log_access_file": os.path.join( gettempdir(), "luminotes%s.log" % username_postfix ), "server.log_tracebacks": True, "luminotes.launch_browser": True, "luminotes.db_host": None, # use local SQLite database diff --git a/luminotes.py b/luminotes.py index a39d24f..5f96256 100755 --- a/luminotes.py +++ b/luminotes.py @@ -2,6 +2,7 @@ import os import sys +import stat import socket import os.path import urllib2 as urllib @@ -77,11 +78,16 @@ def main( args ): # remove the existing log files, if any try: - os.remove( cherrypy.config.configMap[ u"global" ].get( u"server.log_access_file" ) ) + log_access_file = cherrypy.config.configMap[ u"global" ].get( u"server.log_access_file" ) + if log_access_file: + os.remove( log_access_file ) except OSError: pass + try: - os.remove( cherrypy.config.configMap[ u"global" ].get( u"server.log_file" ) ) + log_file = cherrypy.config.configMap[ u"global" ].get( u"server.log_file" ) + if log_file: + os.remove( log_file ) except OSError: pass @@ -96,10 +102,25 @@ def main( args ): root = Root( database, cherrypy.config.configMap ) cherrypy.root = root - if launch_browser is True: - cherrypy.server.start_with_callback( webbrowser.open_new, ( server_url, ) ) - else: - cherrypy.server.start() + cherrypy.server.start_with_callback( callback, ( log_access_file, log_file, server_url, launch_browser ) ) + + +def callback( log_access_file, log_file, server_url, launch_browser = False ): + # this causes cherrypy to create the access log + if log_access_file: + try: + urllib.urlopen( "%sping" % server_url ) + except urllib.URLError: + pass + + # give the cherrypy log files appropriate permissions + if log_access_file and os.path.exists( log_access_file ): + os.chmod( log_access_file, stat.S_IRUSR | stat.S_IWUSR ) + if log_file and os.path.exists( log_file ): + os.chmod( log_file, stat.S_IRUSR | stat.S_IWUSR ) + + if launch_browser: + webbrowser.open_new( server_url ) if __name__ == "__main__":