1
+ import stat
1
2
import click
2
3
from jinja2 import Environment , FileSystemLoader , select_autoescape
3
4
import os
@@ -50,7 +51,7 @@ def make_module(name):
50
51
'forms.py' : 'module_forms.py.j2' ,
51
52
'seeders.py' : 'module_seeders.py.j2' ,
52
53
os .path .join ('templates' , name , 'index.html' ): 'module_templates_index.html.j2' ,
53
- os . path . join ( 'assets' , name , ' scripts.js') : 'module_scripts.js.j2' ,
54
+ 'assets/ scripts.js' : 'module_scripts.js.j2' ,
54
55
'tests/test_unit.py' : 'module_tests_test_unit.py.j2' ,
55
56
'tests/locustfile.py' : 'module_tests_locustfile.py.j2' ,
56
57
'tests/test_selenium.py' : 'module_tests_test_selenium.py.j2'
@@ -77,3 +78,26 @@ def make_module(name):
77
78
open (os .path .join (module_path , filename ), 'a' ).close () # Create empty file if there is no template.
78
79
79
80
click .echo (click .style (f"Module '{ name } ' created successfully." , fg = 'green' ))
81
+
82
+ # Change the owner of the main folder of the module
83
+ os .chown (module_path , 1000 , 1000 )
84
+
85
+ # Change permissions to drwxrwxr-x (chmod 775)
86
+ os .chmod (module_path , stat .S_IRWXU | stat .S_IRWXG | stat .S_IROTH | stat .S_IXOTH )
87
+
88
+ # Change the owner of all created files and directories to UID 1000 and GID 1000
89
+ uid = 1000
90
+ gid = 1000
91
+
92
+ for root , dirs , files in os .walk (module_path ):
93
+ for dir_ in dirs :
94
+ dir_path = os .path .join (root , dir_ )
95
+ os .chown (dir_path , uid , gid )
96
+ os .chmod (dir_path , stat .S_IRWXU | stat .S_IRWXG | stat .S_IROTH | stat .S_IXOTH )
97
+
98
+ for file_ in files :
99
+ file_path = os .path .join (root , file_ )
100
+ os .chown (file_path , uid , gid )
101
+ os .chmod (file_path , stat .S_IRUSR | stat .S_IWUSR | stat .S_IRGRP | stat .S_IWGRP | stat .S_IROTH )
102
+
103
+ click .echo (click .style (f"Module '{ name } ' permissions changed successfully." , fg = 'green' ))
0 commit comments