Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Use cross-platform config file paths #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Dependencies
============

- Python 3
- ``appdirs``
- ``websocket-client`` (optional, for 2016+ TVs)
- ``curses`` (optional, for the interactive mode)

Expand Down Expand Up @@ -84,8 +85,9 @@ arguments:
E.g. samsungctl --host 192.168.0.10 --name myremote KEY_VOLDOWN

The settings can be loaded from a configuration file. The file is searched from
``$XDG_CONFIG_HOME/samsungctl.conf``, ``~/.config/samsungctl.conf``, and
``/etc/samsungctl.conf`` in this order. A simple default configuration is
a user specific path (usually ``~/.config/samsungctl.conf``) and if that is not
found then from a system-wide path (usually
``/etc/xdg/samsungctl/samsungctl.conf``). A simple default configuration is
bundled with the source as `samsungctl.conf <samsungctl.conf>`_.

Library usage
Expand Down
9 changes: 3 additions & 6 deletions samsungctl/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import appdirs
import argparse
import collections
import json
Expand All @@ -23,12 +24,8 @@ def _read_config():
file_loaded = False
directories = []

xdg_config = os.getenv("XDG_CONFIG_HOME")
if xdg_config:
directories.append(xdg_config)

directories.append(os.path.join(os.getenv("HOME"), ".config"))
directories.append("/etc")
directories.append(appdirs.user_config_dir())
directories.append(appdirs.site_config_dir(title))

for directory in directories:
try:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"console_scripts": ["samsungctl=samsungctl.__main__:main"]
},
packages=["samsungctl"],
install_requires=[],
install_requires=["appdirs"],
extras_require={
"websocket": ["websocket-client"],
"interactive_ui": ["curses"],
Expand Down