File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import sys
3
+ import stat
4
+
5
+ if len (sys .argv ) == 1 :
6
+ filename = __file__
7
+ else :
8
+ filename = sys .argv [1 ]
9
+
10
+ # Determine what permissions are already set using stat
11
+ permissions = stat .S_IMODE (os .stat (filename ).st_mode )
12
+
13
+ if not os .access (filename , os .X_OK ):
14
+ print ('Adding execute permission' )
15
+ new_permissions = permissions | stat .S_IXUSR
16
+ else :
17
+ print ('Removing execute permission' )
18
+ # use xor to remove the user execute permission
19
+ new_permissions = permissions ^ stat .S_IXUSR
20
+
21
+ os .chmod (filename , new_permissions )
22
+
23
+ print ('Readable:' , os .access (filename , os .R_OK ))
24
+ print ('Writable:' , os .access (filename , os .W_OK ))
25
+ print ('Executable:' , os .access (filename , os .X_OK ))
Original file line number Diff line number Diff line change
1
+ Some content for testing purposes
You can’t perform that action at this time.
0 commit comments