Browse Source

Added dependant

(function to open files that require another executable)
master
Raphael Roberts 7 years ago
parent
commit
6e61c9dafb
  1. 33
      ext_open.py

33
ext_open.py

@ -1,7 +1,23 @@
import subprocess
from binaryornot.check import is_binary
import os
EDITOR_PATH =
import re
EDITOR_PATH = os.path.expandvars(r'%programfiles%\Notepad++\notepad++.exe')
EXT = re.compile(r'\.\w+$')
def get_ext(file):
match = EXT.search(file)
if match:
return match.group(0)
handlers = {
'.py' : {
'editor': EDITOR_PATH,
'execute': 'python',
'idle_edit': 'pythonw -m idlelib -e',
'windowless': 'pythonw'
}
}
def edit(path,params=[]):
call_chain = [EDITOR_PATH] + params
if not is_binary(path):
@ -19,7 +35,18 @@ def standalone(path,params=[],windowless =False,cwd = None):
if windowless:
cmd = ' '.join('~{}~'.format(arg) if ' ' in arg else arg for arg in [fullpath]+params)
print(cmd)
subprocess.check_output(["cscript.exe",path2windowless,cmd,cwd])
subprocess.check_output(['cscript.exe',path2windowless,cmd,cwd])
else:
subprocess.Popen([fullpath]+params,cwd=cwd)
subprocess.Popen([fullpath]+params,cwd=cwd)
def dependant(path,params=[],mode = 'execute'):
ext = get_ext(path)
if ext:
handler = handlers[ext][mode]
if ' ' in handler:
handler = handler.split(' ')
else:
handler = [handler]
args = handler+[path]+params
subprocess.Popen(args)
Loading…
Cancel
Save