Coverage for src/clone_xfce.py: 30.88%

56 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-02 08:58 -0700

1#!/usr/bin/env python 

2 

3""" 

4Name: clone_xfce.py 

5Purpose: Clones Xfce repositories from https://gitlab.xfce.org/ 

6 

7source: https://gitlab.com/kevinbowen/xfrepos 

8version: 0.8.7 

9updated: 20260827 

10@author: kevin.bowen@gmail.com 

11""" 

12 

13import argparse 

14import os 

15import subprocess # ruff: ignore[suspicious-subprocess-import] 

16import sys 

17from pathlib import Path 

18 

19from cappdata import component_list 

20 

21parser = argparse.ArgumentParser( 

22 description="clone groups of Xfce components" 

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

24) 

25parser.add_argument( 

26 "-c", 

27 "--component", 

28 action="store", 

29 choices=[ 

30 "apps", 

31 "bindings", 

32 "xfce", 

33 "panel-plugins", 

34 "thunar-plugins", 

35 "www", 

36 "all_components", 

37 ], 

38 help="specify an Xfce component group to clone from https://gitlab.xfce.org", 

39) 

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

41args = parser.parse_args() 

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

43 print( 

44 "No component was specified. Default to cloning the 'bindings' components...." 

45 ) 

46 args.component = "bindings" 

47 

48line_rule = "\u2248" * 16 

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

50os.chdir(path) 

51 

52 

53def clone_xfce(component, comp_list): 

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

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

56 # Move to the directory where the script is located 

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

58 

59 def get_path(comp_group): 

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

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

62 

63 return installpath 

64 

65 repopath = get_path(component) 

66 success_count = 0 

67 

68 os.makedirs(repopath, exist_ok=True) 

69 os.chdir(repopath) 

70 

71 for item in component_list(comp_list): 

72 p = Path(item) 

73 if p.is_dir(): 

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

75 print(line_rule) 

76 else: 

77 try: 

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

79 # ruff: ignore[start-process-with-partial-path] 

80 subprocess.run(["git", "clone", url], stdout=None, check=True) # ruff: ignore[subprocess-without-shell-equals-true] 

81 success_count += 1 

82 print(line_rule) 

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

84 except subprocess.CalledProcessError: 

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

86 print(line_rule) 

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

88 

89 print( 

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

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

92 ) 

93 print(line_rule) 

94 

95 

96def main(component_group_name): 

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

98 cappdata for component name list. 

99 command format: 

100 clone_xfce(component='apps', 

101 comp_list='apps') 

102 """ 

103 cgroup_listname = component_list(component_group_name) 

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

105 if isinstance(cgroup_listname, dict): 

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

107 clone_xfce(component=comp, comp_list=cglist) 

108 else: 

109 clone_xfce(component=component_group_name, comp_list=component_group_name) 

110 

111 

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

113 try: 

114 component_group = args.component 

115 main(component_group) 

116 except KeyboardInterrupt: 

117 print() 

118 print("Stopped xfrepos. Exiting...") 

119 sys.exit()