[PATCH/RFC 3/7] Invoke updating process

Hubert Pineault hpineault at riseup.net
Sun Mar 3 08:56:59 GMT 2019


The update process is invoked through init.__sync() method.

Logic:
The idea is not to duplicate sig_handler and UI initializations.
Although, I think it should be rewritten in a distinct methode that
would called by run(). The sync process and the update process
shouldn't mixed.

Discussion:
I'm thinking of two ways to improve. Either write a new method that
would deal with sig_handler and be called by both sync and update
processes. Or, simply copy __sync() code and adapt it for the update
process.

New method:
    _newactiveaccounts()

The method is almost a copy/paste of _get_activeaccounts(). We first
make the list of accounts in the new config file. Then we check that
they exist in the old config file. It returns only accounts found in
both config files.  I think this code should be included in another
method so that we use _get_activeaccounts() and then test config's
files accounts correspondance. (Note that the whole war the update
process takes its input through files should probably be re-thought)

Signed-off-by: Hubert Pineault <hpineault at riseup.net>
---
 offlineimap/init.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/offlineimap/init.py b/offlineimap/init.py
index b36db25..e82d808 100644
--- a/offlineimap/init.py
+++ b/offlineimap/init.py
@@ -480,6 +480,46 @@ class OfflineImap(object):
 
         return activeaccounts
 
+    def _get_newactiveaccounts(self, activeaccounts, options):
+        """Check that each accounts in new config file exists in old config
+        file.
+        Assumes that self.newconfig is defined.
+        Based on _get_activeaccounts()
+        """
+
+        oldactiveaccounts = activeaccounts
+        newactiveaccounts = []
+        errormsg = None
+
+        # Load accounts in new config file source
+        newactiveaccountnames = self.newconfig.get("general", "accounts")
+        if options.accounts:
+            newactiveaccountnames = options.accounts
+        newactiveaccountnames = [x.lstrip()
+                                 for x in newactiveaccountnames.split(",")]
+
+        allnewaccounts = accounts.getaccountlist(self.newconfig)
+  
+        # Check for new config file accounts integrety
+        # (not sure if it does) and if check if they exists
+        # in old config file
+        for accountname in newactiveaccountnames:
+            if accountname in allnewaccounts \
+               and accountname in oldactiveaccounts:
+                newactiveaccounts.append(accountname)
+            else:
+                errormsg = "Valid accounts are: %s"% (
+                    ", ".join(oldactiveaccounts))
+                self.ui.error("The account '%s' does not exist"% accountname)
+
+        if len(activeaccounts) < 1:
+            errormsg = "No accounts are defined!"
+
+        if errormsg is not None:
+            self.ui.terminate(1, errormsg=errormsg)
+
+        return newactiveaccounts
+
     def __sync(self, options):
         """Invoke the correct single/multithread syncing
 
@@ -526,7 +566,16 @@ class OfflineImap(object):
             activeaccounts = self._get_activeaccounts(options)
             mbnames.init(self.config, self.ui, options.dryrun)
 
-            if options.singlethreading:
+            if options.newconfigfile:
+                # Update directory structure and folder names
+                # instead of syncing.
+                newactiveaccounts = self._get_newactiveaccounts(activeaccounts,
+                                                                options)
+                mbnames.init(self.newconfig, self.ui, options.dryrun)
+                self.__updateconf(activeaccounts, newactiveaccounts,
+                                  options.profiledir)
+
+            elif options.singlethreading:
                 # Singlethreaded.
                 self.__sync_singlethreaded(activeaccounts, options.profiledir)
             else:
-- 
2.11.0




More information about the OfflineIMAP-project mailing list