From f6a8e260d5d53b1bfc38c9bfddf9fd3669025966 Mon Sep 17 00:00:00 2001 From: stanislas Date: Mon, 23 Sep 2024 23:46:53 +0200 Subject: [PATCH] added basic main --- .gitignore | 1 + src/losoup/main.py | 28 ++++++++++++++++++++++++++++ test/losoup/test_main.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/losoup/main.py create mode 100644 test/losoup/test_main.py diff --git a/.gitignore b/.gitignore index ab3e8ce..0537cc2 100644 --- a/.gitignore +++ b/.gitignore @@ -162,3 +162,4 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +**/test.env diff --git a/src/losoup/main.py b/src/losoup/main.py new file mode 100644 index 0000000..566c852 --- /dev/null +++ b/src/losoup/main.py @@ -0,0 +1,28 @@ +from pathlib import Path + +import yaml + +from losoup.file_operations import local_files +from losoup.models import Software, GitlabSoftware, GithubSoftware + + +def load_software_list(software_file: Path) -> list[Software]: + software_yaml = yaml.safe_load(software_file.open()) + software_list = [] + for software in software_yaml.get("software", []): + match software.get("cvs").lower(): + case "github": + software_list.append(GithubSoftware(**software)) + case "gitlab": + software_list.append(GitlabSoftware(**software)) + case _: + pass + return software_list + + +def is_software_to_update(software: Software) -> bool: + return local_files.LocalFile(software).is_file_absent() + + +if __name__ == "__main__": + pass diff --git a/test/losoup/test_main.py b/test/losoup/test_main.py new file mode 100644 index 0000000..e043ebd --- /dev/null +++ b/test/losoup/test_main.py @@ -0,0 +1,29 @@ +from pathlib import Path + +from losoup import main +from losoup.models import GithubSoftware + + +def test_read_files(): + cur_dir = Path(__file__).parent + software_file = cur_dir / "software.yaml" + + files = main.load_software_list(software_file) + + assert len(files) == 2 + + nextcloud = files[0] + assert nextcloud.name == "NextCloud" + assert isinstance(nextcloud, GithubSoftware) + + keepassxc = files[1] + assert keepassxc.name == "KeePassXC" + assert isinstance(nextcloud, GithubSoftware) + + +def test_software_needs_to_be_updated(software_to_update): + assert main.is_software_to_update(software_to_update) + + +def test_software_does_not_need_to_be_updated(software_up_to_date): + assert not main.is_software_to_update(software_up_to_date)