Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fdw-forks
django-database-files
Commits
74d24e66
Commit
74d24e66
authored
Jun 11, 2012
by
chris
Browse files
Added feature to define custom user and group to set ownership with when
writing files.
parent
3a56c023
Changes
1
Hide whitespace changes
Inline
Side-by-side
database_files/utils.py
View file @
74d24e66
#from grp import getgrnam
#from pwd import getpwnam
import
os
from
django.conf
import
settings
...
...
@@ -14,3 +16,16 @@ def write_file(name, content, overwrite=False):
if
not
os
.
path
.
isdir
(
dirs
):
os
.
makedirs
(
dirs
)
open
(
fqfn
,
'wb'
).
write
(
content
)
# Set ownership and permissions.
uname
=
getattr
(
settings
,
'DATABASE_FILES_USER'
,
None
)
gname
=
getattr
(
settings
,
'DATABASE_FILES_GROUP'
,
None
)
if
gname
:
gname
=
':'
+
gname
if
uname
:
os
.
system
(
'chown -RL %s%s "%s"'
%
(
uname
,
gname
,
dirs
))
# Set permissions.
perms
=
getattr
(
settings
,
'DATABASE_FILES_PERMS'
,
None
)
if
perms
:
os
.
system
(
'chmod -R %s "%s"'
%
(
perms
,
dirs
))
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment