Reformat offlineimap/folder/UIDMaps.py
Add some spaces, remove lines,... now format is better (lintian).
This commit is contained in:
parent
eafd9eb51d
commit
3a1b25c204
@ -57,17 +57,17 @@ class MappedIMAPFolder(IMAPFolder):
|
|||||||
|
|
||||||
def _loadmaps(self):
|
def _loadmaps(self):
|
||||||
mapfilename = self._getmapfilename()
|
mapfilename = self._getmapfilename()
|
||||||
mapfilenametmp = "%s.tmp"% mapfilename
|
mapfilenametmp = "%s.tmp" % mapfilename
|
||||||
mapfilenamelock = "%s.lock"% mapfilename
|
mapfilenamelock = "%s.lock" % mapfilename
|
||||||
with self.maplock and open(mapfilenamelock, 'w') as mapfilelock:
|
with self.maplock and open(mapfilenamelock, 'w') as mapfilelock:
|
||||||
try:
|
try:
|
||||||
fnctl.lockf(mapfilelock, fnctl.LOCK_EX) # Blocks until acquired.
|
fnctl.lockf(mapfilelock, fnctl.LOCK_EX) # Blocks until acquired.
|
||||||
except NameError:
|
except NameError:
|
||||||
pass # Windows...
|
pass # Windows...
|
||||||
if os.path.exists(mapfilenametmp):
|
if os.path.exists(mapfilenametmp):
|
||||||
self.ui.warn("a previous run might have leave the UIDMaps file"
|
self.ui.warn("a previous run might have leave the UIDMaps file"
|
||||||
" in incorrect state; some sync operations might be done"
|
" in incorrect state; some sync operations might be done"
|
||||||
" again and some emails might become duplicated.")
|
" again and some emails might become duplicated.")
|
||||||
unlink(mapfilenametmp)
|
unlink(mapfilenametmp)
|
||||||
if not os.path.exists(mapfilename):
|
if not os.path.exists(mapfilename):
|
||||||
return ({}, {})
|
return ({}, {})
|
||||||
@ -82,10 +82,10 @@ class MappedIMAPFolder(IMAPFolder):
|
|||||||
line = line.strip()
|
line = line.strip()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
six.reraise(Exception,
|
six.reraise(Exception,
|
||||||
Exception(
|
Exception(
|
||||||
"Corrupt line '%s' in UID mapping file '%s'"%
|
"Corrupt line '%s' in UID mapping file '%s'" %
|
||||||
(line, mapfilename)),
|
(line, mapfilename)),
|
||||||
exc_info()[2])
|
exc_info()[2])
|
||||||
(str1, str2) = line.split(':')
|
(str1, str2) = line.split(':')
|
||||||
loc = int(str1)
|
loc = int(str1)
|
||||||
rem = int(str2)
|
rem = int(str2)
|
||||||
@ -99,19 +99,19 @@ class MappedIMAPFolder(IMAPFolder):
|
|||||||
|
|
||||||
mapfilename = self._getmapfilename()
|
mapfilename = self._getmapfilename()
|
||||||
# Do not use the map file directly to prevent from leaving it truncated.
|
# Do not use the map file directly to prevent from leaving it truncated.
|
||||||
mapfilenametmp = "%s.tmp"% mapfilename
|
mapfilenametmp = "%s.tmp" % mapfilename
|
||||||
mapfilenamelock = "%s.lock"% mapfilename
|
mapfilenamelock = "%s.lock" % mapfilename
|
||||||
with self.maplock and open(mapfilenamelock, 'w') as mapfilelock:
|
with self.maplock and open(mapfilenamelock, 'w') as mapfilelock:
|
||||||
# The "account" lock already prevents from multiple access by
|
# The "account" lock already prevents from multiple access by
|
||||||
# different processes. However, we still need to protect for
|
# different processes. However, we still need to protect for
|
||||||
# multiple access from different threads.
|
# multiple access from different threads.
|
||||||
try:
|
try:
|
||||||
fnctl.lockf(mapfilelock, fnctl.LOCK_EX) # Blocks until acquired.
|
fnctl.lockf(mapfilelock, fnctl.LOCK_EX) # Blocks until acquired.
|
||||||
except NameError:
|
except NameError:
|
||||||
pass # Windows...
|
pass # Windows...
|
||||||
with open(mapfilenametmp, 'wt') as mapfilefd:
|
with open(mapfilenametmp, 'wt') as mapfilefd:
|
||||||
for (key, value) in list(self.diskl2r.items()):
|
for (key, value) in list(self.diskl2r.items()):
|
||||||
mapfilefd.write("%d:%d\n"% (key, value))
|
mapfilefd.write("%d:%d\n" % (key, value))
|
||||||
if self.dofsync():
|
if self.dofsync():
|
||||||
fsync(mapfilefd)
|
fsync(mapfilefd)
|
||||||
# The lock is released when the file descriptor ends.
|
# The lock is released when the file descriptor ends.
|
||||||
@ -142,14 +142,14 @@ class MappedIMAPFolder(IMAPFolder):
|
|||||||
for luid in list(self.diskl2r.keys()):
|
for luid in list(self.diskl2r.keys()):
|
||||||
if not luid in reallist:
|
if not luid in reallist:
|
||||||
ruid = self.diskl2r[luid]
|
ruid = self.diskl2r[luid]
|
||||||
#XXX: the following KeyError are sightly unexpected. This
|
# XXX: the following KeyError are sightly unexpected. This
|
||||||
# would require more digging to understand how it's
|
# would require more digging to understand how it's
|
||||||
# possible.
|
# possible.
|
||||||
errorMessage = ("unexpected error: key {} was not found "
|
errorMessage = ("unexpected error: key {} was not found "
|
||||||
"in memory, see "
|
"in memory, see "
|
||||||
"https://github.com/OfflineIMAP/offlineimap/issues/445"
|
"https://github.com/OfflineIMAP/offlineimap/issues/445"
|
||||||
" to know more."
|
" to know more."
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
del self.diskr2l[ruid]
|
del self.diskr2l[ruid]
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
@ -268,11 +268,11 @@ class MappedIMAPFolder(IMAPFolder):
|
|||||||
newluid = self._mb.savemessage(-1, content, flags, rtime)
|
newluid = self._mb.savemessage(-1, content, flags, rtime)
|
||||||
if newluid < 1:
|
if newluid < 1:
|
||||||
raise OfflineImapError("server of repository '%s' did not return "
|
raise OfflineImapError("server of repository '%s' did not return "
|
||||||
"a valid UID (got '%s') for UID '%s' from '%s'"% (
|
"a valid UID (got '%s') for UID '%s' from '%s'" % (
|
||||||
self._mb.getname(), newluid, uid, self.getname()
|
self._mb.getname(), newluid, uid, self.getname()
|
||||||
),
|
),
|
||||||
OfflineImapError.ERROR.MESSAGE
|
OfflineImapError.ERROR.MESSAGE
|
||||||
)
|
)
|
||||||
with self.maplock:
|
with self.maplock:
|
||||||
self.diskl2r[newluid] = uid
|
self.diskl2r[newluid] = uid
|
||||||
self.diskr2l[uid] = newluid
|
self.diskr2l[uid] = newluid
|
||||||
@ -315,8 +315,8 @@ class MappedIMAPFolder(IMAPFolder):
|
|||||||
changing the mappings file."""
|
changing the mappings file."""
|
||||||
|
|
||||||
if ruid not in self.r2l:
|
if ruid not in self.r2l:
|
||||||
raise OfflineImapError("Cannot change unknown Maildir UID %s"%
|
raise OfflineImapError("Cannot change unknown Maildir UID %s" %
|
||||||
ruid, OfflineImapError.ERROR.MESSAGE)
|
ruid, OfflineImapError.ERROR.MESSAGE)
|
||||||
if ruid == new_ruid: return # sanity check shortcut
|
if ruid == new_ruid: return # sanity check shortcut
|
||||||
with self.maplock:
|
with self.maplock:
|
||||||
luid = self.r2l[ruid]
|
luid = self.r2l[ruid]
|
||||||
@ -351,7 +351,7 @@ class MappedIMAPFolder(IMAPFolder):
|
|||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def deletemessagesflags(self, uidlist, flags):
|
def deletemessagesflags(self, uidlist, flags):
|
||||||
self._mb.deletemessagesflags(self._uidlist(self.r2l, uidlist),
|
self._mb.deletemessagesflags(self._uidlist(self.r2l, uidlist),
|
||||||
flags)
|
flags)
|
||||||
|
|
||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def deletemessage(self, uid):
|
def deletemessage(self, uid):
|
||||||
|
Loading…
Reference in New Issue
Block a user