Locate Tcl/Tk using tclsh

This commit is contained in:
Valentin Niess
2022-09-08 10:27:03 +02:00
parent d7fe43facf
commit 528f797ddf
3 changed files with 36 additions and 21 deletions

View File

@@ -34,6 +34,15 @@ def _get_tk_version(python_pkg):
raise RuntimeError('could not guess Tcl/Tk version')
def _get_tk_libdir(version):
try:
library = system(('tclsh' + version,), stdin='puts [info library]')
except SystemError:
raise RuntimeError('could not locate Tcl/Tk' + version + ' library')
return os.path.dirname(library)
def tcltk_env_string(python_pkg):
'''Environment for using AppImage's TCl/Tk
'''
@@ -280,22 +289,13 @@ def relocate_python(python=None, appdir=None):
tcltkdir = APPDIR_SHARE + '/tcltk'
if (not os.path.exists(tcltkdir + '/tcl' + tk_version)) or \
(not os.path.exists(tcltkdir + '/tk' + tk_version)):
hostdir = '/usr/share/tcltk'
if os.path.exists(hostdir):
make_tree(APPDIR_SHARE)
copy_tree(hostdir, tcltkdir)
else:
make_tree(tcltkdir)
tclpath = '/usr/share/tcl' + tk_version
if not tclpath:
raise ValueError('could not find ' + tclpath)
copy_tree(tclpath, tcltkdir + '/tcl' + tk_version)
tkpath = '/usr/share/tk' + tk_version
if not tkpath:
raise ValueError('could not find ' + tkpath)
copy_tree(tkpath, tcltkdir + '/tk' + tk_version)
libdir = _get_tk_libdir(tk_version)
log('INSTALL', 'Tcl/Tk' + tk_version)
make_tree(tcltkdir)
tclpath = libdir + '/tcl' + tk_version
copy_tree(tclpath, tcltkdir + '/tcl' + tk_version)
tkpath = libdir + '/tk' + tk_version
copy_tree(tkpath, tcltkdir + '/tk' + tk_version)
# Copy any SSL certificate
cert_file = os.getenv('SSL_CERT_FILE')

View File

@@ -1,7 +1,7 @@
import sys
__all__ = ['decode', 'find_spec']
__all__ = ['decode', 'encode', 'find_spec']
def decode(s):
@@ -13,6 +13,15 @@ def decode(s):
return str(s)
def encode(s):
'''Encode Python 3 str as bytes
'''
try:
return s.encode()
except Exception:
return str(s)
if sys.version_info[0] == 2:
from collections import namedtuple
import imp

View File

@@ -2,7 +2,7 @@ import os
import re
import subprocess
from .compat import decode
from .compat import decode, encode
from .log import debug, log
@@ -15,7 +15,7 @@ except NameError:
basestring = (str, bytes)
def system(args, exclude=None):
def system(args, exclude=None, stdin=None):
'''System call with capturing output
'''
cmd = ' '.join(args)
@@ -29,9 +29,15 @@ def system(args, exclude=None):
exclude = list(exclude)
exclude.append('fuse: warning:')
if stdin:
in_arg = subprocess.PIPE
stdin = encode(stdin)
else:
in_arg = None
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
stderr=subprocess.PIPE, stdin=in_arg)
out, err = p.communicate(input=stdin)
if err:
err = decode(err)
stripped = [line for line in err.split(os.linesep) if line]