diff options
-rw-r--r-- | mediagoblin/config.py | 71 | ||||
-rw-r--r-- | mediagoblin/config_spec.ini | 69 | ||||
-rw-r--r-- | setup.py | 1 |
3 files changed, 141 insertions, 0 deletions
diff --git a/mediagoblin/config.py b/mediagoblin/config.py new file mode 100644 index 00000000..533dbe19 --- /dev/null +++ b/mediagoblin/config.py @@ -0,0 +1,71 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 Free Software Foundation, Inc +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import os +import pkg_resources + +from configobj import ConfigObj +from validate import Validator + + +CONFIG_SPEC_PATH = pkg_resources.resource_filename( + 'mediagoblin', 'config_spec.ini') + + +def _setup_defaults(config, config_path): + """ + Setup DEFAULTS in a config object from an (absolute) config_path. + """ + config.setdefault('DEFAULT', {}) + config['DEFAULT']['here'] = os.path.dirname(config_path) + config['DEFAULT']['__file__'] = config_path + + +def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH): + """ + Read a config object from config_path. + + Does automatic value transformation based on the config_spec. + Also provides %(__file__)s and %(here)s values of this file and + its directory respectively similar to paste deploy. + + Args: + - config_path: path to the config file + - config_spec: config file that provides defaults and value types + for validation / conversion. Defaults to mediagoblin/config_spec.ini + + Returns: + A read ConfigObj object. + """ + config_path = os.path.abspath(config_path) + + config_spec = ConfigObj( + CONFIG_SPEC_PATH, + encoding='UTF8', list_values=False, _inspec=True) + + _setup_defaults(config_spec, config_path) + + conf = ConfigObj( + config_path, + configspec=config_spec, + interpolation='ConfigParser') + + _setup_defaults(conf, config_path) + + conf.validate(Validator()) + + return conf + diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini new file mode 100644 index 00000000..f91d1c1b --- /dev/null +++ b/mediagoblin/config_spec.ini @@ -0,0 +1,69 @@ +[mediagoblin] +# +queuestore_base_dir = string(default="%(here)s/user_dev/media/queue") +publicstore_base_dir = string(default="%(here)s/user_dev/media/public") + +# Where temporary files used in processing and etc are kept +workbench_base_dir = string(default="%(here)s/user_dev/media/workbench") + +# +publicstore_base_url = string(default="/mgoblin_media/") + +# Where mediagoblin-builtin static assets are kept +direct_remote_path = string(default="/mgoblin_static/") + +# set to false to enable sending notices +email_debug_mode = boolean(default=True) +email_sender_address = string(default="notice@mediagoblin.example.org") + +local_templates = string(default="%(here)s/user_dev/templates/") + +# Whether or not celery is set up via an environment variable or +# something else (and thus mediagoblin should not attempt to set it up +# itself) +celery_setup_elsewhere = boolean(default=False) + +[celery] +# known booleans +celery_result_persistent = boolean() +celery_create_missing_queues = boolean() +broker_use_ssl = boolean() +broker_connection_retry = boolean() +celery_always_eager = boolean() +celery_eager_propagates_exceptions = boolean() +celery_ignore_result = boolean() +celery_track_started = boolean() +celery_disable_rate_limits = boolean() +celery_acks_late = boolean() +celery_store_errors_even_if_ignored = boolean() +celery_send_task_error_emails = boolean() +celery_send_events = boolean() +celery_send_task_sent_event = boolean() +celeryd_log_color = boolean() +celery_redirect_stdouts = boolean() + +# known ints +celeryd_concurrency = integer() +celeryd_prefetch_multiplier = integer() +celery_amqp_task_result_expires = integer() +celery_amqp_task_result_connection_max = integer() +redis_port = integer() +redis_db = integer() +broker_port = integer() +broker_connection_timeout = integer() +celery_broker_connection_max_retries = integer() +celery_task_result_expires = integer() +celery_max_cached_results = integer() +celery_default_rate_limit = integer() +celeryd_max_tasks_per_child = integer() +celeryd_task_time_limit = integer() +celeryd_task_soft_time_limit = integer() +mail_port = integer() +celerybeat_max_loop_interval = integer() + +# known floats +celeryd_eta_scheduler_precision = float() + +# known lists +celery_routes = list() +celery_imports = list()
\ No newline at end of file @@ -42,6 +42,7 @@ setup( 'translitcodec', 'argparse', 'webtest', + 'ConfigObj', 'lxml', ], test_suite='nose.collector', |