Oben Sonne avatar Oben Sonne committed 23d3ef4

Update item filter handling

Comments (0)

Files changed (1)

 def _exit(ec):
     """Exit with additional check if autostart file is still needed."""
     
-    _autostart(_get_items())
+    _autostart(_get_items(amount="y"))
     sys.exit(ec)
 
 def _proceed(msg):
 
 _items_cached = None
 
-def _get_items(mpoint=None, any=None):
-    """Get EncFS items where EncFS path or mount point equals 'path'."""
+def _get_items(mpoint=None, epath=None, anypath=None, amount=None):
+    """Get all EncFS items or those matching given attributes."""
     
     global _items_cached
     
         except gk.NoMatchError:
             _items_cached = []
     
-    return [i for i in _items_cached if
-                not (mpoint or any) or
-                mpoint and i.attributes["mount-point"] == mpoint or
-                (any and (i.attributes["encfs-path"] == any or
-                          i.attributes["mount-point"] == any))]
+    match = []
+    for item in _items_cached:
+        if mpoint and item.attributes["mount-point"] != mpoint:
+            continue
+        if epath and item.attributes["encfs-path"] != epath:
+            continue
+        if anypath and (item.attributes["mount-point"] != anypath and
+                        item.attributes["encfs-path"] != anypath):
+            continue
+        if amount and item.attributes["auto-mount"] != amount:
+            continue
+        match.append(item)
+    
+    return match
 
 def _autostart(enable):
     """Set up XDG autostart file."""
     return True
 
 def mount_items(path, autostart):
-    """Mount all items where the EncFS path or mount point equals 'path'."""
-
-    items = _get_items(any=path)
+    """Mount selected items.
+    
+    If `path` is set, mount only those items where the EncFS path or mount
+    point equals `path`. If `autostart` is True, mount only those items where
+    auto-mount is set to 'y'.
+    
+    """
+    items = _get_items(anypath=path, amount=(autostart and "y" or None))
 
     if not items:
         print(MSG_NO_MATCH)
         return False
     
-    if autostart:
-        items = [i for i in items if i.attributes["auto-mount"] == "y"]
-    
     for item in items:
         epath = item.attributes["encfs-path"]
         mpoint = item.attributes["mount-point"]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.