Merge pull request #86 from dopefishh/communicate-syncmode-to-synchooks
Communicate syncmode to synchooks
This commit is contained in:
		| @@ -320,6 +320,9 @@ remoterepository = RemoteExample | |||||||
| # | # | ||||||
| # The pre sync script has to complete before a sync to the account will start. | # The pre sync script has to complete before a sync to the account will start. | ||||||
| # | # | ||||||
|  | # The environment variable OFFLINEIMAPSYNCMODE will be set to either full, | ||||||
|  | # quick or idle to communicate the syncmode to the external command. | ||||||
|  | # | ||||||
| #presynchook = imapfilter -c someotherconfig.lua | #presynchook = imapfilter -c someotherconfig.lua | ||||||
| #postsynchook = notifysync.sh | #postsynchook = notifysync.sh | ||||||
|  |  | ||||||
|   | |||||||
| @@ -338,18 +338,6 @@ class SyncableAccount(Account): | |||||||
|  |  | ||||||
|         folderthreads = [] |         folderthreads = [] | ||||||
|  |  | ||||||
|         hook = self.getconf('presynchook', '') |  | ||||||
|         self.callhook(hook) |  | ||||||
|  |  | ||||||
|         if self.utf_8_support and self.remoterepos.getdecodefoldernames(): |  | ||||||
|             raise OfflineImapError("Configuration mismatch in account " + |  | ||||||
|                                    "'%s'. " % self.getname() + |  | ||||||
|                                    "\nAccount setting 'utf8foldernames' and repository " + |  | ||||||
|                                    "setting 'decodefoldernames'\nmay not be used at the " + |  | ||||||
|                                    "same time. This account has not been synchronized.\n" + |  | ||||||
|                                    "Please check the configuration and documentation.", |  | ||||||
|                                    OfflineImapError.ERROR.REPO) |  | ||||||
|  |  | ||||||
|         quickconfig = self.getconfint('quick', 0) |         quickconfig = self.getconfint('quick', 0) | ||||||
|         if quickconfig < 0: |         if quickconfig < 0: | ||||||
|             quick = True |             quick = True | ||||||
| @@ -363,6 +351,19 @@ class SyncableAccount(Account): | |||||||
|         else: |         else: | ||||||
|             quick = False |             quick = False | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         hook = self.getconf('presynchook', '') | ||||||
|  |         self.callhook(hook, "quick" if quick else "full") | ||||||
|  |  | ||||||
|  |         if self.utf_8_support and self.remoterepos.getdecodefoldernames(): | ||||||
|  |             raise OfflineImapError("Configuration mismatch in account " + | ||||||
|  |                                    "'%s'. " % self.getname() + | ||||||
|  |                                    "\nAccount setting 'utf8foldernames' and repository " + | ||||||
|  |                                    "setting 'decodefoldernames'\nmay not be used at the " + | ||||||
|  |                                    "same time. This account has not been synchronized.\n" + | ||||||
|  |                                    "Please check the configuration and documentation.", | ||||||
|  |                                    OfflineImapError.ERROR.REPO) | ||||||
|  |  | ||||||
|         try: |         try: | ||||||
|             startedThread = False |             startedThread = False | ||||||
|             remoterepos = self.remoterepos |             remoterepos = self.remoterepos | ||||||
| @@ -444,9 +445,9 @@ class SyncableAccount(Account): | |||||||
|             remoterepos.holdordropconnections() |             remoterepos.holdordropconnections() | ||||||
|  |  | ||||||
|         hook = self.getconf('postsynchook', '') |         hook = self.getconf('postsynchook', '') | ||||||
|         self.callhook(hook) |         self.callhook(hook, "quick" if quick else "full") | ||||||
|  |  | ||||||
|     def callhook(self, cmd): |     def callhook(self, cmd, syncmode): | ||||||
|         # Check for CTRL-C or SIGTERM and run postsynchook. |         # Check for CTRL-C or SIGTERM and run postsynchook. | ||||||
|         if Account.abort_NOW_signal.is_set(): |         if Account.abort_NOW_signal.is_set(): | ||||||
|             return |             return | ||||||
| @@ -456,9 +457,11 @@ class SyncableAccount(Account): | |||||||
|             self.ui.callhook("Calling hook: " + cmd) |             self.ui.callhook("Calling hook: " + cmd) | ||||||
|             if self.dryrun: |             if self.dryrun: | ||||||
|                 return |                 return | ||||||
|  |             environ = os.environ.copy() | ||||||
|  |             environ['OFFLINEIMAPSYNCMODE'] = syncmode | ||||||
|             p = Popen(cmd, shell=True, |             p = Popen(cmd, shell=True, | ||||||
|                       stdin=PIPE, stdout=PIPE, stderr=PIPE, |                       stdin=PIPE, stdout=PIPE, stderr=PIPE, | ||||||
|                       close_fds=True) |                       close_fds=True, env=environ) | ||||||
|             stdout, stderr = p.communicate() |             stdout, stderr = p.communicate() | ||||||
|             self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n" |             self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n" | ||||||
|                     % (stdout.decode('utf-8'), stderr.decode('utf-8'))) |                     % (stdout.decode('utf-8'), stderr.decode('utf-8'))) | ||||||
|   | |||||||
| @@ -838,10 +838,10 @@ class IdleThread: | |||||||
|         remotefolder = remoterepos.getfolder(self.folder, decode=False) |         remotefolder = remoterepos.getfolder(self.folder, decode=False) | ||||||
|  |  | ||||||
|         hook = account.getconf('presynchook', '') |         hook = account.getconf('presynchook', '') | ||||||
|         account.callhook(hook) |         account.callhook(hook, "idle") | ||||||
|         offlineimap.accounts.syncfolder(account, remotefolder, quick=False) |         offlineimap.accounts.syncfolder(account, remotefolder, quick=False) | ||||||
|         hook = account.getconf('postsynchook', '') |         hook = account.getconf('postsynchook', '') | ||||||
|         account.callhook(hook) |         account.callhook(hook, "idle") | ||||||
|  |  | ||||||
|         ui = getglobalui() |         ui = getglobalui() | ||||||
|         ui.unregisterthread(currentThread())  # syncfolder registered the thread |         ui.unregisterthread(currentThread())  # syncfolder registered the thread | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Rodolfo García Peñas (kix)
					Rodolfo García Peñas (kix)