Reformat offlineimap/accounts.py
Add some spaces, remove lines,... now format is better (lintian).
This commit is contained in:
parent
58596767ef
commit
9f15c05520
@ -41,6 +41,7 @@ except:
|
|||||||
except:
|
except:
|
||||||
pass # Ok if this fails, we can do without.
|
pass # Ok if this fails, we can do without.
|
||||||
|
|
||||||
|
|
||||||
# FIXME: spaghetti code alert!
|
# FIXME: spaghetti code alert!
|
||||||
def getaccountlist(customconfig):
|
def getaccountlist(customconfig):
|
||||||
# Account names in a list.
|
# Account names in a list.
|
||||||
@ -80,7 +81,7 @@ class Account(CustomConfig.ConfigHelperMixin):
|
|||||||
self.dryrun = self.config.getboolean('general', 'dry-run')
|
self.dryrun = self.config.getboolean('general', 'dry-run')
|
||||||
self.quicknum = 0
|
self.quicknum = 0
|
||||||
if self.refreshperiod < 0:
|
if self.refreshperiod < 0:
|
||||||
self.ui.warn("autorefresh for %s is negative, fixing it to 0."%
|
self.ui.warn("autorefresh for %s is negative, fixing it to 0." %
|
||||||
name)
|
name)
|
||||||
self.refreshperiod = 0.0
|
self.refreshperiod = 0.0
|
||||||
if self.refreshperiod == 0.0:
|
if self.refreshperiod == 0.0:
|
||||||
@ -193,10 +194,10 @@ class Account(CustomConfig.ConfigHelperMixin):
|
|||||||
|
|
||||||
remote_repo = Repository(self, 'remote')
|
remote_repo = Repository(self, 'remote')
|
||||||
local_repo = Repository(self, 'local')
|
local_repo = Repository(self, 'local')
|
||||||
#status_repo = Repository(self, 'status')
|
# status_repo = Repository(self, 'status')
|
||||||
self.ui.serverdiagnostics(remote_repo, 'Remote')
|
self.ui.serverdiagnostics(remote_repo, 'Remote')
|
||||||
self.ui.serverdiagnostics(local_repo, 'Local')
|
self.ui.serverdiagnostics(local_repo, 'Local')
|
||||||
#self.ui.serverdiagnostics(statusrepos, 'Status')
|
# self.ui.serverdiagnostics(statusrepos, 'Status')
|
||||||
|
|
||||||
def deletefolder(self, foldername):
|
def deletefolder(self, foldername):
|
||||||
remote_repo = Repository(self, 'remote')
|
remote_repo = Repository(self, 'remote')
|
||||||
@ -204,10 +205,10 @@ class Account(CustomConfig.ConfigHelperMixin):
|
|||||||
try:
|
try:
|
||||||
if self.dryrun:
|
if self.dryrun:
|
||||||
self.ui.info("would try to remove '%s' on remote of '%s' "
|
self.ui.info("would try to remove '%s' on remote of '%s' "
|
||||||
"account"% (foldername, self))
|
"account" % (foldername, self))
|
||||||
else:
|
else:
|
||||||
remote_repo.deletefolder(foldername)
|
remote_repo.deletefolder(foldername)
|
||||||
self.ui.info("Folder '%s' deleted."% foldername)
|
self.ui.info("Folder '%s' deleted." % foldername)
|
||||||
return 0
|
return 0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.ui.error(e)
|
self.ui.error(e)
|
||||||
@ -228,7 +229,7 @@ class SyncableAccount(Account):
|
|||||||
Account.__init__(self, *args, **kwargs)
|
Account.__init__(self, *args, **kwargs)
|
||||||
self._lockfd = None
|
self._lockfd = None
|
||||||
self._lockfilepath = os.path.join(
|
self._lockfilepath = os.path.join(
|
||||||
self.config.getmetadatadir(), "%s.lock"% self)
|
self.config.getmetadatadir(), "%s.lock" % self)
|
||||||
|
|
||||||
def __lock(self):
|
def __lock(self):
|
||||||
"""Lock the account, throwing an exception if it is locked already."""
|
"""Lock the account, throwing an exception if it is locked already."""
|
||||||
@ -239,7 +240,7 @@ class SyncableAccount(Account):
|
|||||||
except NameError:
|
except NameError:
|
||||||
# portalocker not available for Windows.
|
# portalocker not available for Windows.
|
||||||
try:
|
try:
|
||||||
fcntl.lockf(self._lockfd, fcntl.LOCK_EX|fcntl.LOCK_NB)
|
fcntl.lockf(self._lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
except NameError:
|
except NameError:
|
||||||
pass # fnctl not available, disable file locking... :(
|
pass # fnctl not available, disable file locking... :(
|
||||||
except IOError:
|
except IOError:
|
||||||
@ -247,14 +248,14 @@ class SyncableAccount(Account):
|
|||||||
six.reraise(OfflineImapError,
|
six.reraise(OfflineImapError,
|
||||||
OfflineImapError(
|
OfflineImapError(
|
||||||
"Could not lock account %s. Is another "
|
"Could not lock account %s. Is another "
|
||||||
"instance using this account?"% self,
|
"instance using this account?" % self,
|
||||||
OfflineImapError.ERROR.REPO),
|
OfflineImapError.ERROR.REPO),
|
||||||
exc_info()[2])
|
exc_info()[2])
|
||||||
|
|
||||||
def _unlock(self):
|
def _unlock(self):
|
||||||
"""Unlock the account, deleting the lock file"""
|
"""Unlock the account, deleting the lock file"""
|
||||||
|
|
||||||
#If we own the lock file, delete it
|
# If we own the lock file, delete it
|
||||||
if self._lockfd and not self._lockfd.closed:
|
if self._lockfd and not self._lockfd.closed:
|
||||||
try:
|
try:
|
||||||
portalocker.unlock(self._lockfd)
|
portalocker.unlock(self._lockfd)
|
||||||
@ -303,7 +304,7 @@ class SyncableAccount(Account):
|
|||||||
self.ui.error(e, exc_info()[2])
|
self.ui.error(e, exc_info()[2])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.ui.error(e, exc_info()[2], msg=
|
self.ui.error(e, exc_info()[2], msg=
|
||||||
"While attempting to sync account '%s'"% self)
|
"While attempting to sync account '%s'" % self)
|
||||||
else:
|
else:
|
||||||
# After success sync, reset the looping counter to 3.
|
# After success sync, reset the looping counter to 3.
|
||||||
if self.refreshperiod:
|
if self.refreshperiod:
|
||||||
@ -321,7 +322,6 @@ class SyncableAccount(Account):
|
|||||||
remotefolder.getvisiblename().
|
remotefolder.getvisiblename().
|
||||||
replace(self.remoterepos.getsep(), self.localrepos.getsep()))
|
replace(self.remoterepos.getsep(), self.localrepos.getsep()))
|
||||||
|
|
||||||
|
|
||||||
# The syncrunner will loop on this method. This means it is called more than
|
# The syncrunner will loop on this method. This means it is called more than
|
||||||
# once during the run.
|
# once during the run.
|
||||||
def __sync(self):
|
def __sync(self):
|
||||||
@ -338,7 +338,7 @@ class SyncableAccount(Account):
|
|||||||
|
|
||||||
if self.utf_8_support and self.remoterepos.getdecodefoldernames():
|
if self.utf_8_support and self.remoterepos.getdecodefoldernames():
|
||||||
raise OfflineImapError("Configuration mismatch in account " +
|
raise OfflineImapError("Configuration mismatch in account " +
|
||||||
"'%s'. "% self.getname() +
|
"'%s'. " % self.getname() +
|
||||||
"\nAccount setting 'utf8foldernames' and repository " +
|
"\nAccount setting 'utf8foldernames' and repository " +
|
||||||
"setting 'decodefoldernames'\nmay not be used at the " +
|
"setting 'decodefoldernames'\nmay not be used at the " +
|
||||||
"same time. This account has not been synchronized.\n" +
|
"same time. This account has not been synchronized.\n" +
|
||||||
@ -382,7 +382,7 @@ class SyncableAccount(Account):
|
|||||||
|
|
||||||
if not remotefolder.sync_this:
|
if not remotefolder.sync_this:
|
||||||
self.ui.debug('', "Not syncing filtered folder '%s'"
|
self.ui.debug('', "Not syncing filtered folder '%s'"
|
||||||
"[%s]"% (remotefolder.getname(), remoterepos))
|
"[%s]" % (remotefolder.getname(), remoterepos))
|
||||||
continue # Ignore filtered folder.
|
continue # Ignore filtered folder.
|
||||||
|
|
||||||
# The remote folder names must not have the local sep char in
|
# The remote folder names must not have the local sep char in
|
||||||
@ -393,22 +393,22 @@ class SyncableAccount(Account):
|
|||||||
sep != remoterepos.getsep() and
|
sep != remoterepos.getsep() and
|
||||||
sep in remotefolder.getname()):
|
sep in remotefolder.getname()):
|
||||||
self.ui.warn('', "Ignoring folder '%s' due to unsupported "
|
self.ui.warn('', "Ignoring folder '%s' due to unsupported "
|
||||||
"'%s' character serving as local separator."%
|
"'%s' character serving as local separator." %
|
||||||
(remotefolder.getname(), localrepos.getsep()))
|
(remotefolder.getname(), localrepos.getsep()))
|
||||||
continue # Ignore unsupported folder name.
|
continue # Ignore unsupported folder name.
|
||||||
|
|
||||||
localfolder = self.get_local_folder(remotefolder)
|
localfolder = self.get_local_folder(remotefolder)
|
||||||
if not localfolder.sync_this:
|
if not localfolder.sync_this:
|
||||||
self.ui.debug('', "Not syncing filtered folder '%s'"
|
self.ui.debug('', "Not syncing filtered folder '%s'"
|
||||||
"[%s]"% (localfolder.getname(), localfolder.repository))
|
"[%s]" % (localfolder.getname(), localfolder.repository))
|
||||||
continue # Ignore filtered folder.
|
continue # Ignore filtered folder.
|
||||||
|
|
||||||
if not globals.options.singlethreading:
|
if not globals.options.singlethreading:
|
||||||
thread = InstanceLimitedThread(
|
thread = InstanceLimitedThread(
|
||||||
limitNamespace="%s%s"% (
|
limitNamespace="%s%s" % (
|
||||||
FOLDER_NAMESPACE, self.remoterepos.getname()),
|
FOLDER_NAMESPACE, self.remoterepos.getname()),
|
||||||
target=syncfolder,
|
target=syncfolder,
|
||||||
name="Folder %s [acc: %s]"% (
|
name="Folder %s [acc: %s]" % (
|
||||||
remotefolder.getexplainedname(), self),
|
remotefolder.getexplainedname(), self),
|
||||||
args=(self, remotefolder, quick)
|
args=(self, remotefolder, quick)
|
||||||
)
|
)
|
||||||
@ -455,15 +455,15 @@ class SyncableAccount(Account):
|
|||||||
stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
||||||
close_fds=True)
|
close_fds=True)
|
||||||
r = p.communicate()
|
r = p.communicate()
|
||||||
self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n"% r)
|
self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n" % r)
|
||||||
self.ui.callhook("Hook return code: %d"% p.returncode)
|
self.ui.callhook("Hook return code: %d" % p.returncode)
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.ui.error(e, exc_info()[2], msg="Calling hook")
|
self.ui.error(e, exc_info()[2], msg="Calling hook")
|
||||||
|
|
||||||
|
|
||||||
#XXX: This function should likely be refactored. This should not be passed the
|
# XXX: This function should likely be refactored. This should not be passed the
|
||||||
# account instance.
|
# account instance.
|
||||||
def syncfolder(account, remotefolder, quick):
|
def syncfolder(account, remotefolder, quick):
|
||||||
"""Synchronizes given remote folder for the specified account.
|
"""Synchronizes given remote folder for the specified account.
|
||||||
@ -483,7 +483,7 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
# The localfolder full name is good to uniquely identify the sync
|
# The localfolder full name is good to uniquely identify the sync
|
||||||
# transaction.
|
# transaction.
|
||||||
if SYNC_MUTEXES[account_name].get(localfolder_name) is None:
|
if SYNC_MUTEXES[account_name].get(localfolder_name) is None:
|
||||||
#XXX: This lock could be an external file lock so we can remove
|
# XXX: This lock could be an external file lock so we can remove
|
||||||
# the lock at the account level.
|
# the lock at the account level.
|
||||||
SYNC_MUTEXES[account_name][localfolder_name] = Lock()
|
SYNC_MUTEXES[account_name][localfolder_name] = Lock()
|
||||||
|
|
||||||
@ -517,7 +517,7 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
"""Returns messages with uid > min(uids of messages newer than date)."""
|
"""Returns messages with uid > min(uids of messages newer than date)."""
|
||||||
|
|
||||||
remotefolder.cachemessagelist(
|
remotefolder.cachemessagelist(
|
||||||
min_date=time.gmtime(time.mktime(date) + 24*60*60))
|
min_date=time.gmtime(time.mktime(date) + 24 * 60 * 60))
|
||||||
uids = remotefolder.getmessageuidlist()
|
uids = remotefolder.getmessageuidlist()
|
||||||
localfolder.dropmessagelistcache()
|
localfolder.dropmessagelistcache()
|
||||||
if len(uids) > 0:
|
if len(uids) > 0:
|
||||||
@ -564,7 +564,7 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
if min_uid == None: # min_uid file didn't exist
|
if min_uid == None: # min_uid file didn't exist
|
||||||
if len(new.getmessageuidlist()) > 0:
|
if len(new.getmessageuidlist()) > 0:
|
||||||
raise OfflineImapError("To use startdate on Repository %s, "
|
raise OfflineImapError("To use startdate on Repository %s, "
|
||||||
"Repository %s must be empty"%
|
"Repository %s must be empty" %
|
||||||
(partial.repository.name, new.repository.name),
|
(partial.repository.name, new.repository.name),
|
||||||
OfflineImapError.ERROR.MESSAGE)
|
OfflineImapError.ERROR.MESSAGE)
|
||||||
else:
|
else:
|
||||||
@ -581,7 +581,6 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
else:
|
else:
|
||||||
partial.cachemessagelist(min_uid=min_uid)
|
partial.cachemessagelist(min_uid=min_uid)
|
||||||
|
|
||||||
|
|
||||||
remoterepos = account.remoterepos
|
remoterepos = account.remoterepos
|
||||||
localrepos = account.localrepos
|
localrepos = account.localrepos
|
||||||
statusrepos = account.statusrepos
|
statusrepos = account.statusrepos
|
||||||
@ -653,7 +652,7 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder)
|
ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder)
|
||||||
remotefolder.syncmessagesto(localfolder, statusfolder)
|
remotefolder.syncmessagesto(localfolder, statusfolder)
|
||||||
else:
|
else:
|
||||||
ui.debug('', "Not syncing to read-only repository '%s'"%
|
ui.debug('', "Not syncing to read-only repository '%s'" %
|
||||||
localrepos.getname())
|
localrepos.getname())
|
||||||
|
|
||||||
# Synchronize local changes.
|
# Synchronize local changes.
|
||||||
@ -661,7 +660,7 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
ui.syncingmessages(localrepos, localfolder, remoterepos, remotefolder)
|
ui.syncingmessages(localrepos, localfolder, remoterepos, remotefolder)
|
||||||
localfolder.syncmessagesto(remotefolder, statusfolder)
|
localfolder.syncmessagesto(remotefolder, statusfolder)
|
||||||
else:
|
else:
|
||||||
ui.debug('', "Not syncing to read-only repository '%s'"%
|
ui.debug('', "Not syncing to read-only repository '%s'" %
|
||||||
remoterepos.getname())
|
remoterepos.getname())
|
||||||
|
|
||||||
statusfolder.save()
|
statusfolder.save()
|
||||||
@ -674,9 +673,9 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
ui.error(e, exc_info()[2], msg="Aborting sync, folder '%s' "
|
ui.error(e, exc_info()[2], msg="Aborting sync, folder '%s' "
|
||||||
"[acc: '%s']"% (localfolder, account))
|
"[acc: '%s']" % (localfolder, account))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ui.error(e, msg="ERROR in syncfolder for %s folder %s: %s"%
|
ui.error(e, msg="ERROR in syncfolder for %s folder %s: %s" %
|
||||||
(account, remotefolder.getvisiblename(), traceback.format_exc()))
|
(account, remotefolder.getvisiblename(), traceback.format_exc()))
|
||||||
finally:
|
finally:
|
||||||
for folder in ["statusfolder", "localfolder", "remotefolder"]:
|
for folder in ["statusfolder", "localfolder", "remotefolder"]:
|
||||||
|
Loading…
Reference in New Issue
Block a user