-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathplatform.py
More file actions
76 lines (59 loc) · 2.32 KB
/
Copy pathplatform.py
File metadata and controls
76 lines (59 loc) · 2.32 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Platform-specific utilities for MCPM router.
This module provides functions to handle platform-specific operations,
such as determining appropriate log directories based on the operating system.
"""
import os
import sys
from pathlib import Path
def get_pid_directory(app_name: str = "mcpm") -> Path:
"""
Return the appropriate PID directory path based on the current operating system.
Args:
app_name: The name of the application, used in the path
Returns:
Path object representing the PID directory
"""
# macOS
if sys.platform == "darwin":
return Path.home() / "Library" / "Application Support" / app_name
# Windows
elif sys.platform == "win32":
localappdata = os.environ.get("LOCALAPPDATA")
if localappdata:
return Path(localappdata) / app_name
return Path.home() / "AppData" / "Local" / app_name
# Linux and other Unix-like systems
else:
# Check if XDG_DATA_HOME is defined
xdg_data_home = os.environ.get("XDG_DATA_HOME")
if xdg_data_home:
return Path(xdg_data_home) / app_name
# Default to ~/.local/share if XDG_DATA_HOME is not defined
return Path.home() / ".local" / "share" / app_name
def get_frpc_directory(app_name: str = "mcpm") -> Path:
"""
Return the appropriate FRPC directory path based on the current operating system.
Args:
app_name: The name of the application, used in the path
Returns:
Path object representing the FRPC directory
"""
# macOS
if sys.platform == "darwin":
return Path.home() / "Library" / "Application Support" / app_name / "frpc"
# Windows
elif sys.platform == "win32":
localappdata = os.environ.get("LOCALAPPDATA")
if localappdata:
return Path(localappdata) / app_name / "frpc"
return Path.home() / "AppData" / "Local" / app_name / "frpc"
# Linux and other Unix-like systems
else:
# Check if XDG_DATA_HOME is defined
xdg_data_home = os.environ.get("XDG_DATA_HOME")
if xdg_data_home:
return Path(xdg_data_home) / app_name / "frpc"
# Default to ~/.local/share if XDG_DATA_HOME is not defined
return Path.home() / ".local" / "share" / app_name / "frpc"
NPX_CMD = "npx" if sys.platform != "win32" else "npx.cmd"