aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/gmg_commands/theme.py
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2012-07-13 16:08:31 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2012-07-14 12:55:14 -0500
commit8a22617ffeebfdce610dac7127d57e0721d3516e (patch)
tree183b43650677e3f5ce13852bf39b616ea9982641 /mediagoblin/gmg_commands/theme.py
parent111a97524a298c55b6d93e6cbcf6914b9e2d7b23 (diff)
downloadmediagoblin-8a22617ffeebfdce610dac7127d57e0721d3516e.tar.lz
mediagoblin-8a22617ffeebfdce610dac7127d57e0721d3516e.tar.xz
mediagoblin-8a22617ffeebfdce610dac7127d57e0721d3516e.zip
asset linking command now works
Diffstat (limited to 'mediagoblin/gmg_commands/theme.py')
-rw-r--r--mediagoblin/gmg_commands/theme.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/mediagoblin/gmg_commands/theme.py b/mediagoblin/gmg_commands/theme.py
index d00ed6eb..a55a880c 100644
--- a/mediagoblin/gmg_commands/theme.py
+++ b/mediagoblin/gmg_commands/theme.py
@@ -57,20 +57,39 @@ def assetlink(args):
"""
global_config, app_config = setup_global_and_app_config(args.conf_file)
theme_registry, current_theme = register_themes(app_config)
+ link_dir = app_config['theme_linked_assets_dir'].rstrip(os.path.sep)
+ link_parent_dir = os.path.split(link_dir.rstrip(os.path.sep))[0]
if current_theme is None:
print "Cannot link theme... no theme set"
return
- link_dir = app_config['theme_linked_assets_dir']
+ def _maybe_unlink_link_dir():
+ """unlink link directory if it exists"""
+ if os.path.lexists(link_dir) \
+ and os.path.islink(link_dir):
+ os.unlink(link_dir)
+ return True
- # Remove existing symlink if it exists
- if os.path.exists(link_dir):
- # make sure it's a symlink though
- assert os.path.islink(link_dir)
- os.unlink(link_dir)
+ return False
- os.symlink(current_theme['assets_dir'].rstrip('/'), link_dir.rstrip('/'))
+ if current_theme.get('assets_dir') is None:
+ print "No asset directory for this theme"
+ if _maybe_unlink_link_dir():
+ print "However, old link directory symlink found; removed."
+ return
+
+ _maybe_unlink_link_dir()
+
+ # make the link directory parent dirs if necessary
+ if not os.path.lexists(link_parent_dir):
+ os.makedirs(link_parent_dir)
+
+ os.symlink(
+ current_theme['assets_dir'].rstrip(os.path.sep),
+ link_dir)
+ print "Linked the theme's asset directory:\n %s\nto:\n %s" % (
+ current_theme['assets_dir'], link_dir)
SUBCOMMANDS = {