open file/folder windows

This commit is contained in:
j 2016-01-31 18:53:11 +05:30
parent a0b16fc841
commit b7d784a0f8
1 changed files with 13 additions and 3 deletions

View File

@ -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):
"""