annotate piecrust/commands/builtin/themes.py @ 868:8d25f76fce98

bake: Add ability to specify pipelines to exclude during the bake.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 12 Jun 2017 22:22:19 -0700
parents 549e21789ad9
children 58ae026b4c31
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
273
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os.path
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import shutil
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import logging
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 import yaml
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 from piecrust import (
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 RESOURCES_DIR, THEME_DIR, THEME_CONFIG_PATH, THEME_INFO_PATH)
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 from piecrust.commands.base import ChefCommand
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
9 from piecrust.pathutil import SiteNotFoundError
273
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 logger = logging.getLogger(__name__)
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 class ThemesCommand(ChefCommand):
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 def __init__(self):
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 super(ThemesCommand, self).__init__()
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 self.name = 'themes'
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 self.description = "Manage the themes for the current website."
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 def setupParser(self, parser, app):
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 subparsers = parser.add_subparsers()
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 p = subparsers.add_parser(
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
24 'info',
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
25 help="Provides information about the current theme.")
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
26 p.set_defaults(sub_func=self._info)
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
27
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
28 p = subparsers.add_parser(
273
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 'override',
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
30 help="Copies the current theme to the website for "
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
31 "customization.")
273
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 p.set_defaults(sub_func=self._overrideTheme)
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33
480
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
34 p = subparsers.add_parser(
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
35 'link',
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
36 help="Makes a given theme the active one for the current "
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
37 "website by creating a symbolic link to it from the "
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
38 "'theme' directory.")
480
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
39 p.add_argument(
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
40 'theme_dir',
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
41 help="The directory of the theme to link.")
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
42 p.set_defaults(sub_func=self._linkTheme)
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
43
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
44 p = subparsers.add_parser(
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
45 'unlink',
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
46 help="Removes the currently active theme for the website. "
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
47 "This removes the symbolic link to the theme, if any, or "
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
48 "deletes the theme folder if it was copied locally.")
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
49 p.set_defaults(sub_func=self._unlinkTheme)
480
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
50
273
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 def checkedRun(self, ctx):
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
52 if ctx.app.root_dir is None:
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
53 raise SiteNotFoundError(theme=ctx.app.theme_site)
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
54
475
c5df200354e8 themes: Fix crash when invoking command with no sub-command.
Ludovic Chabant <ludovic@chabant.com>
parents: 273
diff changeset
55 if not hasattr(ctx.args, 'sub_func'):
765
549e21789ad9 themes: No parameters shoudl make the help text show up.
Ludovic Chabant <ludovic@chabant.com>
parents: 747
diff changeset
56 ctx.parser.parse_args(['themes', '--help'])
549e21789ad9 themes: No parameters shoudl make the help text show up.
Ludovic Chabant <ludovic@chabant.com>
parents: 747
diff changeset
57 return
273
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 ctx.args.sub_func(ctx)
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
60 def _info(self, ctx):
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
61 theme_dir = ctx.app.theme_dir
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
62 if not os.path.exists(theme_dir):
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
63 logger.info("Using default theme, from: %s" % ctx.app.theme_dir)
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
64 elif theme_dir.startswith(ctx.app.root_dir):
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
65 if os.path.islink(theme_dir):
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
66 target = os.readlink(theme_dir)
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
67 target = os.path.join(os.path.dirname(theme_dir), target)
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
68 logger.info("Using local theme, from: %s" % target)
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
69 else:
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
70 logger.info("Using local theme.")
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
71 else:
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
72 logger.info("Using theme from: %s" % theme_dir)
273
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
74 info_path = os.path.join(theme_dir, THEME_CONFIG_PATH)
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
75 if os.path.exists(info_path):
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
76 info = None
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
77 with open(info_path, 'r', encoding='utf8') as fp:
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
78 theme_cfg = yaml.load(fp.read())
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
79 if isinstance(theme_cfg, dict):
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
80 info = theme_cfg.get('theme')
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
81 if info:
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
82 logger.info("Theme info:")
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
83 for k, v in info.items():
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
84 logger.info(" - %s: %s" % (str(k), str(v)))
273
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 def _overrideTheme(self, ctx):
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 theme_dir = ctx.app.theme_dir
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 if not theme_dir:
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
89 logger.error("There is no theme currently applied.")
273
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 return 1
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 copies = []
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
93 app_dir = ctx.app.root_dir
273
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 for dirpath, dirnames, filenames in os.walk(theme_dir):
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 rel_dirpath = os.path.relpath(dirpath, theme_dir)
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 for name in filenames:
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 if (dirpath == theme_dir and
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 name in [THEME_CONFIG_PATH, THEME_INFO_PATH]):
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 continue
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 src_path = os.path.join(dirpath, name)
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 dst_path = os.path.join(app_dir, rel_dirpath, name)
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 copies.append((src_path, dst_path))
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 conflicts = []
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 for c in copies:
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 if os.path.exists(c[1]):
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 conflicts.append(c[1])
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 if conflicts:
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 logger.warning("Some website files will be overwritten:")
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 for c in conflicts:
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 logger.warning(os.path.relpath(c, app_dir))
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 logger.warning("Are you sure? [Y/n]")
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 ans = input()
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 if len(ans) > 0 and ans.lower() not in ['y', 'yes']:
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 return 1
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117 for c in copies:
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 logger.info(os.path.relpath(c[1], app_dir))
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 if not os.path.exists(os.path.dirname(c[1])):
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 os.makedirs(os.path.dirname(c[1]))
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121 shutil.copy2(c[0], c[1])
d70a4adb61dd themes: Add the `chef themes` command
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
123 def _linkTheme(self, ctx):
480
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
124 if not os.path.isdir(ctx.args.theme_dir):
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
125 logger.error("Invalid theme directory: %s" % ctx.args.theme_dir)
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
126 return 1
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
127
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
128 msg = ("A theme already exists, and will be deleted. "
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
129 "Are you sure? [Y/n]")
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
130 self._doUnlinkTheme(ctx.app.root_dir, msg)
480
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
131
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
132 theme_dir = os.path.join(ctx.app.root_dir, THEME_DIR)
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
133 try:
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
134 os.symlink(ctx.args.theme_dir, theme_dir)
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
135 except (NotImplementedError, OSError) as ex:
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
136 if ctx.args.link_only:
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
137 logger.error("Couldn't symlink the theme: %s" % ex)
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
138 return 1
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
139
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
140 def _unlinkTheme(self, ctx):
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
141 msg = ("The active theme is local. Are you sure you want "
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
142 "to delete the theme directory? [Y/n]")
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
143 self._doUnlinkTheme(ctx.app.root_dir, msg)
480
d5885c6d64bd themes: Add a `link` sub-command to install a theme via a symbolic link.
Ludovic Chabant <ludovic@chabant.com>
parents: 475
diff changeset
144
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
145 def _doUnlinkTheme(self, root_dir, delete_message):
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
146 theme_dir = os.path.join(root_dir, THEME_DIR)
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
147
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
148 if os.path.islink(theme_dir):
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
149 logger.debug("Unlinking: %s" % theme_dir)
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
150 os.unlink(theme_dir)
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
151 return True
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
152
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
153 if os.path.isdir(theme_dir):
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
154 logger.warning(delete_message)
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
155 ans = input()
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
156 if len(ans) > 0 and ans.lower() not in ['y', 'yes']:
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
157 return 1
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
158
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
159 logger.debug("Deleting: %s" % theme_dir)
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
160 shutil.rmtree(theme_dir)
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
161
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
162 return True
488
a00750896316 themes: Improve CLI, add `deactivate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 480
diff changeset
163
747
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
164 return False
5336e146ac8d themes: Simplify `themes` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 488
diff changeset
165