From b7d784a0f863c9527024afb3149be9bbb033c371 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 31 Jan 2016 18:53:11 +0530 Subject: [PATCH] open file/folder windows --- oml/utils.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/oml/utils.py b/oml/utils.py index 3e13db3..7ea7fac 100644 --- a/oml/utils.py +++ b/oml/utils.py @@ -329,7 +329,7 @@ def run(*cmd): return p.returncode 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() return stdout.decode() @@ -345,9 +345,14 @@ def open_file(path=None): cmd += ['open', path] elif sys.platform.startswith('linux'): cmd += ['xdg-open', path] + elif sys.platform == 'win32': + path = '\\'.join(path.split('/')) + os.startfile(path) + cmd = [] else: logger.debug('unsupported platform %s', sys.platform) - subprocess.Popen(cmd, close_fds=True) + if cmd: + subprocess.Popen(cmd, close_fds=True) def open_folder(folder=None, path=None): cmd = [] @@ -361,9 +366,14 @@ def open_folder(folder=None, path=None): cmd += ['open', '-R', path] elif sys.platform.startswith('linux'): cmd += ['xdg-open', folder] + elif sys.platform == 'win32': + path = '\\'.join(folder.split('/')) + os.system('explorer.exe /select,"%s"' % path) + cmd = [] else: logger.debug('unsupported platform %s', sys.platform) - subprocess.Popen(cmd, close_fds=True) + if cmd: + subprocess.Popen(cmd, close_fds=True) def can_connect_dns(host="8.8.8.8", port=53): """