Coverage for src/pull_xfce.py: 25.76%

52 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: pull_xfce.py 

5Purpose: Update local Xfce repositories pulled 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 sys 

16from pathlib import Path 

17 

18from cappdata import component_list 

19 

20parser = argparse.ArgumentParser( 

21 description="Pull/update groups of Xfce components" 

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

23) 

24parser.add_argument( 

25 "-c", 

26 "--component", 

27 action="store", 

28 choices=[ 

29 "apps", 

30 "bindings", 

31 "xfce", 

32 "panel-plugins", 

33 "thunar-plugins", 

34 "www", 

35 "all_components", 

36 ], 

37 help="specify an Xfce component group to pull/update from https://gitlab.xfce.org.", 

38) 

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

40args = parser.parse_args() 

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

42 print( 

43 "No component was specified. Defaulting to pulling/updating" 

44 " the 'apps' component repositories." 

45 ) 

46 args.component = "apps" 

47 

48 

49def pull_xfce(component, comp_list): 

50 """Run 'git pull' on selected components to update repositories.""" 

51 print(f"Updating the Xfce {component} group...") 

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

53 

54 def get_path(comp_group): 

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

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

57 

58 return installpath 

59 

60 repopath = get_path(component) 

61 success_count = 0 

62 

63 if Path.is_dir(repopath): 

64 os.chdir(repopath) 

65 for item in component_list(comp_list): 

66 p = Path(item) 

67 if p.is_dir(): 

68 os.chdir(item) 

69 print(f"Updating {item}...") 

70 # ruff: ignore[start-process-with-a-shell] 

71 os.system("git pull") # ruff: ignore[start-process-with-partial-path] 

72 success_count += 1 

73 print( 

74 f"\n{success_count}/{len(component_list(comp_list))} " 

75 f"'{component}' repositories updated successfully." 

76 ) 

77 print("\u2248" * 16) 

78 os.chdir("..") 

79 else: 

80 print("\nNothing to do...\n") 

81 print( 

82 f"The '{item}' repository does not exist.\n\n" 

83 "Perhaps you need to clone it first.\n" 

84 ) 

85 print("\u2248" * 16) 

86 

87 else: 

88 print("Nothing to do...\n") 

89 print( 

90 f"The '{component}' repositories do not exist.\n\n" 

91 "Perhaps you need to clone the directory first.\n" 

92 ) 

93 print("\u2248" * 16) 

94 

95 

96def main(component_group_name): 

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

98 cappdata for component name list. 

99 command format: 

100 pull_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 pull_xfce(component=comp, comp_list=cglist) 

108 else: 

109 pull_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()