Coverage for heliumcli/actions/setbuild.py: 97.22%

36 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-04 15:02 +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 SetBuildAction: 

14 def __init__(self): 

15 self.name = "set-build" 

16 self.help = "Set all projects to the specified build, which may be a versioned release or a branch" 

17 

18 def setup(self, subparsers): 

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

20 parser.add_argument("version", help="The build version to be deployed, which may be a version or a branch") 

21 parser.set_defaults(action=self) 

22 

23 def run(self, args): 

24 config = utils.get_config() 

25 projects_dir = utils.get_projects_dir() 

26 

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

28 root_dir = os.path.abspath(os.path.join(projects_dir, "..")) 

29 if os.path.exists(os.path.join(root_dir, ".git")): 

30 print(utils.get_repo_name(root_dir, config["remoteName"])) 

31 

32 repo = git.Repo(root_dir) 

33 repo.git.fetch(tags=True, prune=True) 

34 repo.git.checkout(args.version) 

35 

36 print("") 

37 

38 for project in utils.get_projects(config): 

39 print(project) 

40 

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

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

43 else: 

44 project_path = os.path.join(projects_dir) 

45 

46 repo = git.Repo(project_path) 

47 repo.git.fetch(tags=True, prune=True) 

48 repo.git.checkout(args.version) 

49 

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

51 

52 print("")