Mercurial > piecrust2
comparison piecrust/commands/builtin/themes.py @ 480:d5885c6d64bd
themes: Add a `link` sub-command to install a theme via a symbolic link.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 20 Jul 2015 22:56:45 -0700 |
parents | c5df200354e8 |
children | a00750896316 |
comparison
equal
deleted
inserted
replaced
479:3b6cbadd0c64 | 480:d5885c6d64bd |
---|---|
37 | 37 |
38 p = subparsers.add_parser( | 38 p = subparsers.add_parser( |
39 'override', | 39 'override', |
40 help="Copies a theme to the website for customization.") | 40 help="Copies a theme to the website for customization.") |
41 p.set_defaults(sub_func=self._overrideTheme) | 41 p.set_defaults(sub_func=self._overrideTheme) |
42 | |
43 p = subparsers.add_parser( | |
44 'link', | |
45 help="Installs a theme as a link to an already existing " | |
46 "theme on disk.") | |
47 p.add_argument( | |
48 'theme_dir', | |
49 help="The directory of the theme to link.") | |
50 p.set_defaults(sub_func=self._linkTheme) | |
42 | 51 |
43 def checkedRun(self, ctx): | 52 def checkedRun(self, ctx): |
44 if not hasattr(ctx.args, 'sub_func'): | 53 if not hasattr(ctx.args, 'sub_func'): |
45 ctx.parser.parse_args(['themes', '--help']) | 54 ctx.parser.parse_args(['themes', '--help']) |
46 return | 55 return |
129 logger.info(os.path.relpath(c[1], app_dir)) | 138 logger.info(os.path.relpath(c[1], app_dir)) |
130 if not os.path.exists(os.path.dirname(c[1])): | 139 if not os.path.exists(os.path.dirname(c[1])): |
131 os.makedirs(os.path.dirname(c[1])) | 140 os.makedirs(os.path.dirname(c[1])) |
132 shutil.copy2(c[0], c[1]) | 141 shutil.copy2(c[0], c[1]) |
133 | 142 |
143 def _linkTheme(self, ctx): | |
144 if not os.path.isdir(ctx.args.theme_dir): | |
145 logger.error("Invalid theme directory: %s" % ctx.args.theme_dir) | |
146 return 1 | |
147 | |
148 theme_dir = os.path.join(ctx.app.root_dir, THEME_DIR) | |
149 | |
150 if os.path.islink(theme_dir): | |
151 logger.debug("Unlinking: %s" % theme_dir) | |
152 os.unlink(theme_dir) | |
153 elif os.path.isdir(theme_dir): | |
154 logger.warning("A theme already exists, and will be overwritten. " | |
155 "Are you sure? [Y/n]") | |
156 ans = input() | |
157 if len(ans) > 0 and ans.lower() not in ['y', 'yes']: | |
158 return 1 | |
159 | |
160 shutil.rmtree(theme_dir) | |
161 | |
162 os.symlink(ctx.args.theme_dir, theme_dir) | |
163 |