Personal wiki notebook (not under development)

Desktop.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import os
  2. import os.path
  3. import socket
  4. import cherrypy
  5. from tempfile import gettempdir
  6. username_postfix = os.environ.get( "USER" )
  7. username_postfix = username_postfix and "_%s" % username_postfix or ""
  8. def find_available_port( port_number = 0 ):
  9. sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
  10. sock.bind( ( "", port_number ) )
  11. socket_port = sock.getsockname()[ 1 ]
  12. sock.close()
  13. return socket_port
  14. # find an available TCP socket to listen on. try the default port first, and if that's not
  15. # available, then just grab any available port that the OS gives us
  16. DEFAULT_PORT = 6520
  17. try:
  18. socket_port = find_available_port( DEFAULT_PORT )
  19. except socket.error:
  20. socket_port = find_available_port()
  21. settings = {
  22. "global": {
  23. "server.socket_port": socket_port,
  24. "server.socket_host": "localhost",
  25. "server.thread_pool": 4,
  26. "session_filter.storage_class": None,
  27. "session_filter.storage_type": "ram",
  28. "session_filter.timeout": 60 * 24 * 365, # one year
  29. "static_filter.root": os.getcwd(),
  30. "server.log_to_screen": False,
  31. "server.log_file": os.path.join( gettempdir(), "luminotes_error%s.log" % username_postfix ),
  32. "server.log_access_file": os.path.join( gettempdir(), "luminotes%s.log" % username_postfix ),
  33. "server.log_tracebacks": True,
  34. "luminotes.port_file": os.path.join( gettempdir(), "luminotes_port%s" % username_postfix ),
  35. "luminotes.launch_browser": True,
  36. "luminotes.db_host": None, # use local SQLite database
  37. "luminotes.auto_login_username": "desktopuser",
  38. "luminotes.allow_shutdown_command": True, # used to stop the process during uninstall
  39. "luminotes.rate_plans": [
  40. {
  41. "name": "desktop",
  42. "designed_for": "individuals",
  43. "storage_quota_bytes": None, # None indicates that there is no storage quota
  44. "included_users": 1,
  45. "notebook_sharing": False,
  46. "notebook_collaboration": False,
  47. "user_admin": False,
  48. "fee": None,
  49. "yearly_fee": None,
  50. },
  51. ],
  52. },
  53. "/static": {
  54. "static_filter.on": True,
  55. "static_filter.dir": "static",
  56. },
  57. "/favicon.ico": {
  58. "static_filter.on": True,
  59. "static_filter.file": "static/images/favicon.ico",
  60. },
  61. }