Exemplo n.º 1
0
def startCLI():
    """
    Controls the major flow for PISI (CLI)
    
    Calls one after another the supporting functions in this module.
    """
    if not testConfiguration():
        sys.exit(0)
    
    verbose, modulesToLoad, modulesNamesCombined, soft, mergeMode = parseArguments()
    cb = CLICallback(verbose)
    pisiprogress.registerCallback(cb)
    
    cb.progress.push(0, 8)
    cb.update('Starting Configuration')
    cb.verbose('')
    cb.verbose("*" * 55)
    cb.verbose( "*" * 22 + "   PISI    " + "*" * 22)
    cb.verbose( "*" * 55)
    cb.verbose( "** PISI is synchronizing information " + "*" * 18)
    cb.verbose( "** http://freshmeat.net/projects/pisiom " + "*" * 8)
    cb.verbose( "*" * 55)
    
    cb.verbose( ("\n" + "*" * 15 + " PHASE 0 - Configuration " + "*" * 15))
    cb.verbose( "Verbose mode on")
    cb.verbose( ("In case of conflicts I use the following strategy: %s" %(MERGEMODE_STRINGS[mergeMode])))

    config,  configfolder = pisi.readConfiguration()
    source = pisi.importModules(configfolder,  config,  modulesToLoad,  modulesNamesCombined, soft)
    mode = pisi.determineMode(config,  modulesToLoad)
    cb.progress.drop()

    cb.progress.push(8, 10)
    cb.update('Pre-Processing sources')
    cb.verbose("\tSource 1")
    source[0].preProcess()
    cb.verbose("\tSource 2")
    source[1].preProcess()
    cb.verbose("  Pre-Processing Done")
    cb.progress.drop()

    cb.progress.push(10, 40)
    cb.update('Loading from sources')
    cb.verbose("\n" + "*" * 18 + " PHASE 1 - Loading " + "*" * 18)
    cb.progress.push(0, 50)
    source[0].load()
    cb.progress.drop()
    cb.progress.push(50,  100)
    cb.update('Loading')
    source[1].load()
    cb.progress.drop()
    cb.progress.drop()

    cb.progress.push(40, 70)
    cb.update('Comparing sources')
    cb.verbose("\n" + "*" * 17 + " PHASE 2 - Comparing " + "*" * 17)
    if mode == MODE_CALENDAR:  # events mode
        pisi.eventsSync.syncEvents(verbose,  modulesToLoad,  source)
    elif mode == MODE_CONTACTS:  # contacts mode
        pisi.contactsSync.syncContacts(verbose,  modulesToLoad,  source,  mergeMode)    
    cb.progress.drop()

    cb.progress.push(70, 95)
    cb.update('Making changes permanent')
    cb.verbose ("\n" + "*" * 18 + " PHASE 3 - Saving  " + "*" * 18)
    if soft:
        print "You chose soft mode for PISI - changes are not applied to data sources."
    else:
        pisi.applyChanges(source)
    cb.verbose( "*" * 24 + " DONE  " + "*" * 24)
    cb.progress.drop()
    
    cb.progress.push(95, 100)
    cb.update('Post-Processing sources')
    cb.verbose("\tSource 1")
    source[0].postProcess()
    cb.verbose("\tSource 2")
    source[1].postProcess()
    cb.verbose("  Post-Processing Done")
    cb.progress.drop()
    
    cb.update('Finished')
Exemplo n.º 2
0
    def startSync(self, target):
        """
        Passes control on to PISI core and starts up synchronization process
        
        Updates on the GUI are from now on only performed on request of the core by calling the callback functions.
        """
        self.verbose('Configuring')
        self.progress.reset()
        self.progress.setProgress(0)
        self.update('Configuring')
        self.verbose('Starting synchronization')
        self.verbose('My configuration is:')
        page = self.notebook.get_current_page()
        modulesToLoad = []
        modulesNamesCombined = ""
        mergeMode = 0
        if page == 0:   # sync contacts
            mode = 1
            if len(self.sourcesContacts) < 2:
                self.progress.setProgress(0)
                self.update('Error')
                self.message("You cannot synchronize this type of PIM information as you do not have enough data sources available / configured.")
                return
            source1 = self.contacts_combobox1.get_active()
            source1 = self.sourcesContacts[source1]
            source1 = self.sources[source1][0]
            source2 = self.contacts_combobox2.get_active()
            source2 = self.sourcesContacts[source2]
            source2 = self.sources[source2][0]
            mergeMode = self.contacts_combobox3.get_active()
        elif page == 1: # sync calendar
            mode = 0
            if len(self.sourcesCalendar) < 2:
                self.progress.setProgress(0)
                self.update('Error')
                self.message("You cannot synchronize this type of PIM information as you do not have enough data sources available / configured.")
                return
            source1 = self.calendar_combobox1.get_active()
            source1 = self.sourcesCalendar[source1]
            source1 = self.sources[source1][0]
            source2 = self.calendar_combobox2.get_active()
            source2 = self.sourcesCalendar[source2]
            source2 = self.sources[source2][0]
            
        if source1 == source2:
            self.progress.setProgress(0)
            self.update('Error')
            self.error("You cannot choose one source for synchronization twice. Please make sure that two different sources are chosen for synchronization.")
            return
            
        self.verbose('\tMode is %d - %s' %(mode,  MODE_STRINGS[mode]))
        self.verbose( ('\tIn case of conflicts I use the following strategy: %s' %(MERGEMODE_STRINGS[mergeMode])))
        modulesToLoad.append(source1)
        modulesToLoad.append(source2)
        modulesNamesCombined += source1
        modulesNamesCombined += source2

        config,  configfolder = pisi.readConfiguration()
        source = pisi.importModules(configfolder,  config,  modulesToLoad,  modulesNamesCombined, False)

        self.progress.push(8, 10)
        self.update('Pre-Processing sources')
        self.verbose('Pre-Processing sources')
        self.verbose("\tSource 1")
        source[0].preProcess()
        self.verbose("\tSource 2")
        source[1].preProcess()
        self.verbose("  Pre-Processing Done")
        self.progress.drop()

        self.progress.push(10, 40)
        self.update('Loading')
        self.verbose("\n PHASE 1 - Loading ")
        try:
            self.progress.push(0, 50)
            source[0].load()
            self.progress.drop()
        except BaseException,  m:
            if not self.promptGenericConfirmation("The following error occured when loading:\n%s\nContinue processing?" %(m.message)):
                self.progress.reset()
                self.update("Error")
                return
            self.progress.drop()