Work towards getting plugin static linking/serving to work
- add link_plugin_assets. For now, incorrectly running from ./bin/gmg theme assetlink... uh, will fix ;) - Update paste and config_spec.ini configs to handle the locations and serving of the plugins' static resources This commit sponsored by Marko Dimjašević. Thank you!
This commit is contained in:
parent
d6d2c771bd
commit
5ccb16ca20
@ -69,6 +69,10 @@ 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="%(here)s/user_dev/theme_static/")
|
||||||
theme = string()
|
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/")
|
||||||
|
|
||||||
|
|
||||||
[storage:publicstore]
|
[storage:publicstore]
|
||||||
storage_class = string(default="mediagoblin.storage.filestorage:BasicFileStorage")
|
storage_class = string(default="mediagoblin.storage.filestorage:BasicFileStorage")
|
||||||
|
@ -17,9 +17,11 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from mediagoblin.init import setup_global_and_app_config
|
from mediagoblin.init import setup_global_and_app_config
|
||||||
|
from mediagoblin.gmg_commands import util as commands_util
|
||||||
from mediagoblin.tools.theme import register_themes
|
from mediagoblin.tools.theme import register_themes
|
||||||
from mediagoblin.tools.translate import pass_to_ugettext as _
|
from mediagoblin.tools.translate import pass_to_ugettext as _
|
||||||
from mediagoblin.tools.common import simple_printer
|
from mediagoblin.tools.common import simple_printer
|
||||||
|
from mediagoblin.tools import pluginapi
|
||||||
|
|
||||||
|
|
||||||
def theme_parser_setup(subparser):
|
def theme_parser_setup(subparser):
|
||||||
@ -44,7 +46,7 @@ def theme_parser_setup(subparser):
|
|||||||
# Utilities
|
# Utilities
|
||||||
###########
|
###########
|
||||||
|
|
||||||
def link_assets(theme, link_dir, printer=simple_printer):
|
def link_theme_assets(theme, link_dir, printer=simple_printer):
|
||||||
"""
|
"""
|
||||||
Returns a list of string of text telling the user what we did
|
Returns a list of string of text telling the user what we did
|
||||||
which should be printable.
|
which should be printable.
|
||||||
@ -52,11 +54,9 @@ def link_assets(theme, link_dir, printer=simple_printer):
|
|||||||
link_dir = link_dir.rstrip(os.path.sep)
|
link_dir = link_dir.rstrip(os.path.sep)
|
||||||
link_parent_dir = os.path.dirname(link_dir)
|
link_parent_dir = os.path.dirname(link_dir)
|
||||||
|
|
||||||
results = []
|
|
||||||
|
|
||||||
if theme is None:
|
if theme is None:
|
||||||
printer(_("Cannot link theme... no theme set\n"))
|
printer(_("Cannot link theme... no theme set\n"))
|
||||||
return results
|
return
|
||||||
|
|
||||||
def _maybe_unlink_link_dir():
|
def _maybe_unlink_link_dir():
|
||||||
"""unlink link directory if it exists"""
|
"""unlink link directory if it exists"""
|
||||||
@ -65,14 +65,14 @@ def link_assets(theme, link_dir, printer=simple_printer):
|
|||||||
os.unlink(link_dir)
|
os.unlink(link_dir)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return results
|
return
|
||||||
|
|
||||||
if theme.get('assets_dir') is None:
|
if theme.get('assets_dir') is None:
|
||||||
printer(_("No asset directory for this theme\n"))
|
printer(_("No asset directory for this theme\n"))
|
||||||
if _maybe_unlink_link_dir():
|
if _maybe_unlink_link_dir():
|
||||||
printer(
|
printer(
|
||||||
_("However, old link directory symlink found; removed.\n"))
|
_("However, old link directory symlink found; removed.\n"))
|
||||||
return results
|
return
|
||||||
|
|
||||||
_maybe_unlink_link_dir()
|
_maybe_unlink_link_dir()
|
||||||
|
|
||||||
@ -87,6 +87,51 @@ def link_assets(theme, link_dir, printer=simple_printer):
|
|||||||
theme['assets_dir'], link_dir))
|
theme['assets_dir'], link_dir))
|
||||||
|
|
||||||
|
|
||||||
|
def link_plugin_assets(plugin_static, plugins_link_dir, printer=simple_printer):
|
||||||
|
"""
|
||||||
|
Arguments:
|
||||||
|
- plugin_static: a mediagoblin.tools.staticdirect.PluginStatic instance
|
||||||
|
representing the static assets of this plugins' configuration
|
||||||
|
- plugins_link_dir: Base directory plugins are linked from
|
||||||
|
"""
|
||||||
|
# link_dir is the final directory we'll link to, a combination of
|
||||||
|
# the plugin assetlink directory and plugin_static.name
|
||||||
|
link_dir = os.path.sep.join(
|
||||||
|
plugins_link_dir.rstrip(os.path.sep), plugin_static.name)
|
||||||
|
|
||||||
|
# make the link directory parent dirs if necessary
|
||||||
|
if not os.path.lexists(plugins_link_dir):
|
||||||
|
os.makedirs(plugins_link_dir)
|
||||||
|
|
||||||
|
# See if the link_dir already exists.
|
||||||
|
if os.path.lexists(link_dir):
|
||||||
|
# if this isn't a symlink, there's something wrong... error out.
|
||||||
|
if not os.path.islink(link_dir):
|
||||||
|
printer(_('Could not link "%s": %s exists and is not a symlink') % (
|
||||||
|
link_dir))
|
||||||
|
return
|
||||||
|
|
||||||
|
# if this is a symlink and the path already exists, skip it.
|
||||||
|
if os.path.realpath(link_dir) == plugin_static.file_path:
|
||||||
|
# Is this comment helpful or not?
|
||||||
|
printer(_('Skipping "%s"; already set up.') % (
|
||||||
|
plugin_static.name))
|
||||||
|
return
|
||||||
|
|
||||||
|
# Otherwise, it's a link that went to something else... unlink it
|
||||||
|
printer(_('Old link found for "%s"; removing.') % (
|
||||||
|
plugin_static.name))
|
||||||
|
os.unlink(link_dir)
|
||||||
|
|
||||||
|
os.symlink(
|
||||||
|
plugin_static.file_path.rstrip(os.path.sep),
|
||||||
|
link_dir)
|
||||||
|
printer('Linked asset directory for plugin "%s":\n %s\nto:\n %s\n' % (
|
||||||
|
plugin_static.name,
|
||||||
|
plugin_static.file_path.rstrip(os.path.sep),
|
||||||
|
link_dir))
|
||||||
|
|
||||||
|
|
||||||
def install_theme(install_dir, themefile):
|
def install_theme(install_dir, themefile):
|
||||||
pass # TODO ;)
|
pass # TODO ;)
|
||||||
|
|
||||||
@ -101,7 +146,18 @@ def assetlink_command(args):
|
|||||||
"""
|
"""
|
||||||
global_config, app_config = setup_global_and_app_config(args.conf_file)
|
global_config, app_config = setup_global_and_app_config(args.conf_file)
|
||||||
theme_registry, current_theme = register_themes(app_config)
|
theme_registry, current_theme = register_themes(app_config)
|
||||||
link_assets(current_theme, app_config['theme_linked_assets_dir'])
|
|
||||||
|
# link theme
|
||||||
|
link_theme_assets(current_theme, app_config['theme_linked_assets_dir'])
|
||||||
|
|
||||||
|
# Set up the app specifically so we can access the plugin infrastructure
|
||||||
|
commands_util.setup_app(args)
|
||||||
|
|
||||||
|
# link plugin assets
|
||||||
|
## ... probably for this we need the whole application initialized
|
||||||
|
for plugin_static in pluginapi.hook_runall("static_setup"):
|
||||||
|
link_plugin_assets(
|
||||||
|
plugin_static, app_config['plugin_linked_assets_dir'])
|
||||||
|
|
||||||
|
|
||||||
def install_command(args):
|
def install_command(args):
|
||||||
|
@ -24,7 +24,7 @@ from mediagoblin import mg_globals
|
|||||||
from mediagoblin.mg_globals import setup_globals
|
from mediagoblin.mg_globals import setup_globals
|
||||||
from mediagoblin.db.open import setup_connection_and_db_from_config, \
|
from mediagoblin.db.open import setup_connection_and_db_from_config, \
|
||||||
check_db_migrations_current, load_models
|
check_db_migrations_current, load_models
|
||||||
from mediagoblin.pluginapi import hook_runall
|
from mediagoblin.tools.pluginapi import hook_runall
|
||||||
from mediagoblin.tools.workbench import WorkbenchManager
|
from mediagoblin.tools.workbench import WorkbenchManager
|
||||||
from mediagoblin.storage import storage_system_from_config
|
from mediagoblin.storage import storage_system_from_config
|
||||||
|
|
||||||
|
@ -56,6 +56,11 @@ use = egg:Paste#static
|
|||||||
document_root = %(here)s/user_dev/theme_static/
|
document_root = %(here)s/user_dev/theme_static/
|
||||||
cache_max_age = 86400
|
cache_max_age = 86400
|
||||||
|
|
||||||
|
[app:plugin_static]
|
||||||
|
use = egg:Paste#static
|
||||||
|
document_root = %(here)s/user_dev/plugin_static/
|
||||||
|
cache_max_age = 86400
|
||||||
|
|
||||||
[filter:errors]
|
[filter:errors]
|
||||||
use = egg:mediagoblin#errors
|
use = egg:mediagoblin#errors
|
||||||
debug = false
|
debug = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user