|
|
|
@ -1,11 +1,11 @@ |
|
|
|
import subprocess |
|
|
|
from binaryornot.check import is_binary |
|
|
|
from config import config |
|
|
|
import os |
|
|
|
import re |
|
|
|
import shlex |
|
|
|
if __name__ == "__main__": |
|
|
|
__file__ = os.getcwd() |
|
|
|
EDITOR_PATH = os.path.expandvars(r'%programfiles%\Notepad++\notepad++.exe') |
|
|
|
import subprocess |
|
|
|
|
|
|
|
EDITOR_PATH = config.getpath('global','editor') |
|
|
|
EXT = re.compile(r'\.\w+$') |
|
|
|
def get_ext(file): |
|
|
|
match = EXT.search(file) |
|
|
|
@ -13,32 +13,35 @@ def get_ext(file): |
|
|
|
return match.group(0) |
|
|
|
|
|
|
|
def edit(path,params=[]): |
|
|
|
call_chain = [EDITOR_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): |
|
|
|
|
|
|
|
path2windowless = os.path.join(os.path.dirname(__file__),'windowless.vbs') |
|
|
|
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) |
|
|
|
else: |
|
|
|
cwd = os.path.expandvars(cwd) |
|
|
|
if windowless: |
|
|
|
cmd = subprocess.list2cmdline([path]+params).replace('"','~') |
|
|
|
print(cmd) |
|
|
|
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'): |
|
|
|
params = list(map(os.path.expandvars,params)) |
|
|
|
ext = get_ext(path) |
|
|
|
if ext: |
|
|
|
handler = config.getpath(ext,mode) |
|
|
|
handler = shlex.split(handler) |
|
|
|
ext = ext[1:] |
|
|
|
handler = shlex.split(config.getpath(ext,mode)) |
|
|
|
|
|
|
|
args = handler+[path]+params |
|
|
|
subprocess.Popen(args) |