PageRenderTime 31ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/webapps/demo_sequencer/config.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 121 lines | 113 code | 4 blank | 4 comment | 0 complexity | c1f1da8433c8aa22c936b6131c9c0b42 MD5 | raw file
  1. """
  2. Universe configuration builder.
  3. """
  4. import sys, os
  5. import logging, logging.config
  6. from optparse import OptionParser
  7. import ConfigParser
  8. from galaxy.util import string_as_bool
  9. from galaxy import eggs
  10. import pkg_resources
  11. log = logging.getLogger( __name__ )
  12. def resolve_path( path, root ):
  13. """If 'path' is relative make absolute by prepending 'root'"""
  14. if not( os.path.isabs( path ) ):
  15. path = os.path.join( root, path )
  16. return path
  17. class ConfigurationError( Exception ):
  18. pass
  19. class Configuration( object ):
  20. def __init__( self, **kwargs ):
  21. self.config_dict = kwargs
  22. self.root = kwargs.get( 'root_dir', '.' )
  23. # Collect the umask and primary gid from the environment
  24. self.umask = os.umask( 077 ) # get the current umask
  25. os.umask( self.umask ) # can't get w/o set, so set it back
  26. # Where dataset files are stored
  27. self.file_path = resolve_path( kwargs.get( "file_path", "database/files" ), self.root )
  28. self.new_file_path = resolve_path( kwargs.get( "new_file_path", "database/tmp" ), self.root )
  29. self.cookie_path = kwargs.get( "cookie_path", "/" )
  30. self.test_conf = resolve_path( kwargs.get( "test_conf", "" ), self.root )
  31. self.id_secret = kwargs.get( "id_secret", "USING THE DEFAULT IS NOT SECURE!" )
  32. self.use_remote_user = string_as_bool( kwargs.get( "use_remote_user", "False" ) )
  33. self.remote_user_maildomain = kwargs.get( "remote_user_maildomain", None )
  34. self.remote_user_logout_href = kwargs.get( "remote_user_logout_href", None )
  35. self.require_login = string_as_bool( kwargs.get( "require_login", "False" ) )
  36. self.allow_user_creation = string_as_bool( kwargs.get( "allow_user_creation", "True" ) )
  37. self.allow_user_deletion = string_as_bool( kwargs.get( "allow_user_deletion", "False" ) )
  38. self.template_path = resolve_path( kwargs.get( "template_path", "templates" ), self.root )
  39. self.template_cache = resolve_path( kwargs.get( "template_cache_path", "database/compiled_templates/demo_sequencer" ), self.root )
  40. self.admin_users = kwargs.get( "admin_users", "" )
  41. self.sendmail_path = kwargs.get('sendmail_path',"/usr/sbin/sendmail")
  42. self.mailing_join_addr = kwargs.get('mailing_join_addr',"galaxy-announce-join@bx.psu.edu")
  43. self.error_email_to = kwargs.get( 'error_email_to', None )
  44. self.smtp_server = kwargs.get( 'smtp_server', None )
  45. self.log_actions = string_as_bool( kwargs.get( 'log_actions', 'False' ) )
  46. self.brand = kwargs.get( 'brand', None )
  47. self.wiki_url = kwargs.get( 'wiki_url', 'http://wiki.g2.bx.psu.edu/FrontPage' )
  48. self.blog_url = kwargs.get( 'blog_url', None )
  49. self.screencasts_url = kwargs.get( 'screencasts_url', None )
  50. self.log_events = False
  51. self.cloud_controller_instance = False
  52. # Proxy features
  53. self.apache_xsendfile = kwargs.get( 'apache_xsendfile', False )
  54. self.nginx_x_accel_redirect_base = kwargs.get( 'nginx_x_accel_redirect_base', False )
  55. self.sequencer_actions_config = kwargs.get( 'sequencer_actions_config_file', 'galaxy/webapps/demo_sequencer/sequencer_actions.xml' )
  56. # Parse global_conf and save the parser
  57. global_conf = kwargs.get( 'global_conf', None )
  58. global_conf_parser = ConfigParser.ConfigParser()
  59. self.global_conf_parser = global_conf_parser
  60. if global_conf and "__file__" in global_conf:
  61. global_conf_parser.read(global_conf['__file__'])
  62. def get( self, key, default ):
  63. return self.config_dict.get( key, default )
  64. def get_bool( self, key, default ):
  65. if key in self.config_dict:
  66. return string_as_bool( self.config_dict[key] )
  67. else:
  68. return default
  69. def check( self ):
  70. # Check that required directories exist
  71. for path in self.root, self.file_path, self.template_path:
  72. if not os.path.isdir( path ):
  73. raise ConfigurationError("Directory does not exist: %s" % path )
  74. def is_admin_user( self, user ):
  75. """
  76. Determine if the provided user is listed in `admin_users`.
  77. """
  78. admin_users = self.get( "admin_users", "" ).split( "," )
  79. return user is not None and user.email in admin_users
  80. def configure_logging( config ):
  81. """
  82. Allow some basic logging configuration to be read from the cherrpy
  83. config.
  84. """
  85. # PasteScript will have already configured the logger if the appropriate
  86. # sections were found in the config file, so we do nothing if the
  87. # config has a loggers section, otherwise we do some simple setup
  88. # using the 'log_*' values from the config.
  89. if config.global_conf_parser.has_section( "loggers" ):
  90. return
  91. format = config.get( "log_format", "%(name)s %(levelname)s %(asctime)s %(message)s" )
  92. level = logging._levelNames[ config.get( "log_level", "DEBUG" ) ]
  93. destination = config.get( "log_destination", "stdout" )
  94. log.info( "Logging at '%s' level to '%s'" % ( level, destination ) )
  95. # Get root logger
  96. root = logging.getLogger()
  97. # Set level
  98. root.setLevel( level )
  99. # Turn down paste httpserver logging
  100. if level <= logging.DEBUG:
  101. logging.getLogger( "paste.httpserver.ThreadPool" ).setLevel( logging.WARN )
  102. # Remove old handlers
  103. for h in root.handlers[:]:
  104. root.removeHandler(h)
  105. # Create handler
  106. if destination == "stdout":
  107. handler = logging.StreamHandler( sys.stdout )
  108. else:
  109. handler = logging.FileHandler( destination )
  110. # Create formatter
  111. formatter = logging.Formatter( format )
  112. # Hook everything up
  113. handler.setFormatter( formatter )
  114. root.addHandler( handler )