Merge branch '942-default-location'

* 942-default-location:
  Add documentation on changing data dir and Fix stylistic changes
  Updated config_spec.ini to add %(data_basedir)s and make use of it!
  defaults now pulled from a mashup of mediagoblin.ini and config_spec.ini
This commit is contained in:
Jessica Tallon
2014-09-29 09:04:30 +01:00
4 changed files with 78 additions and 27 deletions

View File

@@ -1,3 +1,6 @@
[DEFAULT]
data_basedir = %(here)s/user_dev
[mediagoblin]
# HTML title of the pages
html_title = string(default="GNU MediaGoblin")
@@ -13,10 +16,10 @@ sql_engine = string(default="sqlite:///%(here)s/mediagoblin.db")
run_migrations = boolean(default=False)
# Where temporary files used in processing and etc are kept
workbench_path = string(default="%(here)s/user_dev/media/workbench")
workbench_path = string(default="%(data_basedir)s/media/workbench")
# Where to store cryptographic sensible data
crypto_path = string(default="%(here)s/user_dev/crypto")
crypto_path = string(default="%(data_basedir)s/crypto")
# Where mediagoblin-builtin static assets are kept
direct_remote_path = string(default="/mgoblin_static/")
@@ -67,7 +70,7 @@ allow_reporting = boolean(default=True)
show_tos = boolean(default=False)
# By default not set, but you might want something like:
# "%(here)s/user_dev/templates/"
# "%(data_basedir)s/templates/"
local_templates = string()
# Whether or not celery is set up via an environment variable or
@@ -90,14 +93,14 @@ exif_visible = boolean(default=False)
original_date_visible = boolean(default=False)
# Theming stuff
theme_install_dir = string(default="%(here)s/user_dev/themes/")
theme_install_dir = string(default="%(data_basedir)s/themes/")
theme_web_path = string(default="/theme_static/")
theme_linked_assets_dir = string(default="%(here)s/user_dev/theme_static/")
theme_linked_assets_dir = string(default="%(data_basedir)s/theme_static/")
theme = string()
# plugin default assets directory
plugin_web_path = string(default="/plugin_static/")
plugin_linked_assets_dir = string(default="%(here)s/user_dev/plugin_static/")
plugin_linked_assets_dir = string(default="%(data_basedir)s/plugin_static/")
# Default user upload limit (in Mb)
upload_limit = integer(default=None)
@@ -123,12 +126,12 @@ extensions = string_list(default=list())
[storage:publicstore]
storage_class = string(default="mediagoblin.storage.filestorage:BasicFileStorage")
base_dir = string(default="%(here)s/user_dev/media/public")
base_dir = string(default="%(data_basedir)s/media/public")
base_url = string(default="/mgoblin_media/")
[storage:queuestore]
storage_class = string(default="mediagoblin.storage.filestorage:BasicFileStorage")
base_dir = string(default="%(here)s/user_dev/media/queue")
base_dir = string(default="%(data_basedir)s/media/queue")
[media:medium]
# Dimensions used when creating media display images.

View File

@@ -14,6 +14,7 @@
# 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 copy
import logging
import os
import pkg_resources
@@ -29,16 +30,21 @@ CONFIG_SPEC_PATH = pkg_resources.resource_filename(
'mediagoblin', 'config_spec.ini')
def _setup_defaults(config, config_path):
def _setup_defaults(config, config_path, extra_defaults=None):
"""
Setup DEFAULTS in a config object from an (absolute) config_path.
"""
extra_defaults = extra_defaults or {}
config.setdefault('DEFAULT', {})
config['DEFAULT']['here'] = os.path.dirname(config_path)
config['DEFAULT']['__file__'] = config_path
for key, value in extra_defaults.items():
config['DEFAULT'].setdefault(key, value)
def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH):
def read_mediagoblin_config(config_path, config_spec_path=CONFIG_SPEC_PATH):
"""
Read a config object from config_path.
@@ -54,7 +60,7 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH):
Args:
- config_path: path to the config file
- config_spec: config file that provides defaults and value types
- config_spec_path: config file that provides defaults and value types
for validation / conversion. Defaults to mediagoblin/config_spec.ini
Returns:
@@ -68,7 +74,20 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH):
# we can add their plugin specs to the general config_spec.
config = ConfigObj(
config_path,
interpolation='ConfigParser')
interpolation="ConfigParser")
# temporary bootstrap, just setup here and __file__... we'll do this again
_setup_defaults(config, config_path)
# Now load the main config spec
config_spec = ConfigObj(
config_spec_path,
encoding="UTF8", list_values=False, _inspec=True)
# Set up extra defaults that will be pushed into the rest of the
# configs. This is a combined extrapolation of defaults based on
mainconfig_defaults = copy.copy(config_spec.get("DEFAULT", {}))
mainconfig_defaults.update(config["DEFAULT"])
plugins = config.get("plugins", {}).keys()
plugin_configs = {}
@@ -79,11 +98,12 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH):
plugin, "config_spec.ini")
if not os.path.exists(plugin_config_spec_path):
continue
plugin_config_spec = ConfigObj(
plugin_config_spec_path,
encoding='UTF8', list_values=False, _inspec=True)
_setup_defaults(plugin_config_spec, config_path)
encoding="UTF8", list_values=False, _inspec=True)
_setup_defaults(
plugin_config_spec, config_path, mainconfig_defaults)
if not "plugin_spec" in plugin_config_spec:
continue
@@ -94,23 +114,18 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH):
_log.warning(
"When setting up config section, could not import '%s'" %
plugin)
# Now load the main config spec
config_spec = ConfigObj(
config_spec,
encoding='UTF8', list_values=False, _inspec=True)
# append the plugin specific sections of the config spec
config_spec['plugins'] = plugin_configs
config_spec["plugins"] = plugin_configs
_setup_defaults(config_spec, config_path)
_setup_defaults(config_spec, config_path, mainconfig_defaults)
config = ConfigObj(
config_path,
configspec=config_spec,
interpolation='ConfigParser')
interpolation="ConfigParser")
_setup_defaults(config, config_path)
_setup_defaults(config, config_path, mainconfig_defaults)
# For now the validator just works with the default functions,
# but in the future if we want to add additional validation/configuration