Repository: getnikola/nikola

Issue:
Galleries are broken if no translation ends up in site root
Yep, me again :P
Does this make sense to you?

```
nikola | /h/@/P/g/msx.github.io ‹master*›> nikola build; nikola deploy; nikola github_deploy
Scanning posts....done!
.  render_galleries:output/en/galleries/demo/index.html
########################################
TaskError - taskid:render_galleries:output/en/galleries/demo/index.html
PythonAction Error
Traceback (most recent call last):
  File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/doit/action.py", line 372, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/nikola/plugins/task/galleries.py", line 533, in render_gallery_index
    im = Image.open(thumb)
  File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/PIL/Image.py", line 2248, in open
    fp = builtins.open(fp, "rb")
IOError: [Errno 2] No such file or directory: u'output/galleries/demo/tesla4_lg.thumbnail.jpg'



Scanning posts....done!
[2015-05-16T07:25:21Z] INFO: deploy: => preset 'default'
[2015-05-16T07:25:21Z] INFO: deploy: Successful deployment
Scanning posts....done!
.  render_galleries:output/en/galleries/demo/index.html
########################################
TaskError - taskid:render_galleries:output/en/galleries/demo/index.html
PythonAction Error
Traceback (most recent call last):
  File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/doit/action.py", line 372, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/nikola/plugins/task/galleries.py", line 533, in render_gallery_index
    im = Image.open(thumb)
  File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/PIL/Image.py", line 2248, in open
    fp = builtins.open(fp, "rb")
IOError: [Errno 2] No such file or directory: u'output/galleries/demo/tesla4_lg.thumbnail.jpg'



[2015-05-16T07:25:23Z] ERROR: github_deploy: Build failed, not deploying to GitHub
```

Following your advice I edited _/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/nikola/plugins/command/github_deploy.py_ to match the fix:

```
        # Clean non-target files
        # only_on_output, _ = real_scan_files(self.site)
        l = self._doitargs['cmds'].get_plugin('list')(config=self.config, **self._doitargs)
        only_on_output, _ = real_scan_files(l, self.site)
        for f in only_on_output:
            os.unlink(f)
```



Discussion:
This is the problem:

``` py
TRANSLATIONS = {
    DEFAULT_LANG: "en",
                   ^^
```

We expect at least one translation to end up in the site root — that is, an empty string as one of the values in `TRANSLATIONS`.  In order not to duplicate files, they end up in `DEFAULT_LANG`’s site; however, while resizing them, we don’t use `DEFAULT_LANG` to build the path.  Should not be hard to fix; in the meantime, you may want to make that an empty string — especially if you do not want any translations.

Also: why do you use `nikola deploy`?  It currently does nothing — you did not configure any `DEPLOY_COMMANDS`.

@ralsina, should we work further on making this scenario feasible or not?  There are probably other things that depend on this.  Some people might not want to pick a “default” language and instead put a language picker on the site root.

Yes, I thought about `DEFAULT_LANG` and was about to post back but you did it first :)
About `nikola deploy`, I'm just learning my way around Nikola, thanks for the heads up.
Cheers.


Resolving patch:
diff --git a/nikola/plugins/task/galleries.py b/nikola/plugins/task/galleries.py
--- a/nikola/plugins/task/galleries.py
+++ b/nikola/plugins/task/galleries.py
@@ -66,6 +66,7 @@ class Galleries(Task, ImageProcessor):
 
     def set_site(self, site):
         site.register_path_handler('gallery', self.gallery_path)
+        site.register_path_handler('gallery_global', self.gallery_global_path)
         site.register_path_handler('gallery_rss', self.gallery_rss_path)
 
         self.logger = utils.get_logger('render_galleries', site.loghandlers)
@@ -126,6 +127,11 @@ def gallery_path(self, name, lang):
                 list(os.path.split(gallery_path)) +
                 [self.site.config['INDEX_FILE']] if _f]
 
+    def gallery_global_path(self, name, lang):
+        gallery_path = self._find_gallery_path(name)
+        return [_f for _f in list(os.path.split(gallery_path)) +
+                [self.site.config['INDEX_FILE']] if _f]
+
     def gallery_rss_path(self, name, lang):
         gallery_path = self._find_gallery_path(name)
         return [_f for _f in [self.site.config['TRANSLATIONS'][lang]] +
@@ -429,7 +435,7 @@ def create_target_images(self, img, input_path):
         output_gallery = os.path.dirname(
             os.path.join(
                 self.kw["output_folder"],
-                self.site.path("gallery", gallery_name)))
+                self.site.path("gallery_global", gallery_name)))
         # Do thumbnails and copy originals
         # img is "galleries/name/image_name.jpg"
         # img_name is "image_name.jpg"
@@ -481,7 +487,7 @@ def remove_excluded_image(self, img, input_folder):
         output_folder = os.path.dirname(
             os.path.join(
                 self.kw["output_folder"],
-                self.site.path("gallery", os.path.dirname(img))))
+                self.site.path("gallery_global", os.path.dirname(img))))
         img = os.path.relpath(img, input_folder)
         img_path = os.path.join(output_folder, os.path.basename(img))
         fname, ext = os.path.splitext(img_path)


Test patch: