Mercurial > piecrust2
comparison piecrust/commands/builtin/themes.py @ 891:f13d618cfec6
themes: Allow keeping local overrides when copying a theme locally.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 02 Jul 2017 22:19:58 -0700 |
parents | 58ae026b4c31 |
children | 727110ea112a |
comparison
equal
deleted
inserted
replaced
890:f77f9dcba072 | 891:f13d618cfec6 |
---|---|
101 continue | 101 continue |
102 src_path = os.path.join(dirpath, name) | 102 src_path = os.path.join(dirpath, name) |
103 dst_path = os.path.join(app_dir, rel_dirpath, name) | 103 dst_path = os.path.join(app_dir, rel_dirpath, name) |
104 copies.append((src_path, dst_path)) | 104 copies.append((src_path, dst_path)) |
105 | 105 |
106 conflicts = [] | 106 conflicts = set() |
107 for c in copies: | 107 for c in copies: |
108 if os.path.exists(c[1]): | 108 if os.path.exists(c[1]): |
109 conflicts.append(c[1]) | 109 conflicts.add(c[1]) |
110 if conflicts: | 110 if conflicts: |
111 logger.warning("Some website files will be overwritten:") | 111 logger.warning("Some website files override theme files:") |
112 for c in conflicts: | 112 for c in conflicts: |
113 logger.warning(os.path.relpath(c, app_dir)) | 113 logger.warning(os.path.relpath(c, app_dir)) |
114 logger.warning("Are you sure? [Y/n]") | 114 logger.warning("") |
115 ans = input() | 115 logger.warning("The local website files will be preserved, and " |
116 if len(ans) > 0 and ans.lower() not in ['y', 'yes']: | 116 "the conflicting theme files won't be copied " |
117 return 1 | 117 "locally.") |
118 | 118 |
119 for c in copies: | 119 for c in copies: |
120 logger.info(os.path.relpath(c[1], app_dir)) | 120 if not c[1] in conflicts: |
121 if not os.path.exists(os.path.dirname(c[1])): | 121 logger.info(os.path.relpath(c[1], app_dir)) |
122 os.makedirs(os.path.dirname(c[1])) | 122 os.makedirs(os.path.dirname(c[1]), exist_ok=True) |
123 shutil.copy2(c[0], c[1]) | 123 shutil.copy2(c[0], c[1]) |
124 | 124 |
125 def _linkTheme(self, ctx): | 125 def _linkTheme(self, ctx): |
126 if not os.path.isdir(ctx.args.theme_dir): | 126 if not os.path.isdir(ctx.args.theme_dir): |
127 logger.error("Invalid theme directory: %s" % ctx.args.theme_dir) | 127 logger.error("Invalid theme directory: %s" % ctx.args.theme_dir) |
128 return 1 | 128 return 1 |