more consistent style

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht
2015-01-01 21:41:11 +01:00
parent 11a28fb0cb
commit 61021260cb
20 changed files with 277 additions and 245 deletions

View File

@ -1,5 +1,5 @@
# Base repository support
# Copyright (C) 2002-2012 John Goerzen & contributors
# Copyright (C) 2002-2015 John Goerzen & contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -18,6 +18,7 @@
import re
import os.path
from sys import exc_info
from offlineimap import CustomConfig
from offlineimap.ui import getglobalui
from offlineimap.error import OfflineImapError
@ -113,6 +114,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
@property
def readonly(self):
"""Is the repository readonly?"""
return self._readonly
def getlocaleval(self):
@ -120,11 +122,13 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
def getfolders(self):
"""Returns a list of ALL folders on this server."""
return []
def forgetfolders(self):
"""Forgets the cached list of folders, if any. Useful to run
after a sync run."""
pass
def getsep(self):
@ -132,6 +136,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
def should_sync_folder(self, fname):
"""Should this folder be synced?"""
return fname in self.folderincludes or self.folderfilter(fname)
def get_create_folders(self):
@ -139,11 +144,13 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
It is disabled by either setting the whole repository
'readonly' or by using the 'createfolders' setting."""
return (not self._readonly) and \
self.getconfboolean('createfolders', True)
def makefolder(self, foldername):
"""Create a new folder"""
raise NotImplementedError
def deletefolder(self, foldername):

View File

@ -1,5 +1,5 @@
# IMAP repository support
# Copyright (C) 2002-2011 John Goerzen & contributors
# Copyright (C) 2002-2015 John Goerzen & contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -15,17 +15,19 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from offlineimap.repository.Base import BaseRepository
from offlineimap import folder, imaputil, imapserver, OfflineImapError
from offlineimap.folder.UIDMaps import MappedIMAPFolder
from offlineimap.threadutil import ExitNotifyThread
from offlineimap.utils.distro import get_os_sslcertfile
from threading import Event
import os
from sys import exc_info
import netrc
import errno
from offlineimap.repository.Base import BaseRepository
from offlineimap import folder, imaputil, imapserver, OfflineImapError
from offlineimap.folder.UIDMaps import MappedIMAPFolder
from offlineimap.threadutil import ExitNotifyThread
from offlineimap.utils.distro import get_os_sslcertfile
class IMAPRepository(BaseRepository):
def __init__(self, reposname, account):
"""Initialize an IMAPRepository object."""
@ -116,14 +118,10 @@ class IMAPRepository(BaseRepository):
"'%s' specified." % self,
OfflineImapError.ERROR.REPO)
def get_remote_identity(self):
"""
Remote identity is used for certain SASL mechanisms
"""Remote identity is used for certain SASL mechanisms
(currently -- PLAIN) to inform server about the ID
we want to authorize as instead of our login name.
"""
we want to authorize as instead of our login name."""
return self.getconf('remote_identity', default=None)
@ -218,13 +216,10 @@ class IMAPRepository(BaseRepository):
return self.getconf('ssl_version', None)
def get_ssl_fingerprint(self):
"""
Return array of possible certificate fingerprints.
"""Return array of possible certificate fingerprints.
Configuration item cert_fingerprint can contain multiple
comma-separated fingerprints in hex form.
"""
comma-separated fingerprints in hex form."""
value = self.getconf('cert_fingerprint', "")
return [f.strip().lower() for f in value.split(',') if f]
@ -262,8 +257,8 @@ class IMAPRepository(BaseRepository):
5. read password from /etc/netrc
On success we return the password.
If all strategies fail we return None.
"""
If all strategies fail we return None."""
# 1. evaluate Repository 'remotepasseval'
passwd = self.getconf('remotepasseval', None)
if passwd != None:
@ -304,7 +299,6 @@ class IMAPRepository(BaseRepository):
# no strategy yielded a password!
return None
def getfolder(self, foldername):
return self.getfoldertype()(self.imapserver, foldername, self)
@ -392,6 +386,7 @@ class IMAPRepository(BaseRepository):
when you are done creating folders yourself.
:param foldername: Full path of the folder to be created."""
if self.getreference():
foldername = self.getreference() + self.getsep() + foldername
if not foldername: # Create top level folder as folder separator

View File

@ -1,6 +1,5 @@
# Local status cache repository support
# Copyright (C) 2002 John Goerzen
# <jgoerzen@complete.org>
# Copyright (C) 2002-2015 John Goerzen & contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -81,7 +80,7 @@ class LocalStatusRepository(BaseRepository):
return '.'
def makefolder(self, foldername):
"""Create a LocalStatus Folder"""
"""Create a LocalStatus Folder."""
if self.account.dryrun:
return # bail out in dry-run mode
@ -114,9 +113,11 @@ class LocalStatusRepository(BaseRepository):
(see getfolderfilename) so we can not derive folder names from
the file names that we have available. TODO: need to store a
list of folder names somehow?"""
pass
def forgetfolders(self):
"""Forgets the cached list of folders, if any. Useful to run
after a sync run."""
self._folders = {}

View File

@ -1,6 +1,5 @@
# Maildir repository support
# Copyright (C) 2002 John Goerzen
# <jgoerzen@complete.org>
# Copyright (C) 2002-2015 John Goerzen & contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -27,6 +26,7 @@ class MaildirRepository(BaseRepository):
def __init__(self, reposname, account):
"""Initialize a MaildirRepository object. Takes a path name
to the directory holding all the Maildir directories."""
BaseRepository.__init__(self, reposname, account)
self.root = self.getlocalroot()
@ -41,6 +41,7 @@ class MaildirRepository(BaseRepository):
def _append_folder_atimes(self, foldername):
"""Store the atimes of a folder's new|cur in self.folder_atimes"""
p = os.path.join(self.root, foldername)
new = os.path.join(p, 'new')
cur = os.path.join(p, 'cur')
@ -51,6 +52,7 @@ class MaildirRepository(BaseRepository):
"""Sets folders' atime back to their values after a sync
Controlled by the 'restoreatime' config parameter."""
if not self.getconfboolean('restoreatime', False):
return # not configured to restore
@ -82,6 +84,7 @@ class MaildirRepository(BaseRepository):
levels will be created if they do not exist yet. 'cur',
'tmp', and 'new' subfolders will be created in the maildir.
"""
self.ui.makefolder(self, foldername)
if self.account.dryrun:
return
@ -134,7 +137,7 @@ class MaildirRepository(BaseRepository):
"folder '%s'." % foldername,
OfflineImapError.ERROR.FOLDER)
def _getfolders_scandir(self, root, extension = None):
def _getfolders_scandir(self, root, extension=None):
"""Recursively scan folder 'root'; return a list of MailDirFolder
:param root: (absolute) path to Maildir root
@ -200,4 +203,5 @@ class MaildirRepository(BaseRepository):
def forgetfolders(self):
"""Forgets the cached list of folders, if any. Useful to run
after a sync run."""
self.folders = None