prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Paths dropdown missing some parent dirs
  if a dir contains only directories, not any active stores its not shown in menu (on master)
  
  </issue>
  <code>
  [start of pootle/core/paths.py]
  1 # -*- coding: utf-8 -*-
  2 #
  3 # Copyright (C) Pootle contributors.
  4 #
  5 # This file is a part of the Pootle project. It is distributed under the GPL3
  6 # or later license. See the LICENSE file for a copy of the license and the
  7 # AUTHORS file for copyright and authorship information.
  8 
  9 import posixpath
  10 
  11 from pootle.core.decorators import persistent_property
  12 from pootle.core.delegate import revision
  13 
  14 
  15 class Paths(object):
  16 
  17     def __init__(self, context, q, show_all=False):
  18         self.context = context
  19         self.q = q
  20         self.show_all = show_all
  21 
  22     @property
  23     def rev_cache_key(self):
  24         return revision.get(
  25             self.context.directory.__class__)(
  26                 self.context.directory).get(key="stats")
  27 
  28     @property
  29     def cache_key(self):
  30         return (
  31             "%s.%s.%s"
  32             % (self.q,
  33                self.rev_cache_key,
  34                self.show_all))
  35 
  36     @property
  37     def store_qs(self):
  38         raise NotImplementedError
  39 
  40     @property
  41     def stores(self):
  42         stores = self.store_qs.exclude(obsolete=True)
  43         if not self.show_all:
  44             stores = stores.exclude(
  45                 translation_project__project__disabled=True)
  46         return stores.exclude(is_template=True).filter(
  47             tp_path__contains=self.q).order_by()
  48 
  49     @persistent_property
  50     def paths(self):
  51         stores = set(
  52             st[1:]
  53             for st
  54             in self.stores.values_list("tp_path", flat=True))
  55         dirs = set(
  56             ("%s/" % posixpath.dirname(path))
  57             for path
  58             in stores
  59             if (path.count("/") > 1
  60                 and self.q in path))
  61         return sorted(
  62             dirs | stores,
  63             key=lambda path: (posixpath.dirname(path), posixpath.basename(path)))
  64
  [end of pootle/core/paths.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pootle/core/paths.py b/pootle/core/paths.py
  --- a/pootle/core/paths.py
  +++ b/pootle/core/paths.py
  @@ -6,7 +6,11 @@
   # or later license. See the LICENSE file for a copy of the license and the
   # AUTHORS file for copyright and authorship information.
   
  +import pathlib
   import posixpath
  +from hashlib import md5
  +
  +from django.utils.encoding import force_bytes
   
   from pootle.core.decorators import persistent_property
   from pootle.core.delegate import revision
  @@ -29,7 +33,7 @@
       def cache_key(self):
           return (
               "%s.%s.%s"
  -            % (self.q,
  +            % (md5(force_bytes(self.q)).hexdigest(),
                  self.rev_cache_key,
                  self.show_all))
   
  @@ -52,12 +56,17 @@
               st[1:]
               for st
               in self.stores.values_list("tp_path", flat=True))
  -        dirs = set(
  -            ("%s/" % posixpath.dirname(path))
  -            for path
  -            in stores
  -            if (path.count("/") > 1
  -                and self.q in path))
  +        dirs = set()
  +        for store in stores:
  +            if posixpath.dirname(store) in dirs:
  +                continue
  +            dirs = (
  +                dirs
  +                | (set(
  +                    "%s/" % str(p)
  +                    for p
  +                    in pathlib.PosixPath(store).parents
  +                    if str(p) != ".")))
           return sorted(
               dirs | stores,
               key=lambda path: (posixpath.dirname(path), posixpath.basename(path)))
  
verification_info: {"golden_diff": "diff --git a/pootle/core/paths.py b/pootle/core/paths.py\n--- a/pootle/core/paths.py\n+++ b/pootle/core/paths.py\n@@ -6,7 +6,11 @@\n # or later license. See the LICENSE file for a copy of the license and the\n # AUTHORS file for copyright and authorship information.\n \n+import pathlib\n import posixpath\n+from hashlib import md5\n+\n+from django.utils.encoding import force_bytes\n \n from pootle.core.decorators import persistent_property\n from pootle.core.delegate import revision\n@@ -29,7 +33,7 @@\n     def cache_key(self):\n         return (\n             \"%s.%s.%s\"\n-            % (self.q,\n+            % (md5(force_bytes(self.q)).hexdigest(),\n                self.rev_cache_key,\n                self.show_all))\n \n@@ -52,12 +56,17 @@\n             st[1:]\n             for st\n             in self.stores.values_list(\"tp_path\", flat=True))\n-        dirs = set(\n-            (\"%s/\" % posixpath.dirname(path))\n-            for path\n-            in stores\n-            if (path.count(\"/\") > 1\n-                and self.q in path))\n+        dirs = set()\n+        for store in stores:\n+            if posixpath.dirname(store) in dirs:\n+                continue\n+            dirs = (\n+                dirs\n+                | (set(\n+                    \"%s/\" % str(p)\n+                    for p\n+                    in pathlib.PosixPath(store).parents\n+                    if str(p) != \".\")))\n         return sorted(\n             dirs | stores,\n             key=lambda path: (posixpath.dirname(path), posixpath.basename(path)))\n", "issue": "Paths dropdown missing some parent dirs\nif a dir contains only directories, not any active stores its not shown in menu (on master)\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nimport posixpath\n\nfrom pootle.core.decorators import persistent_property\nfrom pootle.core.delegate import revision\n\n\nclass Paths(object):\n\n    def __init__(self, context, q, show_all=False):\n        self.context = context\n        self.q = q\n        self.show_all = show_all\n\n    @property\n    def rev_cache_key(self):\n        return revision.get(\n            self.context.directory.__class__)(\n                self.context.directory).get(key=\"stats\")\n\n    @property\n    def cache_key(self):\n        return (\n            \"%s.%s.%s\"\n            % (self.q,\n               self.rev_cache_key,\n               self.show_all))\n\n    @property\n    def store_qs(self):\n        raise NotImplementedError\n\n    @property\n    def stores(self):\n        stores = self.store_qs.exclude(obsolete=True)\n        if not self.show_all:\n            stores = stores.exclude(\n                translation_project__project__disabled=True)\n        return stores.exclude(is_template=True).filter(\n            tp_path__contains=self.q).order_by()\n\n    @persistent_property\n    def paths(self):\n        stores = set(\n            st[1:]\n            for st\n            in self.stores.values_list(\"tp_path\", flat=True))\n        dirs = set(\n            (\"%s/\" % posixpath.dirname(path))\n            for path\n            in stores\n            if (path.count(\"/\") > 1\n                and self.q in path))\n        return sorted(\n            dirs | stores,\n            key=lambda path: (posixpath.dirname(path), posixpath.basename(path)))\n", "path": "pootle/core/paths.py"}]}