From feda0993d852ccb450c4d59312159bb6bf2a311b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 6 Feb 2015 15:44:54 -0500 Subject: [PATCH 1/2] config: add support for XDG paths Prefers the XDG paths if they exist, but falls back to ~/.bugwarriorrc if it exists. --- bugwarrior/config.py | 10 +++++++++- setup.py | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bugwarrior/config.py b/bugwarrior/config.py index a84741f57..a986a00b2 100644 --- a/bugwarrior/config.py +++ b/bugwarrior/config.py @@ -8,6 +8,7 @@ import twiggy from twiggy import log from twiggy.levels import name2level +from xdg import BaseDirectory def asbool(some_value): @@ -131,9 +132,16 @@ def validate_config(config): def load_config(): config = ConfigParser({'log.level': "DEBUG", 'log.file': None}) + path = os.path.join(BaseDirectory.load_first_config('bugwarrior'), 'bugwarriorrc') + old_path = os.path.expanduser("~/.bugwarriorrc") + if path is None or not os.path.exists(path): + if os.path.exists(old_path): + path = old_path + else: + path = os.path.join(BaseDirectory.save_config_path('bugwarrior'), 'bugwarriorrc') config.readfp( codecs.open( - os.path.expanduser("~/.bugwarriorrc"), + path, "r", "utf-8", ) diff --git a/setup.py b/setup.py index 0255bcf01..8bacb1138 100644 --- a/setup.py +++ b/setup.py @@ -43,6 +43,7 @@ "dogpile.cache>=0.5.3", "lockfile>=0.9.1", "click", + "pyxdg", ], tests_require=[ "Mock", From 07148bce5cafdf6d69225e71eb14c7c8ce86f16a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 6 Feb 2015 15:45:34 -0500 Subject: [PATCH 2/2] docs: update references to .bugwarriorrc Just call the file by its basename. --- bugwarrior/command.py | 4 ++-- bugwarrior/config.py | 7 +++++-- bugwarrior/docs/common_configuration.rst | 2 +- bugwarrior/docs/configuration.rst | 2 +- bugwarrior/docs/using.rst | 2 +- bugwarrior/services/activecollab2.py | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bugwarrior/command.py b/bugwarrior/command.py index 4b6e5e64a..0b730bd20 100644 --- a/bugwarrior/command.py +++ b/bugwarrior/command.py @@ -28,7 +28,7 @@ def pull(dry_run): """ Pull down tasks from forges and add them to your taskwarrior tasks. - Relies on configuration in ~/.bugwarriorrc + Relies on configuration in bugwarriorrc """ twiggy.quickSetup() try: @@ -93,7 +93,7 @@ def targets(): @vault.command() def list(): pws = lst(targets()) - print "%i @oracle:use_keyring passwords in .bugwarriorrc" % len(pws) + print "%i @oracle:use_keyring passwords in bugwarriorrc" % len(pws) for section in pws: print "-", section diff --git a/bugwarrior/config.py b/bugwarrior/config.py index a986a00b2..ff9d37801 100644 --- a/bugwarrior/config.py +++ b/bugwarrior/config.py @@ -82,7 +82,7 @@ def load_example_rc(): error_template = """ ************************************************* -* There was a problem with your ~/.bugwarriorrc * +* There was a problem with your bugwarriorrc * * {msg} * Here's an example template to help: * ************************************************* @@ -132,7 +132,10 @@ def validate_config(config): def load_config(): config = ConfigParser({'log.level': "DEBUG", 'log.file': None}) - path = os.path.join(BaseDirectory.load_first_config('bugwarrior'), 'bugwarriorrc') + path = None + first_path = BaseDirectory.load_first_config('bugwarrior') + if first_path is not None: + path = os.path.join(first_path, 'bugwarriorrc') old_path = os.path.expanduser("~/.bugwarriorrc") if path is None or not os.path.exists(path): if os.path.exists(old_path): diff --git a/bugwarrior/docs/common_configuration.rst b/bugwarrior/docs/common_configuration.rst index 6ab42e23b..176194426 100644 --- a/bugwarrior/docs/common_configuration.rst +++ b/bugwarrior/docs/common_configuration.rst @@ -101,7 +101,7 @@ regardless of what project was assigned by the service itself:: Password Management ------------------- -You need not store your password in plain text in your `~/.bugwarriorrc` file; +You need not store your password in plain text in your `bugwarriorrc` file; you can enter the following values to control where to gather your password from: diff --git a/bugwarrior/docs/configuration.rst b/bugwarrior/docs/configuration.rst index 2674e640a..0cb53f49b 100644 --- a/bugwarrior/docs/configuration.rst +++ b/bugwarrior/docs/configuration.rst @@ -7,7 +7,7 @@ Example Configuration :: - # Example ~/.bugwarriorrc + # Example bugwarriorrc # General stuff. [general] diff --git a/bugwarrior/docs/using.rst b/bugwarrior/docs/using.rst index 262bff0eb..db579ceb2 100644 --- a/bugwarrior/docs/using.rst +++ b/bugwarrior/docs/using.rst @@ -8,7 +8,7 @@ It's ideal to create a cron task like:: */15 * * * * /usr/bin/bugwarrior-pull Bugwarrior can emit desktop notifications when it adds or completes issues -to and from your local ``~/.task/`` db. If your ``~/.bugwarriorrc`` file has +to and from your local ``~/.task/`` db. If your ``bugwarriorrc`` file has notifications turned on, you'll also need to tell cron which display to use by adding the following to your crontab:: diff --git a/bugwarrior/services/activecollab2.py b/bugwarrior/services/activecollab2.py index 6ef9e778f..592e43193 100644 --- a/bugwarrior/services/activecollab2.py +++ b/bugwarrior/services/activecollab2.py @@ -45,7 +45,7 @@ def get_issue_generator(self, user_id, project_id, project_name): """ Approach: - 1. Get user ID from .bugwarriorrc file + 1. Get user ID from bugwarriorrc file 2. Get list of tickets from /user-tasks for a given project 3. For each ticket/task returned from #2, get ticket/task info and check if logged-in user is primary (look at `is_owner` and