| Total Complexity | 9 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 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 |