root/galaxy-central/lib/galaxy/webapps/community/config.py

リビジョン 2, 6.9 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1"""
2Universe configuration builder.
3"""
4
5import sys, os
6import logging, logging.config
7from optparse import OptionParser
8import ConfigParser
9from galaxy.util import string_as_bool
10
11from galaxy import eggs
12import pkg_resources
13
14log = logging.getLogger( __name__ )
15
16def resolve_path( path, root ):
17    """If 'path' is relative make absolute by prepending 'root'"""
18    if not( os.path.isabs( path ) ):
19        path = os.path.join( root, path )
20    return path
21
22class ConfigurationError( Exception ):
23    pass
24
25class Configuration( object ):
26    def __init__( self, **kwargs ):
27        self.config_dict = kwargs
28        self.root = kwargs.get( 'root_dir', '.' )
29        # Collect the umask and primary gid from the environment
30        self.umask = os.umask( 077 ) # get the current umask
31        os.umask( self.umask ) # can't get w/o set, so set it back
32        self.gid = os.getgid() # if running under newgrp(1) we'll need to fix the group of data created on the cluster
33        # Database related configuration
34        self.database = resolve_path( kwargs.get( "database_file", "database/universe.d" ), self.root )
35        self.database_connection =  kwargs.get( "database_connection", False )
36        self.database_engine_options = get_database_engine_options( kwargs )                       
37        self.database_create_tables = string_as_bool( kwargs.get( "database_create_tables", "True" ) )
38        # Where dataset files are stored
39        self.file_path = resolve_path( kwargs.get( "file_path", "database/files" ), self.root )
40        self.new_file_path = resolve_path( kwargs.get( "new_file_path", "database/tmp" ), self.root )
41        self.cookie_path = kwargs.get( "cookie_path", "/" )
42        self.test_conf = resolve_path( kwargs.get( "test_conf", "" ), self.root )
43        self.id_secret = kwargs.get( "id_secret", "USING THE DEFAULT IS NOT SECURE!" )
44        self.use_remote_user = string_as_bool( kwargs.get( "use_remote_user", "False" ) )
45        self.remote_user_maildomain = kwargs.get( "remote_user_maildomain", None )
46        self.remote_user_logout_href = kwargs.get( "remote_user_logout_href", None )
47        self.require_login = string_as_bool( kwargs.get( "require_login", "False" ) )
48        self.allow_user_creation = string_as_bool( kwargs.get( "allow_user_creation", "True" ) )
49        self.template_path = resolve_path( kwargs.get( "template_path", "templates" ), self.root )
50        self.template_cache = resolve_path( kwargs.get( "template_cache_path", "database/compiled_templates/community" ), self.root )
51        self.admin_users = kwargs.get( "admin_users", "" )
52        self.sendmail_path = kwargs.get('sendmail_path',"/usr/sbin/sendmail")
53        self.mailing_join_addr = kwargs.get('mailing_join_addr',"galaxy-user-join@bx.psu.edu")
54        self.error_email_to = kwargs.get( 'error_email_to', None )
55        self.smtp_server = kwargs.get( 'smtp_server', None )
56        self.log_actions = string_as_bool( kwargs.get( 'log_actions', 'False' ) )
57        self.brand = kwargs.get( 'brand', None )
58        self.wiki_url = kwargs.get( 'wiki_url', 'http://bitbucket.org/galaxy/galaxy-central/wiki/Home' )
59        self.bugs_email = kwargs.get( 'bugs_email', None )
60        self.blog_url = kwargs.get( 'blog_url', None )
61        self.screencasts_url = kwargs.get( 'screencasts_url', None )
62        self.log_events = False
63        self.cloud_controller_instance = False
64        self.datatypes_config = kwargs.get( 'datatypes_config_file', 'community_datatypes_conf.xml' )
65        # Proxy features
66        self.apache_xsendfile = kwargs.get( 'apache_xsendfile', False )
67        self.nginx_x_accel_redirect_base = kwargs.get( 'nginx_x_accel_redirect_base', False )
68        # Parse global_conf and save the parser
69        global_conf = kwargs.get( 'global_conf', None )
70        global_conf_parser = ConfigParser.ConfigParser()
71        self.global_conf_parser = global_conf_parser
72        if global_conf and "__file__" in global_conf:
73            global_conf_parser.read(global_conf['__file__'])
74    def get( self, key, default ):
75        return self.config_dict.get( key, default )
76    def get_bool( self, key, default ):
77        if key in self.config_dict:
78            return string_as_bool( self.config_dict[key] )
79        else:
80            return default
81    def check( self ):
82        # Check that required directories exist
83        for path in self.root, self.file_path, self.template_path:
84            if not os.path.isdir( path ):
85                raise ConfigurationError("Directory does not exist: %s" % path )
86    def is_admin_user( self, user ):
87        """
88        Determine if the provided user is listed in `admin_users`.
89        """
90        admin_users = self.get( "admin_users", "" ).split( "," )
91        return user is not None and user.email in admin_users
92
93def get_database_engine_options( kwargs ):
94    """
95    Allow options for the SQLAlchemy database engine to be passed by using
96    the prefix "database_engine_option_".
97    """
98    conversions =  {
99        'convert_unicode': string_as_bool,
100        'pool_timeout': int,
101        'echo': string_as_bool,
102        'echo_pool': string_as_bool,
103        'pool_recycle': int,
104        'pool_size': int,
105        'max_overflow': int,
106        'pool_threadlocal': string_as_bool,
107        'server_side_cursors': string_as_bool
108    }
109    prefix = "database_engine_option_"
110    prefix_len = len( prefix )
111    rval = {}
112    for key, value in kwargs.iteritems():
113        if key.startswith( prefix ):
114            key = key[prefix_len:]
115            if key in conversions:
116                value = conversions[key](value)
117            rval[ key  ] = value
118    return rval
119
120def configure_logging( config ):
121    """
122    Allow some basic logging configuration to be read from the cherrpy
123    config.
124    """
125    # PasteScript will have already configured the logger if the appropriate
126    # sections were found in the config file, so we do nothing if the
127    # config has a loggers section, otherwise we do some simple setup
128    # using the 'log_*' values from the config.
129    if config.global_conf_parser.has_section( "loggers" ):
130        return
131    format = config.get( "log_format", "%(name)s %(levelname)s %(asctime)s %(message)s" )
132    level = logging._levelNames[ config.get( "log_level", "DEBUG" ) ]
133    destination = config.get( "log_destination", "stdout" )
134    log.info( "Logging at '%s' level to '%s'" % ( level, destination ) )
135    # Get root logger
136    root = logging.getLogger()
137    # Set level
138    root.setLevel( level )
139    # Turn down paste httpserver logging
140    if level <= logging.DEBUG:
141        logging.getLogger( "paste.httpserver.ThreadPool" ).setLevel( logging.WARN )
142    # Remove old handlers
143    for h in root.handlers[:]:
144        root.removeHandler(h)
145    # Create handler
146    if destination == "stdout":
147        handler = logging.StreamHandler( sys.stdout )
148    else:
149        handler = logging.FileHandler( destination )
150    # Create formatter
151    formatter = logging.Formatter( format )   
152    # Hook everything up
153    handler.setFormatter( formatter )
154    root.addHandler( handler )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。