Add support for XDG Base Directory Specification

$XDG_CONFIG_HOME/offlineimap/config will now be tried before
the canonical ~/.offlineimaprc.

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
This commit is contained in:
Eygene Ryabinkin 2014-05-07 00:40:59 +04:00
parent d96af192ed
commit 5150de5514
5 changed files with 38 additions and 4 deletions

View File

@ -16,6 +16,10 @@ OfflineIMAP v6.5.6 (YYYY-MM-DD)
adds mechanics to change message labels (Abdó Roig-Maranges) adds mechanics to change message labels (Abdó Roig-Maranges)
* Allow to migrate status data across differend backends * Allow to migrate status data across differend backends
(Abdó Roig-Maranges) (Abdó Roig-Maranges)
* Support XDG Base Directory Specification
(if $XDG_CONFIG_HOME/offlineimap/config exists, use it as the
default configuration path; ~/.offlineimaprc is still tried after
XDG location) (GitHub#32)
OfflineIMAP v6.5.5 (2013-10-07) OfflineIMAP v6.5.5 (2013-10-07)

View File

@ -74,6 +74,13 @@ to do is specify a directory for your folders to be in (on the localfolders
line), the host name of your IMAP server (on the remotehost line), and your line), the host name of your IMAP server (on the remotehost line), and your
login name on the remote (on the remoteuser line). That's it! login name on the remote (on the remoteuser line). That's it!
If you prefer to be XDG-compatible,
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
then substitute the above ``~/.offlineimaprc'' with
``$XDG\_CONFIG\_HOME/offlineimap/config'' and don't forget to set
XDG\_CONFIG\_HOME properly if you want it to be different from
the default ``$HOME/.config'' for any reason.
To run OfflineIMAP, you just have to say `offlineimap` ― it will fire To run OfflineIMAP, you just have to say `offlineimap` ― it will fire
up, ask you for a login password if necessary, synchronize your folders, up, ask you for a login password if necessary, synchronize your folders,
and exit. See? and exit. See?

View File

@ -63,6 +63,9 @@ set, and you can read about other features later with `offlineimap.conf`.
Check out the `Use Cases`_ section for some example configurations. Check out the `Use Cases`_ section for some example configurations.
If you want to be XDG-compatible, you can put your configuration file into
`$XDG_CONFIG_HOME/offlineimap/config`.
OPTIONS OPTIONS
======= =======

View File

@ -77,6 +77,15 @@ based in instructions submitted by Chris Walker::
That URL also has more details on making OfflineIMAP work with Windows. That URL also has more details on making OfflineIMAP work with Windows.
Does OfflineIMAP supports XDG Base Directory specification?
-----------------------------------------------------------
Yes. We are trying to use `$XDG_CONFIG_HOME/offlineimap/config`
as the primary configuration file, falling back to `~/.offlineimaprc`
if configuration file location was not explicitely specified at the
command line.
Does OfflineIMAP support mbox, mh, or anything else other than Maildir? Does OfflineIMAP support mbox, mh, or anything else other than Maildir?
----------------------------------------------------------------------- -----------------------------------------------------------------------

View File

@ -101,9 +101,8 @@ class OfflineImap:
"or to sync some accounts that you normally prefer not to.") "or to sync some accounts that you normally prefer not to.")
parser.add_option("-c", dest="configfile", metavar="FILE", parser.add_option("-c", dest="configfile", metavar="FILE",
default="~/.offlineimaprc", default=None,
help="Specifies a configuration file to use in lieu of " help="Specifies a configuration file to use")
"%default.")
parser.add_option("-d", dest="debugtype", metavar="type1,[type2...]", parser.add_option("-d", dest="debugtype", metavar="type1,[type2...]",
help="Enables debugging for OfflineIMAP. This is useful " help="Enables debugging for OfflineIMAP. This is useful "
@ -165,6 +164,18 @@ class OfflineImap:
globals.set_options (options) globals.set_options (options)
#read in configuration file #read in configuration file
if not options.configfile:
# Try XDG location, then fall back to ~/.offlineimaprc
xdg_var = 'XDG_CONFIG_HOME'
if not xdg_var in os.environ or not os.environ[xdg_var]:
xdg_home = os.path.expanduser('~/.config')
else:
xdg_home = os.environ[xdg_var]
options.configfile = os.path.join(xdg_home, "offlineimap", "config")
if not os.path.exists(options.configfile):
options.configfile = os.path.expanduser('~/.offlineimaprc')
configfilename = options.configfile
else:
configfilename = os.path.expanduser(options.configfile) configfilename = os.path.expanduser(options.configfile)
config = CustomConfigParser() config = CustomConfigParser()