-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
46 lines (41 loc) · 1.24 KB
/
utils.py
File metadata and controls
46 lines (41 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
This file is part of QuickEDL.
It provides utility functions for the application.
"""
import subprocess
from pathlib import Path
import os
import logging
import webbrowser
def open_directory(path):
"""
Opens a path in a explorer/finder window.
Args:
path: path to open
"""
try:
path = Path(path)
if not path.exists():
logging.error(f"Path does not exist: {path}")
return
if path.is_dir():
directory = path
else:
directory = path.parent
if os.name == 'nt': # Windows
if path.is_dir():
subprocess.run(['explorer', str(directory)])
else:
subprocess.run(['explorer', '/select,', str(path)])
elif os.name == 'posix': # Unix
if path.is_dir():
subprocess.run(['open', str(directory)])
else:
subprocess.run(['open', '-R', str(path)])
else:
logging.error("Unsupported OS")
except Exception as e:
logging.error(f"An error occurred while opening the directory: {e}", exc_info=True)
def open_in_browser(url, **kwargs):
webbrowser.open_new(url)
logging.debug(f"Opening in Browser: {url}")