open file/folder windows
This commit is contained in:
parent
a0b16fc841
commit
b7d784a0f8
1 changed files with 13 additions and 3 deletions
12
oml/utils.py
12
oml/utils.py
|
@ -329,7 +329,7 @@ def run(*cmd):
|
||||||
return p.returncode
|
return p.returncode
|
||||||
|
|
||||||
def get(*cmd):
|
def get(*cmd):
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
stdout, error = p.communicate()
|
stdout, error = p.communicate()
|
||||||
return stdout.decode()
|
return stdout.decode()
|
||||||
|
|
||||||
|
@ -345,8 +345,13 @@ def open_file(path=None):
|
||||||
cmd += ['open', path]
|
cmd += ['open', path]
|
||||||
elif sys.platform.startswith('linux'):
|
elif sys.platform.startswith('linux'):
|
||||||
cmd += ['xdg-open', path]
|
cmd += ['xdg-open', path]
|
||||||
|
elif sys.platform == 'win32':
|
||||||
|
path = '\\'.join(path.split('/'))
|
||||||
|
os.startfile(path)
|
||||||
|
cmd = []
|
||||||
else:
|
else:
|
||||||
logger.debug('unsupported platform %s', sys.platform)
|
logger.debug('unsupported platform %s', sys.platform)
|
||||||
|
if cmd:
|
||||||
subprocess.Popen(cmd, close_fds=True)
|
subprocess.Popen(cmd, close_fds=True)
|
||||||
|
|
||||||
def open_folder(folder=None, path=None):
|
def open_folder(folder=None, path=None):
|
||||||
|
@ -361,8 +366,13 @@ def open_folder(folder=None, path=None):
|
||||||
cmd += ['open', '-R', path]
|
cmd += ['open', '-R', path]
|
||||||
elif sys.platform.startswith('linux'):
|
elif sys.platform.startswith('linux'):
|
||||||
cmd += ['xdg-open', folder]
|
cmd += ['xdg-open', folder]
|
||||||
|
elif sys.platform == 'win32':
|
||||||
|
path = '\\'.join(folder.split('/'))
|
||||||
|
os.system('explorer.exe /select,"%s"' % path)
|
||||||
|
cmd = []
|
||||||
else:
|
else:
|
||||||
logger.debug('unsupported platform %s', sys.platform)
|
logger.debug('unsupported platform %s', sys.platform)
|
||||||
|
if cmd:
|
||||||
subprocess.Popen(cmd, close_fds=True)
|
subprocess.Popen(cmd, close_fds=True)
|
||||||
|
|
||||||
def can_connect_dns(host="8.8.8.8", port=53):
|
def can_connect_dns(host="8.8.8.8", port=53):
|
||||||
|
|
Loading…
Reference in a new issue