| Total Complexity | 7 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # coding: utf-8 |
||
| 2 | """ |
||
| 3 | Files Utils to find dir, files, etc. |
||
| 4 | |||
| 5 | Such as : static files locations or directories location |
||
| 6 | """ |
||
| 7 | |||
| 8 | from os import getcwd, listdir |
||
| 9 | from os.path import dirname, realpath |
||
| 10 | |||
| 11 | |||
| 12 | def get_lib_basedir(): |
||
| 13 | """Return the base directory of stakkr, where all files are, to read services and config.""" |
||
| 14 | return dirname(realpath(__file__)) |
||
| 15 | |||
| 16 | |||
| 17 | def get_dir(directory: str): |
||
| 18 | """Detect if stakkr is a package or a clone and gives the right path for a directory.""" |
||
| 19 | return '{}/{}'.format(get_lib_basedir(), directory) |
||
| 20 | |||
| 21 | |||
| 22 | def get_file(directory: str, filename: str): |
||
| 23 | """Detect if stakkr is a package or a clone and gives the right path for a file.""" |
||
| 24 | return get_dir(directory) + '/' + filename.lstrip('/') |
||
| 25 | |||
| 26 | |||
| 27 | def find_project_dir(): |
||
| 28 | path = getcwd() |
||
| 29 | while True: |
||
| 30 | files = listdir(path) |
||
| 31 | if 'stakkr.yml' in files: |
||
| 32 | return path |
||
| 33 | |||
| 34 | new_path = dirname(path) |
||
| 35 | if new_path == path: |
||
| 36 | raise FileNotFoundError('Could not find config file (stakkr.yml)') |
||
| 37 | path = new_path |
||
| 38 |