Test Failed
Branch v4.0-dev (e44d7e)
by Emmanuel
04:49
created

services   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 32
dl 0
loc 47
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A update_all() 0 6 2
A update_package() 0 9 3
A install() 0 19 4
1
# coding: utf-8
2
"""
3
Manage Stakkr Packages (extra packages)
4
"""
5
6
__github_url__ = 'https://github.com/stakkr-org'
7
8
9
def install(services_dir: str, package: str):
10
    from os.path import isdir
11
    from urllib.parse import urlparse
12
13
    url = '{}/services-{}.git'.format(__github_url__, package)
14
    if urlparse(package).scheme != '':
15
        url = package
16
17
    dest = '{}/{}'.format(services_dir, package)
18
    if isdir(dest):
19
        msg = 'Package "{}" is already installed'.format(package)
20
        return False, msg
21
22
    from git import Repo, exc
23
    try:
24
        Repo.clone_from(url, dest)
25
        return True, None
26
    except exc.GitCommandError as error:
27
        return False, "Couldn't clone {} ({})".format(url, error)
28
29
30
def update_all(services_dir: str):
31
    from os import listdir
32
33
    for folder in listdir(services_dir):
34
        path = services_dir + '/' + folder
35
        update_package(path)
36
37
38
def update_package(path: str):
39
    from git import Repo, exc
40
41
    try:
42
        repo = Repo(path)
43
        if repo.remotes.origin.url.startswith(__github_url__):
44
            repo.remotes.origin.pull()
45
    except exc.InvalidGitRepositoryError:
46
        pass
47