Skip to content

Commit

Permalink
Add diagnose command. Fixes #633.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 16, 2023
1 parent 104c130 commit 769f4dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v24.1.0
-------

* #633: Added ``diagnose`` command with basic support.

v24.0.0
-------

Expand Down
9 changes: 1 addition & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,7 @@ Config file path

The configuration is stored in a file named "keyringrc.cfg"
found in a platform-specific location. To determine
where the config file is stored, run the following::

python -c "import keyring.util.platform_; print(keyring.util.platform_.config_root())"

Some keyrings also store the keyring data in the file system.
To determine where the data files are stored, run::

python -c "import keyring.util.platform_; print(keyring.util.platform_.data_root())"
where the config file is stored, run ``keyring diagnose``.

Config file content
-------------------
Expand Down
15 changes: 14 additions & 1 deletion keyring/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from . import backend
from . import completion
from . import set_keyring, get_password, set_password, delete_password
from .util import platform_


class CommandLineTool:
Expand Down Expand Up @@ -38,7 +39,7 @@ def __init__(self):
)
self.parser.add_argument(
'operation',
choices=["get", "set", "del"],
choices=["get", "set", "del", "diagnose"],
nargs="?",
)
self.parser.add_argument(
Expand All @@ -64,6 +65,10 @@ def run(self, argv):
core.disable()
return

if args.operation == 'diagnose':
self.diagnose()
return

self._check_args()
self._load_spec_backend()
method = getattr(self, f'do_{self.operation}', self.invalid_op)
Expand All @@ -89,6 +94,14 @@ def do_set(self):
def do_del(self):
delete_password(self.service, self.username)

def diagnose(self):
config_root = core._config_path()
if config_root.exists():
print("config path:", config_root)
else:
print("config path:", config_root, "(absent)")
print("data root:", platform_.data_root())

def invalid_op(self):
self.parser.error("Specify operation 'get', 'del', or 'set'.")

Expand Down

0 comments on commit 769f4dc

Please sign in to comment.