Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

give write access to template files after copying with startproject #4604

Merged
merged 3 commits into from
Jun 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions scrapy/commands/startproject.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import os
import stat
import string
from importlib import import_module
from os.path import join, exists, abspath
Expand Down Expand Up @@ -78,6 +79,29 @@ def _copytree(self, src, dst):
else:
copy2(srcname, dstname)
copystat(src, dst)
self._set_rw_permissions(dst)

def _set_rw_permissions(self, path):
"""
Sets permissions of a directory tree to +rw and +rwx for folders.
This is necessary if the start template files come without write
permissions.
"""
mode_rw = (stat.S_IRUSR
| stat.S_IWUSR
| stat.S_IRGRP
| stat.S_IROTH)

mode_x = (stat.S_IXUSR
| stat.S_IXGRP
| stat.S_IXOTH)

os.chmod(path, mode_rw | mode_x)
for root, dirs, files in os.walk(path):
for dir in dirs:
os.chmod(join(root, dir), mode_rw | mode_x)
for file in files:
os.chmod(join(root, file), mode_rw)

def run(self, args, opts):
if len(args) not in (1, 2):
Expand Down