Skip to content

Commit 2e22266

Browse files
authored
sinol-make export should add +x to xyzingen.sh (#142)
* Add executable permission to shell ingen in export * Add test
1 parent 057ed32 commit 2e22266

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/sinol_make/commands/export/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import glob
3+
import stat
34
import shutil
45
import tarfile
56
import argparse
@@ -62,6 +63,10 @@ def copy_package_required_files(self, target_dir: str):
6263
shutil.copytree(file_path, os.path.join(target_dir, file))
6364
else:
6465
shutil.copy(file_path, target_dir)
66+
shell_ingen = os.path.join(target_dir, 'prog', f'{self.task_id}ingen.sh')
67+
if os.path.exists(shell_ingen):
68+
st = os.stat(shell_ingen)
69+
os.chmod(shell_ingen, st.st_mode | stat.S_IEXEC)
6570

6671
print('Copying example tests...')
6772
for ext in ['in', 'out']:

tests/commands/export/test_integration.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import yaml
2+
import stat
23
import glob
34
import pytest
45
import tarfile
@@ -80,3 +81,28 @@ def test_doc_cleared(create_package):
8081
assert os.path.exists(extracted)
8182
for pattern in ['doc/*~', 'doc/*.aux', 'doc/*.log', 'doc/*.dvi', 'doc/*.err', 'doc/*.inf']:
8283
assert glob.glob(os.path.join(extracted, pattern)) == []
84+
85+
86+
@pytest.mark.parametrize("create_package", [util.get_shell_ingen_pack_path()], indirect=True)
87+
def test_correct_permissions(create_package, capsys):
88+
"""
89+
Checks if shell ingen has correct permissions.
90+
"""
91+
shell_ingen = os.path.join(os.getcwd(), 'prog', f'{package_util.get_task_id()}ingen.sh')
92+
st = os.stat(shell_ingen)
93+
os.chmod(shell_ingen, st.st_mode & ~stat.S_IEXEC)
94+
95+
parser = configure_parsers()
96+
args = parser.parse_args(["export"])
97+
command = Command()
98+
command.run(args)
99+
task_id = package_util.get_task_id()
100+
101+
with tempfile.TemporaryDirectory() as tmpdir:
102+
with tarfile.open(f'{task_id}.tgz', "r") as tar:
103+
tar.extractall(tmpdir)
104+
105+
shell_ingen = os.path.join(tmpdir, task_id, 'prog', f'{task_id}ingen.sh')
106+
assert os.path.exists(shell_ingen)
107+
st = os.stat(shell_ingen)
108+
assert st.st_mode & stat.S_IEXEC

0 commit comments

Comments
 (0)