Passed
Push — develop ( 6fb855...7cfc9a )
by Dean
02:39
created

BackupGroup.list()   B

Complexity

Conditions 5

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 17.8
Metric Value
cc 5
dl 0
loc 14
ccs 2
cts 10
cp 0.2
crap 17.8
rs 8.5454
1 1
from plugin.core.backup.constants import BACKUP_PATH
2
3 1
import os
4
5
6 1
class BackupGroup(object):
7 1
    def __init__(self, name, path):
8
        self.name = name
9
        self.path = path
10
11 1
    @classmethod
12
    def load(cls, path):
13
        name = os.path.relpath(path, BACKUP_PATH)
14
15
        return cls(name, path)
16
17 1
    @classmethod
18 1
    def list(cls, search_path=BACKUP_PATH, max_depth=0):
19
        names = os.listdir(search_path)
20
21
        for name in names:
22
            path = os.path.join(search_path, name)
23
24
            if path.endswith('.bgr'):
25
                # Load backup group
26
                yield cls.load(path)
27
            elif max_depth > 0:
28
                # Search sub-directory for backup groups
29
                for p in cls.list(path, max_depth - 1):
30
                    yield p
31
32 1
    def __repr__(self):
33
        return '<BackupGroup name: %r>' % self.name
34