Skip to content

Commit 528f797

Browse files
committed
Locate Tcl/Tk using tclsh
1 parent d7fe43f commit 528f797

3 files changed

Lines changed: 36 additions & 21 deletions

File tree

‎python_appimage/appimage/relocate.py‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def _get_tk_version(python_pkg):
3434
raise RuntimeError('could not guess Tcl/Tk version')
3535

3636

37+
def _get_tk_libdir(version):
38+
try:
39+
library = system(('tclsh' + version,), stdin='puts [info library]')
40+
except SystemError:
41+
raise RuntimeError('could not locate Tcl/Tk' + version + ' library')
42+
43+
return os.path.dirname(library)
44+
45+
3746
def tcltk_env_string(python_pkg):
3847
'''Environment for using AppImage's TCl/Tk
3948
'''
@@ -280,22 +289,13 @@ def relocate_python(python=None, appdir=None):
280289
tcltkdir = APPDIR_SHARE + '/tcltk'
281290
if (not os.path.exists(tcltkdir + '/tcl' + tk_version)) or \
282291
(not os.path.exists(tcltkdir + '/tk' + tk_version)):
283-
hostdir = '/usr/share/tcltk'
284-
if os.path.exists(hostdir):
285-
make_tree(APPDIR_SHARE)
286-
copy_tree(hostdir, tcltkdir)
287-
else:
288-
make_tree(tcltkdir)
289-
tclpath = '/usr/share/tcl' + tk_version
290-
if not tclpath:
291-
raise ValueError('could not find ' + tclpath)
292-
copy_tree(tclpath, tcltkdir + '/tcl' + tk_version)
293-
294-
tkpath = '/usr/share/tk' + tk_version
295-
if not tkpath:
296-
raise ValueError('could not find ' + tkpath)
297-
copy_tree(tkpath, tcltkdir + '/tk' + tk_version)
298-
292+
libdir = _get_tk_libdir(tk_version)
293+
log('INSTALL', 'Tcl/Tk' + tk_version)
294+
make_tree(tcltkdir)
295+
tclpath = libdir + '/tcl' + tk_version
296+
copy_tree(tclpath, tcltkdir + '/tcl' + tk_version)
297+
tkpath = libdir + '/tk' + tk_version
298+
copy_tree(tkpath, tcltkdir + '/tk' + tk_version)
299299

300300
# Copy any SSL certificate
301301
cert_file = os.getenv('SSL_CERT_FILE')

‎python_appimage/utils/compat.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22

33

4-
__all__ = ['decode', 'find_spec']
4+
__all__ = ['decode', 'encode', 'find_spec']
55

66

77
def decode(s):
@@ -13,6 +13,15 @@ def decode(s):
1313
return str(s)
1414

1515

16+
def encode(s):
17+
'''Encode Python 3 str as bytes
18+
'''
19+
try:
20+
return s.encode()
21+
except Exception:
22+
return str(s)
23+
24+
1625
if sys.version_info[0] == 2:
1726
from collections import namedtuple
1827
import imp

‎python_appimage/utils/system.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33
import subprocess
44

5-
from .compat import decode
5+
from .compat import decode, encode
66
from .log import debug, log
77

88

@@ -15,7 +15,7 @@
1515
basestring = (str, bytes)
1616

1717

18-
def system(args, exclude=None):
18+
def system(args, exclude=None, stdin=None):
1919
'''System call with capturing output
2020
'''
2121
cmd = ' '.join(args)
@@ -29,9 +29,15 @@ def system(args, exclude=None):
2929
exclude = list(exclude)
3030
exclude.append('fuse: warning:')
3131

32+
if stdin:
33+
in_arg = subprocess.PIPE
34+
stdin = encode(stdin)
35+
else:
36+
in_arg = None
37+
3238
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
33-
stderr=subprocess.PIPE)
34-
out, err = p.communicate()
39+
stderr=subprocess.PIPE, stdin=in_arg)
40+
out, err = p.communicate(input=stdin)
3541
if err:
3642
err = decode(err)
3743
stripped = [line for line in err.split(os.linesep) if line]

0 commit comments

Comments
 (0)