@@ -51,55 +51,68 @@ def run_global(script_name, *args):
51
51
return
52
52
53
53
54
- PERMISSIONS = (stat .S_IRWXU # read/write/execute, user
55
- | stat .S_IRWXG # read/write/execute, group
56
- | stat .S_IROTH # read, others
57
- | stat .S_IXOTH ) # execute, others
58
- PERMISSIONS_SOURCED = PERMISSIONS \
59
- & ~ (# remove executable bits for
60
- stat .S_IXUSR # ... user
61
- | stat .S_IXGRP # ... group
62
- | stat .S_IXOTH ) # ... others
54
+ PERMISSIONS = (
55
+ stat .S_IRWXU # read/write/execute, user
56
+ | stat .S_IRGRP # read, group
57
+ | stat .S_IXGRP # execute, group
58
+ | stat .S_IROTH # read, others
59
+ | stat .S_IXOTH # execute, others
60
+ )
61
+ PERMISSIONS_SOURCED = PERMISSIONS & ~ (
62
+ # remove executable bits for
63
+ stat .S_IXUSR # ... user
64
+ | stat .S_IXGRP # ... group
65
+ | stat .S_IXOTH # ... others
66
+ )
63
67
64
68
65
69
GLOBAL_HOOKS = [
66
70
# initialize
67
71
("initialize" ,
68
72
"This hook is sourced during the startup phase "
69
- "when loading virtualenvwrapper.sh." ),
73
+ "when loading virtualenvwrapper.sh." ,
74
+ PERMISSIONS_SOURCED ),
70
75
71
76
# mkvirtualenv
72
77
("premkvirtualenv" ,
73
78
"This hook is run after a new virtualenv is created "
74
- "and before it is activated." ),
75
- # argument: name of new environment
79
+ "and before it is activated.\n "
80
+ "# argument: name of new environment" ,
81
+ PERMISSIONS ),
76
82
("postmkvirtualenv" ,
77
- "This hook is sourced after a new virtualenv is activated." ),
83
+ "This hook is sourced after a new virtualenv is activated." ,
84
+ PERMISSIONS_SOURCED ),
78
85
79
86
# cpvirtualenv:
80
87
# precpvirtualenv <old> <new> (run),
81
88
# postcpvirtualenv (sourced)
82
89
83
90
# rmvirtualenv
84
91
("prermvirtualenv" ,
85
- "This hook is run before a virtualenv is deleted." ),
86
- # argument: full path to environment directory
92
+ "This hook is run before a virtualenv is deleted.\n "
93
+ "# argument: full path to environment directory" ,
94
+ PERMISSIONS ),
87
95
("postrmvirtualenv" ,
88
- "This hook is run after a virtualenv is deleted." ),
89
- # argument: full path to environment directory
96
+ "This hook is run after a virtualenv is deleted.\n "
97
+ "# argument: full path to environment directory" ,
98
+ PERMISSIONS ),
90
99
91
100
# deactivate
92
101
("predeactivate" ,
93
- "This hook is sourced before every virtualenv is deactivated." ),
102
+ "This hook is sourced before every virtualenv is deactivated." ,
103
+ PERMISSIONS_SOURCED ),
94
104
("postdeactivate" ,
95
- "This hook is sourced after every virtualenv is deactivated." ),
105
+ "This hook is sourced after every virtualenv is deactivated." ,
106
+ PERMISSIONS_SOURCED ),
96
107
97
108
# activate
98
109
("preactivate" ,
99
- "This hook is run before every virtualenv is activated." ),
100
- # argument: environment name
110
+ "This hook is run before every virtualenv is activated.\n "
111
+ "# argument: environment name" ,
112
+ PERMISSIONS ),
101
113
("postactivate" ,
102
- "This hook is sourced after every virtualenv is activated." ),
114
+ "This hook is sourced after every virtualenv is activated." ,
115
+ PERMISSIONS_SOURCED ),
103
116
104
117
# mkproject:
105
118
# premkproject <new project name> (run),
@@ -108,42 +121,39 @@ def run_global(script_name, *args):
108
121
# get_env_details
109
122
("get_env_details" ,
110
123
"This hook is run when the list of virtualenvs is printed "
111
- "so each name can include details." ),
112
- # argument: environment name
124
+ "so each name can include details.\n "
125
+ "# argument: environment name" ,
126
+ PERMISSIONS ),
113
127
]
114
128
115
129
116
130
LOCAL_HOOKS = [
117
131
# deactivate
118
132
("predeactivate" ,
119
- "This hook is sourced before this virtualenv is deactivated." ),
133
+ "This hook is sourced before this virtualenv is deactivated." ,
134
+ PERMISSIONS_SOURCED ),
120
135
("postdeactivate" ,
121
- "This hook is sourced after this virtualenv is deactivated." ),
136
+ "This hook is sourced after this virtualenv is deactivated." ,
137
+ PERMISSIONS_SOURCED ),
122
138
123
139
# activate
124
140
("preactivate" ,
125
- "This hook is run before this virtualenv is activated." ),
141
+ "This hook is run before this virtualenv is activated." ,
142
+ PERMISSIONS ),
126
143
("postactivate" ,
127
- "This hook is sourced after this virtualenv is activated." ),
144
+ "This hook is sourced after this virtualenv is activated." ,
145
+ PERMISSIONS_SOURCED ),
128
146
129
147
# get_env_details
130
148
("get_env_details" ,
131
149
"This hook is run when the list of virtualenvs is printed "
132
- "in 'long' mode so each name can include details." ),
133
- # argument: environment name
150
+ "in 'long' mode so each name can include details.\n "
151
+ "# argument: environment name" ,
152
+ PERMISSIONS ),
134
153
]
135
154
136
155
137
- SOURCED = ('initialize' ,
138
- 'postactivate' ,
139
- 'predeactivate' ,
140
- 'postdeactivate' ,
141
- 'postmkproject' ,
142
- 'postmkvirtualenv' ,
143
- )
144
-
145
-
146
- def make_hook (filename , comment ):
156
+ def make_hook (filename , comment , permissions ):
147
157
"""Create a hook script.
148
158
149
159
:param filename: The name of the file to write.
@@ -162,19 +172,17 @@ def make_hook(filename, comment):
162
172
})
163
173
finally :
164
174
f .close ()
165
- os .chmod (filename ,
166
- os .path .basename (filename ) in SOURCED
167
- and PERMISSIONS_SOURCED
168
- or PERMISSIONS )
175
+ os .chmod (filename , permissions )
169
176
return
170
177
171
178
172
179
# HOOKS
173
180
174
181
175
182
def initialize (args ):
176
- for filename , comment in GLOBAL_HOOKS :
177
- make_hook (get_path ('$VIRTUALENVWRAPPER_HOOK_DIR' , filename ), comment )
183
+ for filename , comment , permissions in GLOBAL_HOOKS :
184
+ make_hook (get_path ('$VIRTUALENVWRAPPER_HOOK_DIR' , filename ),
185
+ comment , permissions )
178
186
return
179
187
180
188
@@ -191,9 +199,9 @@ def initialize_source(args):
191
199
def pre_mkvirtualenv (args ):
192
200
log .debug ('pre_mkvirtualenv %s' , str (args ))
193
201
envname = args [0 ]
194
- for filename , comment in LOCAL_HOOKS :
202
+ for filename , comment , permissions in LOCAL_HOOKS :
195
203
make_hook (get_path ('$WORKON_HOME' , envname , script_folder , filename ),
196
- comment )
204
+ comment , permissions )
197
205
run_global ('premkvirtualenv' , * args )
198
206
return
199
207
@@ -211,9 +219,9 @@ def post_mkvirtualenv_source(args):
211
219
def pre_cpvirtualenv (args ):
212
220
log .debug ('pre_cpvirtualenv %s' , str (args ))
213
221
envname = args [0 ]
214
- for filename , comment in LOCAL_HOOKS :
222
+ for filename , comment , permissions in LOCAL_HOOKS :
215
223
make_hook (get_path ('$WORKON_HOME' , envname , script_folder , filename ),
216
- comment )
224
+ comment , permissions )
217
225
run_global ('precpvirtualenv' , * args )
218
226
return
219
227
0 commit comments