mirror of
https://github.com/niess/python-appimage.git
synced 2026-03-14 04:10:15 +01:00
Locate Tcl/Tk using tclsh
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user