added basic main
This commit is contained in:
parent
3eb045cd4a
commit
f6a8e260d5
3 changed files with 58 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -162,3 +162,4 @@ cython_debug/
|
|||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
**/test.env
|
||||
|
|
28
src/losoup/main.py
Normal file
28
src/losoup/main.py
Normal file
|
@ -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
|
29
test/losoup/test_main.py
Normal file
29
test/losoup/test_main.py
Normal file
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue