Thomas Gläßle avatar Thomas Gläßle committed 680fe30

Relocate system bus connection

Comments (0)

Files changed (2)

udiskie/common.py

 """
 Common utilities.
 """
-__all__ = ['Properties', 'system_bus']
+__all__ = ['Properties']
 import dbus
 
 
         """Retrieve the property via the dbus proxy."""
         return self.__proxy.Get(self.__interface, property)
 
-def system_bus():
-    """
-    Connect to system bus.
-
-    When called for the first time, dbus will be initialized to use a glib
-    mainloop.
-
-    """
-    if not system_bus.initialized:
-        from dbus.mainloop.glib import DBusGMainLoop
-        DBusGMainLoop(set_as_default=True)
-        system_bus.initialized = True
-    return dbus.SystemBus()
-system_bus.initialized = False
-
 import udiskie.automount
 import udiskie.daemon
 
-from udiskie.common import system_bus
-
-
 class Mounter:
     CONFIG_PATH = 'udiskie/filters.conf'
 
     parser = option_parser()
     options, posargs = parser.parse_args(args)
     logging.basicConfig(level=options.log_level, format='%(message)s')
+    run_daemon = allow_daemon and not options.all and len(posargs) == 0
 
     # establish connection to system bus
-    bus = system_bus()
+    if run_daemon:
+        from dbus.mainloop.glib import DBusGMainLoop
+        DBusGMainLoop(set_as_default=True)
+    bus = dbus.SystemBus()
 
     # create a mounter
     prompt = udiskie.prompt.password(options.password_prompt)
     mounter = Mounter(bus=bus, filter_file=options.filters, prompt=prompt)
 
     # run udiskie daemon if needed
-    run_daemon = allow_daemon and not options.all and len(posargs) == 0
     if run_daemon:
         daemon = udiskie.daemon.Daemon(bus)
-
     if run_daemon and not options.suppress_notify:
         notify = udiskie.notify.Notify('udiskie.mount')
         notify.connect(daemon)
-
     if run_daemon:
         automount = udiskie.automount.AutoMounter(mounter)
         automount.connect(daemon)
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.