Skip to content

Commit

Permalink
adding command line option to fix folder content permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Iolaum committed Oct 5, 2020
1 parent b9f870c commit 8509781
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 21 deletions.
2 changes: 1 addition & 1 deletion fcust/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# fmt: off
__author__ = """Nikolaos Perrakis"""
__email__ = 'nikperrakis@gmail.com'
__version__ = '0.0.3'
__version__ = '0.0.4'
# fmt: on
24 changes: 15 additions & 9 deletions fcust/cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
"""Console script for fcust."""
import sys
import click
from pathlib import PosixPath
from fcust.fcust import CommonFolder


@click.command()
def main(args=None):
"""Console script for fcust."""
click.echo("Replace this message by putting your code into " "fcust.cli.main")
click.echo("See click documentation at https://click.palletsprojects.com/")
return 0
@click.argument("folder_path")
def main(
folder_path: str,
help="Path where the common foler is located",
):
fpath = PosixPath(folder_path)
if not fpath.exists():
raise FileNotFoundError(f"Specified folder {folder_path} does not exist!")


if __name__ == "__main__":
sys.exit(main()) # pragma: no cover
# assume common folder itself has been created with proper group and permissions.
click.echo(f"Initiating maintenance on {folder_path}")
cf = CommonFolder(folder_path=fpath)
cf.enforce_permissions()
click.echo("Common folder maintenance completed.")
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.3
current_version = 0.0.4
commit = False
tag = False

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
"dev": setup_requirements + test_requirements
},
url='https://github.com/Iolaum/fcust',
version='0.0.3',
version='0.0.4',
zip_safe=False,
)
53 changes: 44 additions & 9 deletions tests/test_fcust.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,47 @@ def test_enforce_permissions(self):
assert self.o2.group() == self.group


def test_command_line_interface():
"""Test the CLI."""
runner = CliRunner()
result = runner.invoke(cli.main)
assert result.exit_code == 0
assert "fcust.cli.main" in result.output
help_result = runner.invoke(cli.main, ["--help"])
assert help_result.exit_code == 0
assert "--help Show this message and exit." in help_result.output
class TestCommonFolderCLI:
def setup_class(cls):
"""
Setting up the objects to test functionality.
Note:
User running the tests must be a member of group 'family'.
"""
cls.folder = Path(tempfile.mkdtemp())
# populate folder
f1 = PurePath.joinpath(cls.folder, "file1.txt")
with f1.open(mode="w") as fh:
fh.write("file1")
chown(f1, group="family")
f1.chmod(0o40400)
f2 = PurePath.joinpath(cls.folder, "file2.txt")
with f2.open(mode="w") as fh:
fh.write("file2")
f4 = PurePath.joinpath(cls.folder, "folder")
f4.mkdir()
chown(f4, group="family")
f4.chmod(0o40750)
f3 = PurePath.joinpath(cls.folder, "folder", "file3.txt")
with f3.open(mode="w") as fh:
fh.write("file3")
cls.group = cls.folder.group()
cls.owner = cls.folder.owner()
cls.o1 = f1
cls.o2 = f4

def test_command_line_interface(self):
"""Test the CLI."""
runner = CliRunner()
result = runner.invoke(cli.main, [str(self.folder)])
assert result.exit_code == 0
assert oct(self.o1.stat().st_mode)[-4:] == "0664"
assert self.o1.group() == self.group
assert oct(self.o2.stat().st_mode)[-4:] == "2775"
assert self.o2.group() == self.group

help_result = runner.invoke(cli.main, ["--help"])
assert help_result.exit_code == 0
assert "--help Show this message and exit." in help_result.output
assert "Usage: main [OPTIONS] FOLDER_PATH" in help_result.output

0 comments on commit 8509781

Please sign in to comment.