From 2b1e0af03b7c92b504313a2c6461190a43bc1c28 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 10 Aug 2014 16:19:50 -0500 Subject: [PATCH 1/3] defaults now pulled from a mashup of mediagoblin.ini and config_spec.ini MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit sponsored by Thomas Løcke. Thank you! --- mediagoblin/init/config.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/mediagoblin/init/config.py b/mediagoblin/init/config.py index 11a91cff..8d5577ac 100644 --- a/mediagoblin/init/config.py +++ b/mediagoblin/init/config.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import copy import logging import os import pkg_resources @@ -29,13 +30,18 @@ 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): @@ -73,6 +79,19 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH): plugins = config.get("plugins", {}).keys() plugin_configs = {} + # Now load the main config spec + config_spec = ConfigObj( + config_spec, + encoding='UTF8', list_values=False, _inspec=True) + + # temporary bootstrap, just setup here and __file__... we'll do this again + _setup_defaults(config, config_path) + + # 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.get('DEFAULT', {})) + for plugin in plugins: try: plugin_config_spec_path = pkg_resources.resource_filename( @@ -83,7 +102,8 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH): plugin_config_spec = ConfigObj( plugin_config_spec_path, encoding='UTF8', list_values=False, _inspec=True) - _setup_defaults(plugin_config_spec, config_path) + _setup_defaults( + plugin_config_spec, config_path, mainconfig_defaults) if not "plugin_spec" in plugin_config_spec: continue @@ -95,22 +115,17 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH): "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 - _setup_defaults(config_spec, config_path) + _setup_defaults(config_spec, config_path, mainconfig_defaults) config = ConfigObj( config_path, configspec=config_spec, 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 From 98cbe47fb3243dc4d500a1ce1d93240f200e6f0c Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 10 Aug 2014 16:27:29 -0500 Subject: [PATCH 2/3] Updated config_spec.ini to add %(data_basedir)s and make use of it! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit sponsored by Loïc Grobol. Thanks! --- mediagoblin.ini | 6 +++--- mediagoblin/config_spec.ini | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/mediagoblin.ini b/mediagoblin.ini index 5e2477a4..de4d2c85 100644 --- a/mediagoblin.ini +++ b/mediagoblin.ini @@ -24,7 +24,7 @@ allow_registration = true allow_reporting = true ## Uncomment this to put some user-overriding templates here -# local_templates = %(here)s/user_dev/templates/ +# local_templates = %(data_basedir)s/templates/ ## You can set your theme by specifying this (not specifying it will ## use the default theme). Run `gmg assetlink` to apply the change. @@ -37,10 +37,10 @@ allow_reporting = true user_privilege_scheme = "uploader,commenter,reporter" [storage:queuestore] -base_dir = %(here)s/user_dev/media/queue +base_dir = %(data_basedir)s/media/queue [storage:publicstore] -base_dir = %(here)s/user_dev/media/public +base_dir = %(data_basedir)s/media/public base_url = /mgoblin_media/ [celery] diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini index f3f3f7ab..dade8420 100644 --- a/mediagoblin/config_spec.ini +++ b/mediagoblin/config_spec.ini @@ -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. From 11f0e2f89bade7f3d38665968adf478c3b039c5d Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Fri, 19 Sep 2014 14:15:11 +0100 Subject: [PATCH 3/3] Add documentation on changing data dir and Fix stylistic changes --- docs/source/siteadmin/configuration.rst | 28 +++++++++++++++++ mediagoblin.ini | 5 ++++ mediagoblin/init/config.py | 40 ++++++++++++------------- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/docs/source/siteadmin/configuration.rst b/docs/source/siteadmin/configuration.rst index 3da5cdd9..dd0d6cd9 100644 --- a/docs/source/siteadmin/configuration.rst +++ b/docs/source/siteadmin/configuration.rst @@ -109,6 +109,34 @@ they sound like. - email_smtp_user - email_smtp_pass +Changing data directory +----------------------- + +MediaGoblin by default stores your data in wherever ``data_basedir``. +This can be changed by changing the value in your ``mediagoblin.ini`` file +for example:: + + [DEFAULT] + data_basedir = "/var/mediagoblin/user_data" + +For efficiency reasons MediaGoblin doesn't serve these files itself and +instead leaves that to the webserver. You will have to alter the location +to match the path in ``data_basedir``. + +If you use ``lazyserver.sh`` you need to change the ``paste.ini`` file:: + + [app:mediagoblin] + /mgoblin_media = /var/mediagoblin/user_data + +If you use nginx you need to change the config:: + + # Instance specific media: + location /mgoblin_media/ { + alias /var/mediagoblin/user_data; + } + +Once you have done this you will need to move any existing media you had in the +old directory to the new directory so existing media still can be displayed. All other configuration changes ------------------------------- diff --git a/mediagoblin.ini b/mediagoblin.ini index de4d2c85..7899d7ca 100644 --- a/mediagoblin.ini +++ b/mediagoblin.ini @@ -5,6 +5,11 @@ # It defines types and defaults so it’s a good place to look for documentation # or to find hidden options that we didn’t tell you about. :) +# To chnange the directory you should make sure you change the +# directory in paste.ini and/or your webserver configuration. +#[DEFAULT] +# data_basedir = "/path/to/data/directory" + [mediagoblin] direct_remote_path = /mgoblin_static/ email_sender_address = "notice@mediagoblin.example.org" diff --git a/mediagoblin/init/config.py b/mediagoblin/init/config.py index 8d5577ac..a9189e8d 100644 --- a/mediagoblin/init/config.py +++ b/mediagoblin/init/config.py @@ -39,12 +39,12 @@ def _setup_defaults(config, config_path, extra_defaults=None): 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. @@ -60,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: @@ -74,23 +74,23 @@ 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') - - plugins = config.get("plugins", {}).keys() - plugin_configs = {} - - # Now load the main config spec - config_spec = ConfigObj( - config_spec, - encoding='UTF8', list_values=False, _inspec=True) + 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.get('DEFAULT', {})) + # 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 = {} for plugin in plugins: try: @@ -98,10 +98,10 @@ 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) + encoding="UTF8", list_values=False, _inspec=True) _setup_defaults( plugin_config_spec, config_path, mainconfig_defaults) @@ -114,16 +114,16 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH): _log.warning( "When setting up config section, could not import '%s'" % plugin) - + # 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, mainconfig_defaults) config = ConfigObj( config_path, configspec=config_spec, - interpolation='ConfigParser') + interpolation="ConfigParser") _setup_defaults(config, config_path, mainconfig_defaults)