Skip to content

Commit

Permalink
Copy permission bits from template to target #3 (#6)
Browse files Browse the repository at this point in the history
* Copy permission bits from template to target #3

* Review suggestion changes for #3
  • Loading branch information
sshashank124 authored and JakobGM committed Apr 9, 2018
1 parent 8f4b5ed commit e7161d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions astrality/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import os
import stat
from functools import partial
from pathlib import Path
from typing import Any, Dict, Optional, Union
Expand Down Expand Up @@ -153,6 +154,10 @@ def compile_template(
with open(target, 'w') as target_file:
target_file.write(result)

# Copy template's file permissions to compiled target file
template_permissions = stat.S_IMODE(template.stat().st_mode)
target.chmod(template_permissions)

if permissions:
mode: int
if isinstance(permissions, int):
Expand Down
15 changes: 15 additions & 0 deletions astrality/tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ def test_handling_of_undefined_context(tmpdir, caplog):

assert "'this' is undefined" in caplog.record_tuples[0][2]

def test_writing_template_file_with_default_permissions(tmpdir):
tmpdir = Path(tmpdir)
template = tmpdir / 'template'
template.write_text('content')
permission = 0o751
template.chmod(permission)
target = tmpdir / 'target'

compile_template(
template=template,
target=target,
context={},
shell_command_working_directory=tmpdir,
)
assert (target.stat().st_mode & 0o777) == permission

def test_writing_template_file_with_specific_permissions(tmpdir):
tmpdir = Path(tmpdir)
Expand Down

0 comments on commit e7161d9

Please sign in to comment.