Skip to content

Commit

Permalink
setup: fix generation of init templates (#4209)
Browse files Browse the repository at this point in the history
if an init file ends in any of the letters [tmpl] these will be stripped
in addition to the .tmpl extension.

This is documented behaviour of the str.rstrip() method.
This PR fixes it by using os.path.splitext() (rather than
str.removesuffix which is only available in python 3.9+)

Sponsored by: The FreeBSD Foundation

* BSD*: render sysvinit scripts execubable
  • Loading branch information
igalic authored Jun 29, 2023
1 parent cce37f6 commit c70ea01
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def render_tmpl(template, mode=None):
topdir = os.path.dirname(sys.argv[0])
tmpd = tempfile.mkdtemp(dir=topdir, prefix=RENDERED_TMPD_PREFIX)
atexit.register(shutil.rmtree, tmpd)
bname = os.path.basename(template).rstrip(tmpl_ext)
bname = os.path.basename(template)
ename, ext = os.path.splitext(bname)
if ext == tmpl_ext:
bname = ename
fpath = os.path.join(tmpd, bname)
cmd_variant = []
cmd_prefix = []
Expand Down Expand Up @@ -164,10 +167,14 @@ def render_tmpl(template, mode=None):
INITSYS_FILES = {
"sysvinit": [f for f in glob("sysvinit/redhat/*") if is_f(f)],
"sysvinit_freebsd": [
render_tmpl(f) for f in glob("sysvinit/freebsd/*") if is_f(f)
render_tmpl(f, mode=0o755)
for f in glob("sysvinit/freebsd/*")
if is_f(f)
],
"sysvinit_netbsd": [
render_tmpl(f) for f in glob("sysvinit/netbsd/*") if is_f(f)
render_tmpl(f, mode=0o755)
for f in glob("sysvinit/netbsd/*")
if is_f(f)
],
"sysvinit_deb": [f for f in glob("sysvinit/debian/*") if is_f(f)],
"sysvinit_openrc": [f for f in glob("sysvinit/gentoo/*") if is_f(f)],
Expand Down

0 comments on commit c70ea01

Please sign in to comment.