# HG changeset patch # User Ludovic Chabant # Date 1437458205 25200 # Node ID d5885c6d64bd98e22d1d27f4677570ddcaf632e2 # Parent 3b6cbadd0c64298c011fa76a61a925754bcbbd09 themes: Add a `link` sub-command to install a theme via a symbolic link. diff -r 3b6cbadd0c64 -r d5885c6d64bd piecrust/commands/builtin/themes.py --- a/piecrust/commands/builtin/themes.py Mon Jul 20 22:25:39 2015 -0700 +++ b/piecrust/commands/builtin/themes.py Mon Jul 20 22:56:45 2015 -0700 @@ -40,6 +40,15 @@ help="Copies a theme to the website for customization.") p.set_defaults(sub_func=self._overrideTheme) + p = subparsers.add_parser( + 'link', + help="Installs a theme as a link to an already existing " + "theme on disk.") + p.add_argument( + 'theme_dir', + help="The directory of the theme to link.") + p.set_defaults(sub_func=self._linkTheme) + def checkedRun(self, ctx): if not hasattr(ctx.args, 'sub_func'): ctx.parser.parse_args(['themes', '--help']) @@ -131,3 +140,24 @@ os.makedirs(os.path.dirname(c[1])) shutil.copy2(c[0], c[1]) + def _linkTheme(self, ctx): + if not os.path.isdir(ctx.args.theme_dir): + logger.error("Invalid theme directory: %s" % ctx.args.theme_dir) + return 1 + + theme_dir = os.path.join(ctx.app.root_dir, THEME_DIR) + + if os.path.islink(theme_dir): + logger.debug("Unlinking: %s" % theme_dir) + os.unlink(theme_dir) + elif os.path.isdir(theme_dir): + logger.warning("A theme already exists, and will be overwritten. " + "Are you sure? [Y/n]") + ans = input() + if len(ans) > 0 and ans.lower() not in ['y', 'yes']: + return 1 + + shutil.rmtree(theme_dir) + + os.symlink(ctx.args.theme_dir, theme_dir) +