[PATCH/RFC 2/7] Load up new config file to which we're uploading

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


Adds three command options:
     --update-conf [new config file]
     --move-content : simpy move the files instead of copying message
     --restore-update [aborted update dir]

Logic:
Loads the new config file the same way it's done for regular config.
If --restore-update is provided, check that the dir exists.  Set the
same command options for the new config file.  Initialize some vars
that will be used in the update process.

Discussion:
I'm thinking of completly changing the way the update process takes
its input. Instead of loading a new config file, this could be done in
a single config files with parameters for updating to new nametrans,
folderfilter and encoding. This could could open new possibilities to
improve performence of the updating process. It could also make the
--restore-update cmd option easier to use, since we can record its dir
in the config file.

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

diff --git a/offlineimap/init.py b/offlineimap/init.py
index 80158bd..b36db25 100644
--- a/offlineimap/init.py
+++ b/offlineimap/init.py
@@ -97,6 +97,8 @@ class OfflineImap(object):
             mbnames.write()
         elif options.deletefolder:
             return self.__deletefolder(options)
+        elif options.newconfigfile:
+            return self.__sync(options)
         else:
             return self.__sync(options)
 
@@ -160,6 +162,26 @@ class OfflineImap(object):
                   metavar="[section:]option=value",
                   help="override configuration file option")
 
+        parser.add_option("--update-conf", dest="newconfigfile",
+                  metavar="NEWCONFIGFILE",
+                  default=None,
+                  help="(EXPERIMENTAL: do not support changes in account names)"
+                  "convert actual config to new config from source file,"
+                  "and replace configfile with sourcefile.")
+
+        parser.add_option("--restore-update", dest="failedupdaterestore",
+                  metavar="FAILEDUPDATERESTORE",
+                  default=None,
+                  help="in conjonction with --update-conf, "
+                  "restore a failed update process.")
+
+        parser.add_option("--move-content",
+                  action="store_true",
+                  dest="movecontent",
+                  default=False,
+                  help="in conjonction with --update-conf, "
+                  "move content of folder instead of copying.")
+
         parser.add_option("-o",
                   action="store_true", dest="runonce",
                   default=False,
@@ -246,6 +268,47 @@ class OfflineImap(object):
                     section = "general"
                 config.set(section, key, value)
 
+        # Update and convert config file.
+        if options.newconfigfile:
+            newconfigfilename = os.path.expanduser(options.newconfigfile)
+
+            # Read new configfile
+            newconfigfile = CustomConfigParser()
+            if not os.path.exists(newconfigfilename):
+                # TODO, initialize and make use of chosen ui for logging
+                logging.error(" *** New config file '%s' does not exist; aborting!"%
+                              newconfigfilename)
+                sys.exit(1)
+            newconfigfile.read(newconfigfilename)
+            
+            if options.dryrun:
+                dryrun = newconfigfile.set('general', 'dry-run', 'True')
+            newconfigfile.set_if_not_exists('general', 'dry-run', 'False')
+
+            if options.failedupdaterestore:
+                failedupdaterestore = os.path.expanduser(options.failedupdaterestore)
+                if not os.path.exists(failedupdaterestore):
+                    # TODO, initialize and make use of chosen ui for logging
+                    logging.error(" *** Failed update '%s' does not exist; aborting!"%
+                                  failedupdaterestore)
+                    sys.exit(1)
+            else:
+                failedupdaterestore = ''
+
+            # Set update options in both config files
+            # and initialize some vars.
+            self.config_filename = configfilename
+            self.newconfig_filename = newconfigfilename
+            newconfigfile.set('general', 'update-conf', 'True')
+            newconfigfile.set('general', 'is-new-config-source', 'True')
+            newconfigfile.set('general', 'movecontent', str(options.movecontent))
+            newconfigfile.set('general', 'failedupdaterestore', failedupdaterestore)
+            config.set('general', 'update-conf', 'True')
+            config.set('general', 'movecontent', str(options.movecontent))
+            self.newconfig = newconfigfile
+        config.set('general', 'is-new-config-source', 'False')
+        config.set_if_not_exists('general', 'update-conf', 'False')
+
         # Which ui to use? CLI option overrides config file.
         ui_type = config.getdefault('general', 'ui', 'ttyui')
         if options.interface != None:
-- 
2.11.0




More information about the OfflineIMAP-project mailing list