Byron Clark committed 3858c7d

Allow the user to specify which filter files to use.

Comments (0)

Files changed (2)

     def _load_filters_from_config_files(self, config_files):
         filters = Filters()
+        self.log.debug('loading filters from %s' % (config_files,))
         parser = SafeConfigParser()
 import logging
 import optparse
+import os
 import dbus
 import gobject
 import gio
 import pynotify
+import xdg.BaseDirectory
 import udiskie.device
 import udiskie.match
 class AutoMounter:
-    def __init__(self, bus=None):
+    CONFIG_PATH = 'udiskie/filters.conf'
+    def __init__(self, bus=None, filter_files=None):
         self.log = logging.getLogger('udiskie.mount.AutoMounter')
-        self.filters = udiskie.match.FilterMatcher(('filters.conf',))
         self.last_device_state = {}
         if not bus:
             self.bus = bus
+        if not filter_files:
+            base_paths = xdg.BaseDirectory.xdg_config_dirs
+            filter_files = [os.path.join(D, self.CONFIG_PATH) for D in base_paths]
+        self.filters = udiskie.match.FilterMatcher(filter_files)
     parser.add_option('-v', '--verbose', action='store_true',
                       dest='verbose', default=False,
                       help='verbose output')
+    parser.add_option('-f', '--filters', action='store',
+                      dest='filters', default=None,
+                      metavar='FILE', help='filter FILE')
     (options, args) = parser.parse_args(args)
     log_level = logging.INFO
-    mounter = AutoMounter()
+    mounter = AutoMounter(bus=None, filter_files=options.filters)
     return gobject.MainLoop().run()
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
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.