-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_manager.py
43 lines (36 loc) · 1.44 KB
/
package_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import settings
import requests
import cal
import os
import logging
logger = logging.getLogger()
class PackageManager:
"""
Download packages containing HikePrograms, HikeChains or ChainLoaders from
the central repository.
"""
def pull(self, package_name):
"""
Download a package in the appropriate directory.
Return True if downloaded, false if already exists, and throw exception in case of errors.
"""
# if is a system package or if the package has been already downloaded, do nothing.
if package_name == 'hike_default' or os.path.isdir(f"{settings.COMPONENTS_DIR}/{package_name}"):
return False
url = f"{settings.PROGRAMS_REPOSITORY_URL}"
r = requests.get(url, allow_redirects=True)
data = r.json()['data']
is_found = False
for d in data:
if d['name'] == package_name:
logger.info(
f'Found {package_name} in the package list. Start cloning...')
logger.info(f"Package information retrieved: {str(d)}")
is_found = True
cal.clone_repo(
d['git_url'], f"{settings.COMPONENTS_DIR}/{package_name}", d['tag'])
logger.info(f"Package {package_name} cloned successfully")
if not is_found:
raise Exception(
f"package {package_name} not found in the repository")
return True