Coverage for heliumcli/actions/updateprojects.py: 97.50%

40 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-02 23:15 +0000

1import os 

2import subprocess 

3 

4import git 

5 

6from .. import utils 

7 

8__author__ = "Alex Laird" 

9__copyright__ = "Copyright 2018, Helium Edu" 

10__version__ = "1.5.0" 

11 

12 

13class UpdateProjectsAction: 

14 def __init__(self): 

15 self.name = "update-projects" 

16 self.help = "Ensure all projects have the latest code and dependencies installed" 

17 

18 def setup(self, subparsers): 

19 parser = subparsers.add_parser(self.name, help=self.help) 

20 parser.set_defaults(action=self) 

21 

22 def run(self, args): 

23 config = utils.get_config() 

24 projects_dir = utils.get_projects_dir() 

25 

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"])) 

30 

31 repo = git.Repo(root_dir) 

32 repo.git.fetch(tags=True, prune=True, force=os.environ.get("HELIUMCLI_FORCE_FETCH", "False") == "True") 

33 if os.environ.get("HELIUMCLI_SKIP_UPDATE_PULL", "False") != "True": 

34 print(repo.git.pull() + "\n") 

35 

36 if not os.path.exists(projects_dir): 

37 os.mkdir(projects_dir) 

38 

39 for project in utils.get_projects(config): 

40 print(project) 

41 

42 if config["projectsRelativeDir"] != ".": 

43 project_path = os.path.join(projects_dir, project) 

44 else: 

45 project_path = os.path.join(projects_dir) 

46 

47 if not os.path.exists(os.path.join(project_path, ".git")): 

48 print("Cloning repo to ./projects/{}".format(project)) 

49 git.Repo.clone_from("{}/{}.git".format(config["gitProject"], project), project_path) 

50 else: 

51 repo = git.Repo(project_path) 

52 repo.git.fetch(tags=True, prune=True, force=os.environ.get("HELIUMCLI_FORCE_FETCH", "False") == "True") 

53 print(repo.git.pull()) 

54 

55 subprocess.call(["make", "install", "-C", project_path]) 

56 

57 print("")