Coverage for putki/api.py: 0.00%

38 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-04 22:07:46 +00:00

1import os 

2import pathlib 

3from typing import no_type_check 

4 

5import yaml 

6import putki.discover as discover 

7import putki.traverse as traverse 

8from putki import log 

9 

10 

11@no_type_check 

12def verify_tasks(doc_root, structure_name, target_key, facet_key, options) -> int: 

13 """Yes.""" 

14 tasks_root = discover.root() 

15 log.info(f'Identified tasks default root at {tasks_root}') 

16 tasks_map = discover.tasks(doc_root) 

17 if not tasks_map: 

18 log.error('No tasks files found') 

19 return 1 

20 log.info(f'Mapped tasks below specified root at {doc_root}') 

21 files_count = len(tasks_map.keys()) 

22 log.info(f'The {files_count} tasks files collected below specified root at {doc_root} are:') 

23 for path in tasks_map: 

24 log.info(f'- {path}') 

25 task_count = sum(len(section) for section in tasks_map.values()) 

26 tasks = discover.combine(tasks_map) 

27 log.info(f'Collected the following {task_count} tasks from {files_count} tasks files:') 

28 show_me = yaml.safe_dump_all(tasks) 

29 for path in show_me.split('\n'): 

30 log.info(path) 

31 log.info('OK') 

32 return 0 

33 

34 

35@no_type_check 

36def verify_structures(doc_root, structures_name, component, options) -> int: 

37 """Maybe later.""" 

38 traverse.ROI = component 

39 saved_path = pathlib.Path.cwd() 

40 os.chdir(doc_root) 

41 log.info(f'Verifying structures below {doc_root}') 

42 code, message, root, claims = traverse.follow(structures_name) 

43 traverse.walk_fs(claims, root) 

44 os.chdir(saved_path) 

45 return 0