Coverage for heliumcli/actions/updateprojects.py: 97.44%
39 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-22 17:03 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-22 17:03 +0000
1import os
2import subprocess
4import git
6from .. import utils
8__author__ = "Alex Laird"
9__copyright__ = "Copyright 2018, Helium Edu"
10__version__ = "1.5.0"
13class UpdateProjectsAction:
14 def __init__(self):
15 self.name = "update-projects"
16 self.help = "Ensure all projects have the latest code and dependencies installed"
18 def setup(self, subparsers):
19 parser = subparsers.add_parser(self.name, help=self.help)
20 parser.set_defaults(action=self)
22 def run(self, args):
23 config = utils.get_config()
24 projects_dir = utils.get_projects_dir()
26 if config["projectsRelativeDir"] != ".":
27 root_dir = os.path.abspath(os.path.join(projects_dir, ".."))
28 if os.path.exists(os.path.join(root_dir, ".git")):
29 print(utils.get_repo_name(root_dir, config["remoteName"]))
31 repo = git.Repo(root_dir)
32 repo.git.fetch(tags=True, prune=True, force=os.environ.get("HELIUMCLI_FORCE_FETCH", "False") == "True")
33 print(repo.git.pull() + "\n")
35 if not os.path.exists(projects_dir):
36 os.mkdir(projects_dir)
38 for project in utils.get_projects(config):
39 print(project)
41 if config["projectsRelativeDir"] != ".":
42 project_path = os.path.join(projects_dir, project)
43 else:
44 project_path = os.path.join(projects_dir)
46 if not os.path.exists(os.path.join(project_path, ".git")):
47 print("Cloning repo to ./projects/{}".format(project))
48 git.Repo.clone_from("{}/{}.git".format(config["gitProject"], project), project_path)
49 else:
50 repo = git.Repo(project_path)
51 repo.git.fetch(tags=True, prune=True, force=os.environ.get("HELIUMCLI_FORCE_FETCH", "False") == "True")
52 print(repo.git.pull())
54 subprocess.call(["make", "install", "-C", project_path])
56 print("")