Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid creating empty colorbox-i18n directory
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jun 3, 2017
1 parent f45bafb commit 94379b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 9 additions & 1 deletion nikola/plugins/task/copy_assets.py
Expand Up @@ -80,11 +80,19 @@ def gen_tasks(self):
if ignore_colorbox_i18n == "unused":
# Check what colorbox languages we need so we can ignore the rest
needed_colorbox_languages = [LEGAL_VALUES['COLORBOX_LOCALES'][i] for i in kw['translations']]
needed_colorbox_languages = [i for i in needed_colorbox_languages if i] # remove '' for en
# ignored_filenames is passed to copy_tree to avoid creating
# directories. Since ignored_assets are full paths, and copy_tree
# works on single filenames, we can’t use that here.
if not needed_colorbox_languages:
ignored_filenames = set(["colorbox-i18n"])
else:
ignored_filenames = set()

for theme_name in kw['themes']:
src = os.path.join(utils.get_theme_path(theme_name), 'assets')
dst = os.path.join(kw['output_folder'], 'assets')
for task in utils.copy_tree(src, dst):
for task in utils.copy_tree(src, dst, ignored_filenames=ignored_filenames):
asset_name = os.path.relpath(task['name'], dst)
if task['name'] in tasks or asset_name in ignored_assets:
continue
Expand Down
8 changes: 5 additions & 3 deletions nikola/utils.py
Expand Up @@ -738,7 +738,7 @@ def load_messages(themes, translations, default_lang, themes_dirs):
return messages


def copy_tree(src, dst, link_cutoff=None):
def copy_tree(src, dst, link_cutoff=None, ignored_filenames=None):
"""Copy a src tree to the dst folder.
Example:
Expand All @@ -749,11 +749,13 @@ def copy_tree(src, dst, link_cutoff=None):
should copy "themes/defauts/assets/foo/bar" to
"output/assets/foo/bar"
if link_cutoff is set, then the links pointing at things
If link_cutoff is set, then the links pointing at things
*inside* that folder will stay as links, and links
pointing *outside* that folder will be copied.
ignored_filenames is a set of file names that will be ignored.
"""
ignore = set(['.svn'])
ignore = set(['.svn', '.git']) | (ignored_filenames or set())
base_len = len(src.split(os.sep))
for root, dirs, files in os.walk(src, followlinks=True):
root_parts = root.split(os.sep)
Expand Down

0 comments on commit 94379b9

Please sign in to comment.