@@ -51,55 +51,68 @@ def run_global(script_name, *args):
5151 return
5252
5353
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+ )
6367
6468
6569GLOBAL_HOOKS = [
6670 # initialize
6771 ("initialize" ,
6872 "This hook is sourced during the startup phase "
69- "when loading virtualenvwrapper.sh." ),
73+ "when loading virtualenvwrapper.sh." ,
74+ PERMISSIONS_SOURCED ),
7075
7176 # mkvirtualenv
7277 ("premkvirtualenv" ,
7378 "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 ),
7682 ("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 ),
7885
7986 # cpvirtualenv:
8087 # precpvirtualenv <old> <new> (run),
8188 # postcpvirtualenv (sourced)
8289
8390 # rmvirtualenv
8491 ("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 ),
8795 ("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 ),
9099
91100 # deactivate
92101 ("predeactivate" ,
93- "This hook is sourced before every virtualenv is deactivated." ),
102+ "This hook is sourced before every virtualenv is deactivated." ,
103+ PERMISSIONS_SOURCED ),
94104 ("postdeactivate" ,
95- "This hook is sourced after every virtualenv is deactivated." ),
105+ "This hook is sourced after every virtualenv is deactivated." ,
106+ PERMISSIONS_SOURCED ),
96107
97108 # activate
98109 ("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 ),
101113 ("postactivate" ,
102- "This hook is sourced after every virtualenv is activated." ),
114+ "This hook is sourced after every virtualenv is activated." ,
115+ PERMISSIONS_SOURCED ),
103116
104117 # mkproject:
105118 # premkproject <new project name> (run),
@@ -108,42 +121,39 @@ def run_global(script_name, *args):
108121 # get_env_details
109122 ("get_env_details" ,
110123 "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 ),
113127]
114128
115129
116130LOCAL_HOOKS = [
117131 # deactivate
118132 ("predeactivate" ,
119- "This hook is sourced before this virtualenv is deactivated." ),
133+ "This hook is sourced before this virtualenv is deactivated." ,
134+ PERMISSIONS_SOURCED ),
120135 ("postdeactivate" ,
121- "This hook is sourced after this virtualenv is deactivated." ),
136+ "This hook is sourced after this virtualenv is deactivated." ,
137+ PERMISSIONS_SOURCED ),
122138
123139 # activate
124140 ("preactivate" ,
125- "This hook is run before this virtualenv is activated." ),
141+ "This hook is run before this virtualenv is activated." ,
142+ PERMISSIONS ),
126143 ("postactivate" ,
127- "This hook is sourced after this virtualenv is activated." ),
144+ "This hook is sourced after this virtualenv is activated." ,
145+ PERMISSIONS_SOURCED ),
128146
129147 # get_env_details
130148 ("get_env_details" ,
131149 "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 ),
134153]
135154
136155
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 ):
147157 """Create a hook script.
148158
149159 :param filename: The name of the file to write.
@@ -162,19 +172,17 @@ def make_hook(filename, comment):
162172 })
163173 finally :
164174 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 )
169176 return
170177
171178
172179# HOOKS
173180
174181
175182def 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 )
178186 return
179187
180188
@@ -191,9 +199,9 @@ def initialize_source(args):
191199def pre_mkvirtualenv (args ):
192200 log .debug ('pre_mkvirtualenv %s' , str (args ))
193201 envname = args [0 ]
194- for filename , comment in LOCAL_HOOKS :
202+ for filename , comment , permissions in LOCAL_HOOKS :
195203 make_hook (get_path ('$WORKON_HOME' , envname , script_folder , filename ),
196- comment )
204+ comment , permissions )
197205 run_global ('premkvirtualenv' , * args )
198206 return
199207
@@ -211,9 +219,9 @@ def post_mkvirtualenv_source(args):
211219def pre_cpvirtualenv (args ):
212220 log .debug ('pre_cpvirtualenv %s' , str (args ))
213221 envname = args [0 ]
214- for filename , comment in LOCAL_HOOKS :
222+ for filename , comment , permissions in LOCAL_HOOKS :
215223 make_hook (get_path ('$WORKON_HOME' , envname , script_folder , filename ),
216- comment )
224+ comment , permissions )
217225 run_global ('precpvirtualenv' , * args )
218226 return
219227
0 commit comments