-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathpath.go
127 lines (106 loc) · 2.37 KB
/
path.go
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package path
import (
"io/ioutil"
"os"
"path/filepath"
"sync"
"github.com/pkg/errors"
)
const (
OSEnvPythonbrewRoot = "PYTHONBREW_ROOT"
OSEnvPythonbrewHome = "PYTHONBREW_HOME"
)
var (
mux sync.Mutex
tempDir string
)
// RootDir returns root directory path (system-wide)
func RootDir() string {
v := os.Getenv(OSEnvPythonbrewRoot)
if v == "" {
v = filepath.Join(os.Getenv("HOME"), ".pythonbrew")
}
return v
}
// HomeDir returns home directory path
func HomeDir() string {
v := os.Getenv(OSEnvPythonbrewHome)
if v == "" {
v = filepath.Join(os.Getenv("HOME"), ".pythonbrew")
}
return v
}
// TempDir returns temporary directory
func TempDir() string {
mux.Lock()
defer mux.Unlock()
if tempDir != "" {
return tempDir
}
d, err := ioutil.TempDir("", "pythonbrew")
if err != nil {
panic(err)
}
tempDir = d
return tempDir
}
// InstallDir returns install directory path
func InstallDir() string {
return filepath.Join(RootDir(), "versions")
}
// CacheDir returns cache directory path
func CacheDir() string {
return filepath.Join(RootDir(), "cache")
}
// BuildDir returns build directory path
func BuildDir() string {
return filepath.Join(CacheDir(), "build")
}
// EnvDir returns env directory path
func EnvDir() string {
return filepath.Join(HomeDir(), "env")
}
// VenvsDir returns venv directory path
func VenvsDir() string {
return filepath.Join(HomeDir(), "venvs")
}
// Log returns log file path
func Log() string {
return filepath.Join(TempDir(), "pythonbrew.log")
}
// PipPy32 returns pip installer file path (for Python-3.2)
func PipPy32() string {
return filepath.Join(CacheDir(), "get-pip-32.py")
}
// PipPy returns pip installer file path
func PipPy() string {
return filepath.Join(CacheDir(), "get-pip.py")
}
// EnvTmp returns temporary environment file path
func EnvTmp() string {
return filepath.Join(EnvDir(), "tmp")
}
// EnvPermanent returns permanently environment file path
func EnvPermanent() string {
return filepath.Join(EnvDir(), "permanent")
}
// EnvVenv returns venv run command file path
func EnvVenv() string {
return filepath.Join(EnvDir(), "venv")
}
// MkdirAll makes all directories
func MkdirAll() error {
dirs := []string{
CacheDir(),
BuildDir(),
InstallDir(),
EnvDir(),
VenvsDir(),
}
for _, dir := range dirs {
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return errors.Wrap(err, dir)
}
}
return nil
}