dropping python-xdg dependancy. It’s easier to implement our own version of it

This commit is contained in:
Lionel Dricot 2022-03-08 10:14:36 +01:00
parent 7de6cf5d1f
commit 672a1a9c4b
3 changed files with 19 additions and 25 deletions

View File

@ -4,8 +4,9 @@
- Content and pictures now centered for more elegant reading
- "less" has been renamed "view"
- "view feed" and "view feeds" to see the first/all feeds on a HTML page
- "view full" has been improved by dropping inline CSSand JS.
- Fixed a crash when accessing links in list (thanks Matthieu Talbot for the report)
- Fixed a crash due to a typo in a variable name rarely accessed.
- Fixed a crash in "info" due to a typo in a variable name rarely accessed.
## 0.9 - March 05th 2022
- Initial Spartan protocol support

View File

@ -73,7 +73,6 @@ To avoid using unstable or too recent libraries, the rule of thumb is that a lib
Run command `version` in offpunk to see if you are missing some dependencies.
* [Python-xdg](https://www.freedesktop.org/wiki/Software/pyxdg) will place your data, config and cache in place recommended by the XDG specs (usually its .local/share/offpunk, .config/offpunk and .cache/offpunk). Without it, look for ~/.offpunk or ~/.config/offpunk while the cache will be in ~/.cache/offpunk/. If installation is done later, some config files may need to be migrated by hand.
* [xdg-utils](https://www.freedesktop.org/wiki/Software/xdg-utils/) provides xdg-open which is highly recommended to open files without a renderer or a handler. It is also used for mailto: command.
* [Python-requests](http://python-requests.org) is needed to handle http/https requests natively (apt-get install python3-requests). Without it, http links will be opened in an external browser
* [BeautifulSoup4](https://www.crummy.com/software/BeautifulSoup) and [Readability](https://github.com/buriy/python-readability) are both needed to render HTML. Without them, HTML will not be rendered or be sent to an external parser like Lynx. (apt-get install python3-bs4 python3-readability or pip3 install readability-lxml)

View File

@ -157,28 +157,23 @@ except ModuleNotFoundError:
_DO_FEED = False
## Config directories
# There are two conflicting xdg modules, we try to work with both
try:
from xdg import BaseDirectory
_HAS_XDG = True
_CACHE_PATH = BaseDirectory.save_cache_path("offpunk/")
_CONFIG_DIR = BaseDirectory.save_config_path("offpunk/")
_DATA_DIR = BaseDirectory.save_data_path("offpunk/")
except ModuleNotFoundError:
_HAS_XDG = False
_CACHE_PATH = os.path.expanduser("~/.cache/offpunk/")
_CONFIG_DIR = None
## Look for pre-existing config directory, if any
for confdir in ("~/.offpunk/", "~/.config/offpunk/"):
confdir = os.path.expanduser(confdir)
if os.path.exists(confdir):
_CONFIG_DIR = confdir
break
## Otherwise, make one in .config if it exists
if not _CONFIG_DIR and os.path.exists("~/.config/"):
_CONFIG_DIR = os.path.expanduser("~/.config/offpunk/")
elif not _CONFIG_DIR:
_CONFIG_DIR = os.path.expanduser("~/.offpunk/")
## We implement our own python-xdg to avoid conflict with existing libraries.
_home = os.path.expanduser('~')
data_home = os.environ.get('XDG_DATA_HOME') or \
os.path.join(_home,'.local','share')
config_home = os.environ.get('XDG_CONFIG_HOME') or \
os.path.join(_home,'.config')
cache_home = os.environ.get('XDG_CACHE_HOME') or\
os.path.join(_home,'.cache')
_CACHE_PATH = os.path.join(cache_home,"offpunk/")
_CONFIG_DIR = os.path.join(config_home,"offpunk/")
_DATA_DIR = os.path.join(data_home,"offpunk/")
_old_config = os.path.expanduser("~/.offpunk/")
## Look for pre-existing config directory, if any
if os.path.exists(_old_config):
_CONFIG_DIR = _old_config
#if no XDG .local/share and not XDG .config, we use the old config
if not os.path.exists(data_home) and os.path.exists(_old_config):
_DATA_DIR = _CONFIG_DIR
for f in [_CONFIG_DIR, _CACHE_PATH, _DATA_DIR]:
if not os.path.exists(f):
@ -2780,7 +2775,6 @@ Think of it like marks in vi: 'mark a'='ma' and 'go a'=''a'."""
output += " - python-feedparser : " + has(_DO_FEED)
output += " - python-bs4 : " + has(_HAS_SOUP)
output += " - python-readability : " + has(_HAS_READABILITY)
output += " - python-xdg : " + has(_HAS_XDG)
output += " - python-setproctitle : " + has(_HAS_SETPROCTITLE)
output += " - xdg-open : " + has(_HAS_XDGOPEN)
output += " - chafa : " + has(_HAS_CHAFA)