Install linkcheckerrc in the package data

data/__init__.py needed for Python < 3.10
(namespace packages supported from importlib_resources v3.2)
This commit is contained in:
Chris Mayo 2021-12-30 19:27:04 +00:00
parent 5c0d66dd74
commit 819dacb9bb
6 changed files with 22 additions and 23 deletions

View file

@ -11,6 +11,7 @@ include .project
include .pydevproject
include .yamllint
include _release_date
include linkcheck/data/linkcheckerrc
recursive-include cgi-bin \
*.css \
@ -23,8 +24,7 @@ recursive-include cgi-bin \
recursive-include config \
*.sql \
linkchecker-completion \
linkchecker.apache2.conf \
linkcheckerrc
linkchecker.apache2.conf
recursive-include doc \
*.1 \
*.5 \

View file

@ -42,6 +42,8 @@ from .logconf import (
)
import _LinkChecker_configdata as configdata
PACKAGE_NAME = __package__
def module_path():
"""Return absolute directory of system executable."""

View file

@ -17,13 +17,14 @@
Store metadata and options.
"""
import importlib.resources
import os
import re
import urllib.parse
import shutil
import socket
import _LinkChecker_configdata as configdata
from .. import log, LOG_CHECK, get_install_data, fileutil
from .. import log, LOG_CHECK, PACKAGE_NAME, fileutil
from . import confparse
from xdg.BaseDirectory import xdg_config_home, xdg_data_home
@ -89,11 +90,6 @@ def get_modules_info():
return "Modules: %s" % (", ".join(module_infos))
def get_share_dir():
"""Return absolute path of LinkChecker example configuration."""
return os.path.join(get_install_data(), "share", "linkchecker")
def get_system_cert_file():
"""Try to find a system-wide SSL certificate file.
@return: the filename to the cert file
@ -368,8 +364,6 @@ def get_user_config():
@return configuration filename
@rtype string
"""
# initial config (with all options explained)
initialconf = normpath(os.path.join(get_share_dir(), "linkcheckerrc"))
# per user config settings
homedotfile = normpath("~/.linkchecker/linkcheckerrc")
userconf = (
@ -377,18 +371,21 @@ def get_user_config():
if os.path.isfile(homedotfile)
else os.path.join(xdg_config_home, "linkchecker", "linkcheckerrc")
)
if os.path.isfile(initialconf) and not os.path.exists(userconf):
# copy the initial configuration to the user configuration
try:
make_userdir(userconf)
shutil.copy(initialconf, userconf)
except Exception as errmsg:
msg = _(
"could not copy initial configuration file %(src)r"
" to %(dst)r: %(errmsg)r"
)
args = dict(src=initialconf, dst=userconf, errmsg=errmsg)
log.warn(LOG_CHECK, msg % args)
if not os.path.exists(userconf):
# initial config (with all options explained)
with importlib.resources.path(
f"{PACKAGE_NAME}.data", "linkcheckerrc") as initialconf:
# copy the initial configuration to the user configuration
try:
make_userdir(userconf)
shutil.copy(initialconf, userconf)
except Exception as errmsg:
msg = _(
"could not copy initial configuration file %(src)r"
" to %(dst)r: %(errmsg)r"
)
args = dict(src=initialconf, dst=userconf, errmsg=errmsg)
log.warn(LOG_CHECK, msg % args)
return userconf

View file

View file

@ -294,7 +294,6 @@ myname = "LinkChecker Authors"
myemail = ""
data_files = [
("share/linkchecker", ["config/linkcheckerrc"]),
(
"share/linkchecker/examples",
[
@ -358,6 +357,7 @@ setup(
]
},
data_files=data_files,
include_package_data=True,
classifiers=[
"Topic :: Internet :: WWW/HTTP :: Site Management :: Link Checking",
"Development Status :: 5 - Production/Stable",