Passed
Push — master ( b9e3b5...041dd8 )
by Emmanuel
05:58
created

stakkr.file_utils   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 38
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 7

4 Functions

Rating   Name   Duplication   Size   Complexity  
A get_file() 0 3 1
A get_lib_basedir() 0 3 1
A find_project_dir() 0 11 4
A get_dir() 0 3 1
1
# coding: utf-8
2 1
"""
3
Files Utils to find dir, files, etc.
4
5
Such as : static files locations or directories location
6
"""
7
8 1
from os import getcwd, listdir
9 1
from os.path import dirname, realpath
10
11
12 1
def get_lib_basedir():
13
    """Return the base directory of stakkr, where all files are, to read services and config."""
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (96/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
14 1
    return dirname(realpath(__file__))
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
15
16
17 1
def get_dir(directory: str):
18
    """Detect if stakkr is a package or a clone and gives the right path for a directory."""
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (92/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
19 1
    return '{}/{}'.format(get_lib_basedir(), directory)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
20
21
22 1
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."""
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (87/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
24 1
    return get_dir(directory) + '/' + filename.lstrip('/')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
25
26
27 1
def find_project_dir():
28 1
    path = getcwd()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
29 1
    while True:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
30 1
        files = listdir(path)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
31 1
        if 'stakkr.yml' in files:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
32 1
            return path
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
33
34 1
        new_path = dirname(path)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
35 1
        if new_path == path:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
36 1
            raise FileNotFoundError('Could not find config file (stakkr.yml)')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
37
        path = new_path
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
38