Coverage for src/clone_xfce.py: 30.88%

56 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-12-30 22:19 -0800

1#!/usr/bin/env python3 

2 

3""" 

4Name: clone_xfce.py 

5Purpose: Clones Xfce repositories pulled from 

6 https://gitlab.xfce.org/ 

7 

8source: https://gitlab.com/kevinbowen/xfce-repocapp 

9version: 0.8.7 

10updated: 20230314 

11@author: kevin.bowen@gmail.com 

12""" 

13 

14import argparse 

15import os 

16import subprocess 

17import sys 

18from pathlib import Path 

19 

20from cappdata import component_list 

21 

22parser = argparse.ArgumentParser( 

23 description="clone groups of Xfce components" 

24 " from https://gitlab.xfce.org repositories." 

25) 

26parser.add_argument( 

27 "-c", 

28 "--component", 

29 action="store", 

30 choices=[ 

31 "apps", 

32 "bindings", 

33 "xfce", 

34 "panel-plugins", 

35 "thunar-plugins", 

36 "www", 

37 "all_components", 

38 ], 

39 help="specify an Xfce component group to clone" 

40 " from https://gitlab.xfce.org", 

41) 

42parser.add_argument("--version", action="version", version="%(prog)s 0.8.7") 

43args = parser.parse_args() 

44if args.component is None: 44 ↛ 51line 44 didn't jump to line 51 because the condition on line 44 was always true

45 print( 

46 "No component was specified. Default to cloning" 

47 " the 'bindings' components...." 

48 ) 

49 args.component = "bindings" 

50 

51line_rule = "\u2248" * 16 

52path = Path(__file__).parent.resolve() 

53os.chdir(path) 

54 

55 

56def clone_xfce(component, comp_list): 

57 """Run 'git clone' for selected components.""" 

58 print(f"Cloning the Xfce {component} group...") 

59 # Move to the directory where the script is located 

60 os.chdir(Path(__file__).parent.resolve()) 

61 

62 def get_path(comp_group): 

63 # grandparent directory (../../) relative to script. 

64 installpath = Path.cwd().parent.parent.joinpath(comp_group) 

65 

66 return installpath 

67 

68 repopath = get_path(component) 

69 success_count = 0 

70 

71 os.makedirs(repopath, exist_ok=True) 

72 os.chdir(repopath) 

73 

74 for item in component_list(comp_list): 

75 p = Path(item) 

76 if p.is_dir(): 

77 print(f"\nThe '{item}' directory already exists. Skipping...\n") 

78 print(line_rule) 

79 else: 

80 try: 

81 url = f"https://gitlab.xfce.org/{component}/{item}.git" 

82 subprocess.run(["git", "clone", url], stdout=None, check=True) 

83 success_count += 1 

84 print(line_rule) 

85 print(f"{item} repository cloned successfully.") 

86 except subprocess.CalledProcessError: 

87 # On error, returns a non-zero exit status 128. 

88 print(line_rule) 

89 print(f"Failed to clone {item} repository.") 

90 

91 print( 

92 f"{success_count}/{len(component_list(comp_list))} " 

93 f"'{component}' repositories cloned successfully." 

94 ) 

95 print(line_rule) 

96 

97 

98def main(component_group_name): 

99 """Build arguments to pass to clone_xfce() with a call to 

100 cappdata for component name list. 

101 command format: 

102 clone_xfce(component='apps', 

103 comp_list='apps') 

104 """ 

105 cgroup_listname = component_list(component_group_name) 

106 # All cgroup_listnames will return a string, except 'all' 

107 if isinstance(cgroup_listname, dict): 

108 for comp, cglist in cgroup_listname.items(): 

109 clone_xfce(component=comp, comp_list=cglist) 

110 else: 

111 clone_xfce( 

112 component=component_group_name, comp_list=component_group_name 

113 ) 

114 

115 

116if __name__ == "__main__": 116 ↛ 117line 116 didn't jump to line 117 because the condition on line 116 was never true

117 try: 

118 component_group = args.component 

119 main(component_group) 

120 except KeyboardInterrupt: 

121 print() 

122 print("Stopped xfce-repocapp. Exiting...") 

123 sys.exit()