def _connect_to_tomboy(self): if self.remoteTomboy != None: return True bus = dbus.SessionBus() if Utils.dbus_service_available(TomboyNoteTwoWay.TOMBOY_DBUS_IFACE, bus): obj = bus.get_object(TomboyNoteTwoWay.TOMBOY_DBUS_IFACE, TomboyNoteTwoWay.TOMBOY_DBUS_PATH) app = dbus.Interface(obj, "org.gnome.Tomboy.RemoteControl") version = tuple( int(item) for item in str(app.Version()).split('.')) if version >= TomboyNoteTwoWay.TOMBOY_MIN_VERSION: self.remoteTomboy = app self.remoteTomboy.connect_to_signal( "NoteAdded", lambda uid: self.handle_added(str(uid))) self.remoteTomboy.connect_to_signal( "NoteSaved", lambda uid: self.handle_modified(str(uid))) self.remoteTomboy.connect_to_signal( "NoteDeleted", lambda uid, x: self.handle_deleted(str(uid))) self.supportsCompleteXML = version >= TomboyNoteTwoWay.TOMBOY_COMPLETE_XML_VERSION log.info("Using Tomboy Version %s" % str(version)) return True return False
def _connect_to_fspot(self): bus = dbus.SessionBus() if Utils.dbus_service_available(FSpotDbusTwoWay.SERVICE_PATH, bus): #If the connection was broken and remade, the connection name changes #and the connection objects no longer works. #F-Spot restarting does exactly that, so we need to remake our objects. connection_name = bus.get_name_owner(FSpotDbusTwoWay.SERVICE_PATH) if self._connection_name != connection_name: self.photo_remote = None self.tag_remote = None self._connection_name = connection_name if self.photo_remote == None: try: remote_object = bus.get_object(FSpotDbusTwoWay.SERVICE_PATH, FSpotDbusTwoWay.PHOTOREMOTE_PATH) self.photo_remote = dbus.Interface(remote_object, FSpotDbusTwoWay.PHOTOREMOTE_IFACE) except dbus.exceptions.DBusException: print "*"*34 self.photo_remote = None if self.tag_remote == None: try: remote_object = bus.get_object(FSpotDbusTwoWay.SERVICE_PATH, FSpotDbusTwoWay.TAGREMOTE_PATH) self.tag_remote = dbus.Interface(remote_object, FSpotDbusTwoWay.TAGREMOTE_IFACE) except dbus.exceptions.DBusException: print "#"*34 self.tag_remote = None else: self.photo_remote = None self.tag_remote = None #need both tag and photo remote to be OK return self.tag_remote != None and self.photo_remote != None
def _connect_to_tomboy(self): if self.remoteTomboy != None: return True bus = dbus.SessionBus() if Utils.dbus_service_available(TomboyNoteTwoWay.TOMBOY_DBUS_IFACE, bus): obj = bus.get_object(TomboyNoteTwoWay.TOMBOY_DBUS_IFACE, TomboyNoteTwoWay.TOMBOY_DBUS_PATH) app = dbus.Interface(obj, "org.gnome.Tomboy.RemoteControl") version = tuple(int(item) for item in str(app.Version()).split('.')) if version >= TomboyNoteTwoWay.TOMBOY_MIN_VERSION: self.remoteTomboy = app self.remoteTomboy.connect_to_signal("NoteAdded", lambda uid: self.handle_added(str(uid))) self.remoteTomboy.connect_to_signal("NoteSaved", lambda uid: self.handle_modified(str(uid))) self.remoteTomboy.connect_to_signal("NoteDeleted", lambda uid, x: self.handle_deleted(str(uid))) self.supportsCompleteXML = version >= TomboyNoteTwoWay.TOMBOY_COMPLETE_XML_VERSION log.info("Using Tomboy Version %s" % str(version)) return True return False
def _connect_to_fspot(self): bus = dbus.SessionBus() if Utils.dbus_service_available(FSpotDbusTwoWay.SERVICE_PATH, bus): if self.photo_remote == None: try: remote_object = bus.get_object(FSpotDbusTwoWay.SERVICE_PATH, FSpotDbusTwoWay.PHOTOREMOTE_PATH) self.photo_remote = dbus.Interface(remote_object, FSpotDbusTwoWay.PHOTOREMOTE_IFACE) except dbus.exceptions.DBusException: print "*"*34 self.photo_remote = None if self.tag_remote == None: try: remote_object = bus.get_object(FSpotDbusTwoWay.SERVICE_PATH, FSpotDbusTwoWay.TAGREMOTE_PATH) self.tag_remote = dbus.Interface(remote_object, FSpotDbusTwoWay.TAGREMOTE_IFACE) except dbus.exceptions.DBusException: print "#"*34 self.tag_remote = None #need both tag and photo remote to be OK return self.tag_remote != None and self.photo_remote != None
def _connect_to_fspot(self): bus = dbus.SessionBus() if Utils.dbus_service_available(FSpotDbusTwoWay.SERVICE_PATH, bus): #If the connection was broken and remade, the connection name changes #and the connection objects no longer works. #F-Spot restarting does exactly that, so we need to remake our objects. connection_name = bus.get_name_owner(FSpotDbusTwoWay.SERVICE_PATH) if self._connection_name != connection_name: self.photo_remote = None self.tag_remote = None self._connection_name = connection_name if self.photo_remote == None: try: remote_object = bus.get_object( FSpotDbusTwoWay.SERVICE_PATH, FSpotDbusTwoWay.PHOTOREMOTE_PATH) self.photo_remote = dbus.Interface( remote_object, FSpotDbusTwoWay.PHOTOREMOTE_IFACE) except dbus.exceptions.DBusException: print "*" * 34 self.photo_remote = None if self.tag_remote == None: try: remote_object = bus.get_object( FSpotDbusTwoWay.SERVICE_PATH, FSpotDbusTwoWay.TAGREMOTE_PATH) self.tag_remote = dbus.Interface( remote_object, FSpotDbusTwoWay.TAGREMOTE_IFACE) except dbus.exceptions.DBusException: print "#" * 34 self.tag_remote = None else: self.photo_remote = None self.tag_remote = None #need both tag and photo remote to be OK return self.tag_remote != None and self.photo_remote != None
#Make a fake iPod so we dont damage a real one fakeIpodDir = os.path.join(os.environ['TEST_DIRECTORY'],"iPod") if not os.path.exists(fakeIpodDir): os.mkdir(fakeIpodDir) ok("Created fake ipod at %s" % fakeIpodDir, True) klass = iPodModule.IPodNoteTwoWay(fakeIpodDir,"") #setup the conduit sourceW = test.get_dataprovider("TomboyNoteTwoWay") sinkW = test.wrap_dataprovider(klass) test.prepare(sourceW, sinkW) test.set_two_way_policy({"conflict":"replace","deleted":"replace"}) #check if tomboy running tomboy = sourceW.module if not Utils.dbus_service_available(tomboy.TOMBOY_DBUS_IFACE): skip("tomboy not running") #check they refresh ok a,b = test.refresh() ok("Got all items to sync (%s,%s)" % (a,b), a > 0 and b == 0) #check they sync ok a,b = test.sync() aborted = test.sync_aborted() ok("Sync completed", aborted == False) ok("All notes transferred (%s,%s)" % (a,b), a == b) finished()
def __init__(self): """ Conduit application class Parses command line arguments. Sets up the views and models; restores application settings, shows the splash screen and the UI Notes: 1) If conduit is launched without --console switch then the gui and the console interfaces are started 2) If launched with --console and then later via the gui then set up the gui and connect all the appropriate signal handlers """ self.splash = None self.gui = None self.statusIcon = None self.dbus = None self.guiSyncSet = None self.dbusSyncSet = None self.uiLib = None gobject.set_application_name("Conduit") self.settingsFile = os.path.join(conduit.USER_DIR, "settings.xml") self.dbFile = os.path.join(conduit.USER_DIR, "mapping.db") # initialize application settings conduit.GLOBALS.settings = Settings() # command line parsing parser = optparse.OptionParser( prog="conduit", version="%%prog %s" % conduit.VERSION, description="Conduit is a synchronization application.", ) parser.add_option( "-c", "--console", dest="build_gui", action="store_false", default=True, help="Launch without GUI. [default: %default]", ) parser.add_option( "-f", "--config-file", metavar="FILE", default=self.settingsFile, help="Save dataprovider configuration to FILE. [default: %default]", ) parser.add_option( "-i", "--iconify", action="store_true", default=False, help="Iconify on startup. [default: %default]" ) parser.add_option( "-u", "--ui", metavar="NAME", default="gtk", help="Run with the specified UI. [default: %default]" ) parser.add_option( "-w", "--with-modules", metavar="mod1,mod2", help="Only load modules in the named files. [default: load all modules]", ) parser.add_option( "-x", "--without-modules", metavar="mod1,mod2", help="Do not load modules in the named files. [default: load all modules]", ) parser.add_option( "-s", "--settings", metavar="key=val,key=val", help="Explicitly set internal Conduit settings (keys) to the given values for this session. [default: do not set]", ) parser.add_option( "-U", "--enable-unsupported", action="store_true", default=False, help="Enable loading of unfinished or unsupported dataproviders. [default: %default]", ) options, args = parser.parse_args() whitelist = None blacklist = None settings = {} if options.settings: for i in options.settings.split(","): k, v = i.split("=") settings[k] = v if options.with_modules: whitelist = options.with_modules.split(",") if options.without_modules: blacklist = options.without_modules.split(",") self.ui = options.ui self.settingsFile = os.path.abspath(options.config_file) log.info("Conduit v%s Installed: %s" % (conduit.VERSION, conduit.IS_INSTALLED)) log.info("Python: %s" % sys.version) log.info( "Platform Implementations: %s,%s,%s" % (conduit.FILE_IMPL, conduit.BROWSER_IMPL, conduit.SETTINGS_IMPL) ) if settings: log.info("Settings have been overridden: %s" % settings) # Make conduit single instance. If conduit is already running then # make the original process build or show the gui sessionBus = dbus.SessionBus() if Utils.dbus_service_available(APPLICATION_DBUS_IFACE, sessionBus): log.info("Conduit is already running") obj = sessionBus.get_object(APPLICATION_DBUS_IFACE, "/activate") conduitApp = dbus.Interface(obj, APPLICATION_DBUS_IFACE) if options.build_gui: if conduitApp.HasGUI(): conduitApp.ShowGUI() else: conduitApp.ImportGUI() conduitApp.ShowSplash() conduitApp.ShowStatusIcon() conduitApp.BuildGUI() conduitApp.ShowGUI() conduitApp.HideSplash() sys.exit(0) # Initialise dbus stuff here as any earlier will interfere # with Conduit already running check. bus_name = dbus.service.BusName(APPLICATION_DBUS_IFACE, bus=sessionBus) dbus.service.Object.__init__(self, bus_name, "/activate") # Throw up a splash screen ASAP. Dont show anything if launched via --console. if options.build_gui: log.info("Using UI: %s" % self.ui) self.ImportGUI() if not options.iconify: self.ShowSplash() self.ShowStatusIcon() # Dynamically load all datasources, datasinks and converters dirs_to_search = [conduit.SHARED_MODULE_DIR, os.path.join(conduit.USER_DIR, "modules")] if options.enable_unsupported: dirs_to_search.append(os.path.join(conduit.SHARED_MODULE_DIR, "UNSUPPORTED")) # Initialize all globals variables conduit.GLOBALS.app = self conduit.GLOBALS.moduleManager = ModuleManager(dirs_to_search) conduit.GLOBALS.moduleManager.load_all(whitelist, blacklist) conduit.GLOBALS.typeConverter = TypeConverter(conduit.GLOBALS.moduleManager) conduit.GLOBALS.syncManager = SyncManager(conduit.GLOBALS.typeConverter) conduit.GLOBALS.mappingDB = MappingDB(self.dbFile) conduit.GLOBALS.mainloop = gobject.MainLoop() # Build both syncsets and put on the bus as early as possible self.guiSyncSet = SyncSet( moduleManager=conduit.GLOBALS.moduleManager, syncManager=conduit.GLOBALS.syncManager, xmlSettingFilePath=self.settingsFile, ) self.dbusSyncSet = SyncSet(moduleManager=conduit.GLOBALS.moduleManager, syncManager=conduit.GLOBALS.syncManager) # Set the view models if options.build_gui: self.BuildGUI() if not options.iconify: self.ShowGUI() # Dbus view... self.dbus = DBusInterface( conduitApplication=self, moduleManager=conduit.GLOBALS.moduleManager, typeConverter=conduit.GLOBALS.typeConverter, syncManager=conduit.GLOBALS.syncManager, guiSyncSet=self.guiSyncSet, dbusSyncSet=self.dbusSyncSet, ) if self.statusIcon: self.dbusSyncSet.connect("conduit-added", self.statusIcon.on_conduit_added) self.dbusSyncSet.connect("conduit-removed", self.statusIcon.on_conduit_removed) # hide the splash screen self.HideSplash() try: conduit.GLOBALS.mainloop.run() except KeyboardInterrupt: self.Quit()
def __init__(self): """ Conduit application class Parses command line arguments. Sets up the views and models; restores application settings, shows the splash screen and the UI Notes: 1) If conduit is launched without --console switch then the gui and the console interfaces are started 2) If launched with --console and then later via the gui then set up the gui and connect all the appropriate signal handlers """ self.splash = None self.gui = None self.statusIcon = None self.guiSyncSet = None self.uiLib = None gobject.set_application_name("Conduit") self.settingsFile = os.path.join(conduit.USER_DIR, "settings.xml") self.dbFile = os.path.join(conduit.USER_DIR, "mapping.db") #initialize application settings conduit.GLOBALS.settings = Settings() #command line parsing parser = optparse.OptionParser( prog="conduit", version="%%prog %s" % conduit.VERSION, description=_("Conduit is a synchronization application.")) parser.add_option( "-c", "--console", dest="build_gui", action="store_false", default=True, help=_("Launch without GUI. [default: %default]")) parser.add_option( "-f", "--config-file", metavar="FILE", default=self.settingsFile, help=_("Save dataprovider configuration to FILE. [default: %default]")) parser.add_option( "-i", "--iconify", action="store_true", default=False, help=_("Iconify on startup. [default: %default]")) parser.add_option( "-u", "--ui", metavar="NAME", default="gtk", help=_("Run with the specified UI. [default: %default]")) parser.add_option( "-w", "--with-modules", metavar="mod1,mod2", help=_("Only load modules in the named files. [default: load all modules]")) parser.add_option( "-x", "--without-modules", metavar="mod1,mod2", help=_("Do not load modules in the named files. [default: load all modules]")) parser.add_option( "-e", "--settings", metavar="key=val,key=val", help=_("Explicitly set internal Conduit settings (keys) to the given values for this session. [default: do not set]")) parser.add_option( "-U", "--enable-unsupported", action="store_true", default=False, help=_("Enable loading of unfinished or unsupported dataproviders. [default: %default]")) parser.add_option( "-d", "--debug", action="store_true", default=False, help=_("Generate more debugging information. [default: %default]")) parser.add_option( "-q", "--quiet", action="store_true", default=False, help=_("Generate less debugging information. [default: %default]")) parser.add_option( "-s", "--silent", action="store_true", default=False, help=_("Generate no debugging information. [default: %default]")) options, args = parser.parse_args() whitelist = None blacklist = None settings = {} if options.settings: for i in options.settings.split(','): k,v = i.split('=') settings[k] = v if options.with_modules: whitelist = options.with_modules.split(",") if options.without_modules: blacklist = options.without_modules.split(",") self.ui = options.ui self.settingsFile = os.path.abspath(options.config_file) if options.debug or not conduit.IS_INSTALLED: Logging.enable_debugging() if options.quiet: Logging.disable_debugging() if options.silent: Logging.disable_logging() log.info("Conduit v%s Installed: %s" % (conduit.VERSION, conduit.IS_INSTALLED)) log.info("Python: %s" % sys.version) log.info("Platform Implementations: %s,%s" % (conduit.BROWSER_IMPL, conduit.SETTINGS_IMPL)) if settings: log.info("Settings have been overridden: %s" % settings) #Make conduit single instance. If conduit is already running then #make the original process build or show the gui sessionBus = dbus.SessionBus() if Utils.dbus_service_available(APPLICATION_DBUS_IFACE, sessionBus): log.info("Conduit is already running") obj = sessionBus.get_object(APPLICATION_DBUS_IFACE, "/activate") conduitApp = dbus.Interface(obj, APPLICATION_DBUS_IFACE) if options.build_gui: if conduitApp.HasGUI(): conduitApp.ShowGUI() else: conduitApp.ImportGUI() conduitApp.ShowSplash() conduitApp.ShowStatusIcon() conduitApp.BuildGUI() conduitApp.ShowGUI() conduitApp.HideSplash() sys.exit(0) # Initialise dbus stuff here as any earlier will interfere # with Conduit already running check. bus_name = dbus.service.BusName(APPLICATION_DBUS_IFACE, bus=sessionBus) dbus.service.Object.__init__(self, bus_name, "/activate") #Throw up a splash screen ASAP. Dont show anything if launched via --console. if options.build_gui: log.info("Using UI: %s" % self.ui) self.ImportGUI() if not options.iconify: self.ShowSplash() self.ShowStatusIcon() #Dynamically load all datasources, datasinks and converters dirs_to_search = [ conduit.SHARED_MODULE_DIR, os.path.join(conduit.USER_DIR, "modules") ] if options.enable_unsupported: dirs_to_search.append(os.path.join(conduit.SHARED_MODULE_DIR, "UNSUPPORTED")) #Initialize all globals variables conduit.GLOBALS.app = self conduit.GLOBALS.moduleManager = ModuleManager(dirs_to_search) conduit.GLOBALS.moduleManager.load_all(whitelist, blacklist) conduit.GLOBALS.typeConverter = TypeConverter(conduit.GLOBALS.moduleManager) conduit.GLOBALS.syncManager = SyncManager(conduit.GLOBALS.typeConverter) conduit.GLOBALS.mappingDB = MappingDB(self.dbFile) conduit.GLOBALS.mainloop = gobject.MainLoop() #Build both syncsets and put on the bus as early as possible self.guiSyncSet = SyncSet( moduleManager=conduit.GLOBALS.moduleManager, syncManager=conduit.GLOBALS.syncManager, xmlSettingFilePath=self.settingsFile ) #Dbus view... conduit.GLOBALS.dbus = DBusInterface( conduitApplication=self, moduleManager=conduit.GLOBALS.moduleManager, typeConverter=conduit.GLOBALS.typeConverter, syncManager=conduit.GLOBALS.syncManager, guiSyncSet=self.guiSyncSet ) #Set the view models if options.build_gui: self.BuildGUI() if not options.iconify: self.ShowGUI() if self.statusIcon: dbusSyncSet = conduit.GLOBALS.dbus.get_syncset() dbusSyncSet.connect("conduit-added", self.statusIcon.on_conduit_added) dbusSyncSet.connect("conduit-removed", self.statusIcon.on_conduit_removed) #hide the splash screen self.HideSplash() try: conduit.GLOBALS.mainloop.run() except KeyboardInterrupt: self.Quit()