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:
|
||||
pass # Ok if this fails, we can do without.
|
||||
|
||||
|
||||
# FIXME: spaghetti code alert!
|
||||
def getaccountlist(customconfig):
|
||||
# Account names in a list.
|
||||
@ -80,7 +81,7 @@ class Account(CustomConfig.ConfigHelperMixin):
|
||||
self.dryrun = self.config.getboolean('general', 'dry-run')
|
||||
self.quicknum = 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)
|
||||
self.refreshperiod = 0.0
|
||||
if self.refreshperiod == 0.0:
|
||||
@ -193,10 +194,10 @@ class Account(CustomConfig.ConfigHelperMixin):
|
||||
|
||||
remote_repo = Repository(self, 'remote')
|
||||
local_repo = Repository(self, 'local')
|
||||
#status_repo = Repository(self, 'status')
|
||||
# status_repo = Repository(self, 'status')
|
||||
self.ui.serverdiagnostics(remote_repo, 'Remote')
|
||||
self.ui.serverdiagnostics(local_repo, 'Local')
|
||||
#self.ui.serverdiagnostics(statusrepos, 'Status')
|
||||
# self.ui.serverdiagnostics(statusrepos, 'Status')
|
||||
|
||||
def deletefolder(self, foldername):
|
||||
remote_repo = Repository(self, 'remote')
|
||||
@ -204,10 +205,10 @@ class Account(CustomConfig.ConfigHelperMixin):
|
||||
try:
|
||||
if self.dryrun:
|
||||
self.ui.info("would try to remove '%s' on remote of '%s' "
|
||||
"account"% (foldername, self))
|
||||
"account" % (foldername, self))
|
||||
else:
|
||||
remote_repo.deletefolder(foldername)
|
||||
self.ui.info("Folder '%s' deleted."% foldername)
|
||||
self.ui.info("Folder '%s' deleted." % foldername)
|
||||
return 0
|
||||
except Exception as e:
|
||||
self.ui.error(e)
|
||||
@ -228,7 +229,7 @@ class SyncableAccount(Account):
|
||||
Account.__init__(self, *args, **kwargs)
|
||||
self._lockfd = None
|
||||
self._lockfilepath = os.path.join(
|
||||
self.config.getmetadatadir(), "%s.lock"% self)
|
||||
self.config.getmetadatadir(), "%s.lock" % self)
|
||||
|
||||
def __lock(self):
|
||||
"""Lock the account, throwing an exception if it is locked already."""
|
||||
@ -239,7 +240,7 @@ class SyncableAccount(Account):
|
||||
except NameError:
|
||||
# portalocker not available for Windows.
|
||||
try:
|
||||
fcntl.lockf(self._lockfd, fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||
fcntl.lockf(self._lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except NameError:
|
||||
pass # fnctl not available, disable file locking... :(
|
||||
except IOError:
|
||||
@ -247,14 +248,14 @@ class SyncableAccount(Account):
|
||||
six.reraise(OfflineImapError,
|
||||
OfflineImapError(
|
||||
"Could not lock account %s. Is another "
|
||||
"instance using this account?"% self,
|
||||
"instance using this account?" % self,
|
||||
OfflineImapError.ERROR.REPO),
|
||||
exc_info()[2])
|
||||
|
||||
def _unlock(self):
|
||||
"""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:
|
||||
try:
|
||||
portalocker.unlock(self._lockfd)
|
||||
@ -303,7 +304,7 @@ class SyncableAccount(Account):
|
||||
self.ui.error(e, exc_info()[2])
|
||||
except Exception as e:
|
||||
self.ui.error(e, exc_info()[2], msg=
|
||||
"While attempting to sync account '%s'"% self)
|
||||
"While attempting to sync account '%s'" % self)
|
||||
else:
|
||||
# After success sync, reset the looping counter to 3.
|
||||
if self.refreshperiod:
|
||||
@ -321,7 +322,6 @@ class SyncableAccount(Account):
|
||||
remotefolder.getvisiblename().
|
||||
replace(self.remoterepos.getsep(), self.localrepos.getsep()))
|
||||
|
||||
|
||||
# The syncrunner will loop on this method. This means it is called more than
|
||||
# once during the run.
|
||||
def __sync(self):
|
||||
@ -338,7 +338,7 @@ class SyncableAccount(Account):
|
||||
|
||||
if self.utf_8_support and self.remoterepos.getdecodefoldernames():
|
||||
raise OfflineImapError("Configuration mismatch in account " +
|
||||
"'%s'. "% self.getname() +
|
||||
"'%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" +
|
||||
@ -382,7 +382,7 @@ class SyncableAccount(Account):
|
||||
|
||||
if not remotefolder.sync_this:
|
||||
self.ui.debug('', "Not syncing filtered folder '%s'"
|
||||
"[%s]"% (remotefolder.getname(), remoterepos))
|
||||
"[%s]" % (remotefolder.getname(), remoterepos))
|
||||
continue # Ignore filtered folder.
|
||||
|
||||
# The remote folder names must not have the local sep char in
|
||||
@ -393,22 +393,22 @@ class SyncableAccount(Account):
|
||||
sep != remoterepos.getsep() and
|
||||
sep in remotefolder.getname()):
|
||||
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()))
|
||||
continue # Ignore unsupported folder name.
|
||||
|
||||
localfolder = self.get_local_folder(remotefolder)
|
||||
if not localfolder.sync_this:
|
||||
self.ui.debug('', "Not syncing filtered folder '%s'"
|
||||
"[%s]"% (localfolder.getname(), localfolder.repository))
|
||||
"[%s]" % (localfolder.getname(), localfolder.repository))
|
||||
continue # Ignore filtered folder.
|
||||
|
||||
if not globals.options.singlethreading:
|
||||
thread = InstanceLimitedThread(
|
||||
limitNamespace="%s%s"% (
|
||||
limitNamespace="%s%s" % (
|
||||
FOLDER_NAMESPACE, self.remoterepos.getname()),
|
||||
target=syncfolder,
|
||||
name="Folder %s [acc: %s]"% (
|
||||
name="Folder %s [acc: %s]" % (
|
||||
remotefolder.getexplainedname(), self),
|
||||
args=(self, remotefolder, quick)
|
||||
)
|
||||
@ -455,15 +455,15 @@ class SyncableAccount(Account):
|
||||
stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
||||
close_fds=True)
|
||||
r = p.communicate()
|
||||
self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n"% r)
|
||||
self.ui.callhook("Hook return code: %d"% p.returncode)
|
||||
self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n" % r)
|
||||
self.ui.callhook("Hook return code: %d" % p.returncode)
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except Exception as e:
|
||||
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.
|
||||
def syncfolder(account, remotefolder, quick):
|
||||
"""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
|
||||
# transaction.
|
||||
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.
|
||||
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)."""
|
||||
|
||||
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()
|
||||
localfolder.dropmessagelistcache()
|
||||
if len(uids) > 0:
|
||||
@ -564,7 +564,7 @@ def syncfolder(account, remotefolder, quick):
|
||||
if min_uid == None: # min_uid file didn't exist
|
||||
if len(new.getmessageuidlist()) > 0:
|
||||
raise OfflineImapError("To use startdate on Repository %s, "
|
||||
"Repository %s must be empty"%
|
||||
"Repository %s must be empty" %
|
||||
(partial.repository.name, new.repository.name),
|
||||
OfflineImapError.ERROR.MESSAGE)
|
||||
else:
|
||||
@ -581,7 +581,6 @@ def syncfolder(account, remotefolder, quick):
|
||||
else:
|
||||
partial.cachemessagelist(min_uid=min_uid)
|
||||
|
||||
|
||||
remoterepos = account.remoterepos
|
||||
localrepos = account.localrepos
|
||||
statusrepos = account.statusrepos
|
||||
@ -653,7 +652,7 @@ def syncfolder(account, remotefolder, quick):
|
||||
ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder)
|
||||
remotefolder.syncmessagesto(localfolder, statusfolder)
|
||||
else:
|
||||
ui.debug('', "Not syncing to read-only repository '%s'"%
|
||||
ui.debug('', "Not syncing to read-only repository '%s'" %
|
||||
localrepos.getname())
|
||||
|
||||
# Synchronize local changes.
|
||||
@ -661,7 +660,7 @@ def syncfolder(account, remotefolder, quick):
|
||||
ui.syncingmessages(localrepos, localfolder, remoterepos, remotefolder)
|
||||
localfolder.syncmessagesto(remotefolder, statusfolder)
|
||||
else:
|
||||
ui.debug('', "Not syncing to read-only repository '%s'"%
|
||||
ui.debug('', "Not syncing to read-only repository '%s'" %
|
||||
remoterepos.getname())
|
||||
|
||||
statusfolder.save()
|
||||
@ -674,9 +673,9 @@ def syncfolder(account, remotefolder, quick):
|
||||
raise
|
||||
else:
|
||||
ui.error(e, exc_info()[2], msg="Aborting sync, folder '%s' "
|
||||
"[acc: '%s']"% (localfolder, account))
|
||||
"[acc: '%s']" % (localfolder, account))
|
||||
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()))
|
||||
finally:
|
||||
for folder in ["statusfolder", "localfolder", "remotefolder"]:
|
||||
|
Loading…
Reference in New Issue
Block a user