You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
from binaryornot.check import is_binary
|
|
from config import config
|
|
import os
|
|
import shlex
|
|
import subprocess
|
|
|
|
EDITOR_PATH = config.getpath('global','editor')
|
|
def get_ext(file):
|
|
ext = os.path.splitext(file)[-1]
|
|
if ext != '':
|
|
return ext
|
|
|
|
def edit(path,params=[]):
|
|
params = list(map(os.path.expandvars,params))
|
|
call_chain = shlex.split(EDITOR_PATH)
|
|
if not is_binary(path):
|
|
call_chain.append(path)
|
|
subprocess.call(call_chain)
|
|
|
|
def standalone(path,params=[],windowless =False,cwd = None):
|
|
if __name__ == "__main__":
|
|
path2windowless = 'windowless.vbs'
|
|
else:
|
|
path2windowless = os.path.join(os.path.dirname(__file__),'windowless.vbs')
|
|
params = list(map(os.path.expandvars,params))
|
|
if not cwd:
|
|
cwd = os.path.dirname(path)
|
|
if cwd == '':
|
|
cwd = os.getcwd()
|
|
else:
|
|
cwd = os.path.expandvars(cwd)
|
|
if windowless:
|
|
cmd = cmd = subprocess.list2cmdline([path]+params).replace('"','~')
|
|
subprocess.check_output(['cscript.exe',path2windowless,cmd,cwd])
|
|
else:
|
|
|
|
subprocess.Popen([path]+params,cwd=cwd)
|
|
|
|
def dependant(path,params=[],mode = 'execute',cwd = None):
|
|
if not cwd:
|
|
cwd = os.path.dirname(path)
|
|
if cwd == '':
|
|
cwd = os.getcwd()
|
|
params = list(map(os.path.expandvars,params))
|
|
ext = get_ext(path)
|
|
if ext:
|
|
ext = ext[1:]
|
|
handler = shlex.split(config.getpath(ext,mode))
|
|
|
|
args = handler+[path]+params
|
|
subprocess.Popen(args,cwd=cwd)
|